mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Implement parsing of method calls
Parsing methods calls of the form:
<identifier> '(' arg [, arg, ...] ')'
<identifier> arg [, arg, ...]
--HG--
branch : dev
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Widgets.SimpleScripting;
|
||||
using Orchard.Widgets.SimpleScripting.Compiler;
|
||||
|
||||
namespace Orchard.Tests.Modules.SimpleScriptingTests {
|
||||
namespace Orchard.Tests.Modules.SimpleScripting {
|
||||
[TestFixture]
|
||||
public class EvaluatorTests {
|
||||
[Test]
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Widgets.SimpleScripting;
|
||||
using Orchard.Widgets.SimpleScripting.Ast;
|
||||
using Orchard.Widgets.SimpleScripting.Compiler;
|
||||
|
||||
namespace Orchard.Tests.Modules.SimpleScriptingTests {
|
||||
namespace Orchard.Tests.Modules.SimpleScripting {
|
||||
[TestFixture]
|
||||
public class ParserTests {
|
||||
[Test]
|
||||
@@ -26,6 +25,37 @@ namespace Orchard.Tests.Modules.SimpleScriptingTests {
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParserShouldUnderstandCommandExpressions() {
|
||||
var tree = new Parser("print 'foo', 'bar'").Parse();
|
||||
CheckTree(tree, new object[] {
|
||||
"call", TokenKind.Identifier, "print",
|
||||
"const", "foo",
|
||||
"const", "bar",
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParserShouldUnderstandCallExpressions() {
|
||||
var tree = new Parser("print('foo', 'bar')").Parse();
|
||||
CheckTree(tree, new object[] {
|
||||
"call", TokenKind.Identifier, "print",
|
||||
"const", "foo",
|
||||
"const", "bar",
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParserShouldUnderstandCallExpressions2() {
|
||||
var tree = new Parser("print 1+2").Parse();
|
||||
CheckTree(tree, new object[] {
|
||||
"call", TokenKind.Identifier, "print",
|
||||
"binop", TokenKind.Plus,
|
||||
"const", 1,
|
||||
"const", 2,
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParserShouldUnderstandOperatorPrecedence() {
|
||||
var tree = new Parser("1+2*3").Parse();
|
||||
@@ -123,7 +153,7 @@ namespace Orchard.Tests.Modules.SimpleScriptingTests {
|
||||
private void CheckExpression(AstNode astNode, int indent, object[] objects, ref int index) {
|
||||
var exprName = (string)objects[index++];
|
||||
Type type = null;
|
||||
switch(exprName) {
|
||||
switch (exprName) {
|
||||
case "const":
|
||||
type = typeof(ConstantAstNode);
|
||||
break;
|
||||
@@ -133,6 +163,9 @@ namespace Orchard.Tests.Modules.SimpleScriptingTests {
|
||||
case "unop":
|
||||
type = typeof(UnaryAstNode);
|
||||
break;
|
||||
case "call":
|
||||
type = typeof(MethodCallAstNode);
|
||||
break;
|
||||
case "error":
|
||||
type = typeof(ErrorAstNode);
|
||||
break;
|
||||
@@ -151,8 +184,12 @@ namespace Orchard.Tests.Modules.SimpleScriptingTests {
|
||||
else if (exprName == "unop") {
|
||||
Assert.That((astNode as UnaryAstNode).Operator.Kind, Is.EqualTo(objects[index++]));
|
||||
}
|
||||
else if (exprName == "call") {
|
||||
Assert.That((astNode as MethodCallAstNode).Token.Kind, Is.EqualTo(objects[index++]));
|
||||
Assert.That((astNode as MethodCallAstNode).Token.Value, Is.EqualTo(objects[index++]));
|
||||
}
|
||||
|
||||
foreach(var child in astNode.Children) {
|
||||
foreach (var child in astNode.Children) {
|
||||
CheckExpression(child, indent + 1, objects, ref index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using NUnit.Framework;
|
||||
using Orchard.Widgets.SimpleScripting;
|
||||
using Orchard.Widgets.SimpleScripting.Compiler;
|
||||
|
||||
namespace Orchard.Tests.Modules.SimpleScriptingTests {
|
||||
namespace Orchard.Tests.Modules.SimpleScripting {
|
||||
[TestFixture]
|
||||
public class TokenizerTests {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user