Initial interpreter implemenation

--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-11-27 19:57:33 -08:00
parent 289ba2ff5e
commit 8fa1af1939
10 changed files with 192 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
using NUnit.Framework;
using System;
using NUnit.Framework;
using Orchard.Widgets.SimpleScripting;
using Orchard.Widgets.SimpleScripting.Compiler;
@@ -7,8 +8,25 @@ namespace Orchard.Tests.Modules.SimpleScriptingTests {
public class EvaluatorTests {
[Test]
public void EvaluateSimpleConstant() {
var tree = new Parser("1*2+3").Parse();
var result = EvaluateSimpleExpression("true and true");
Assert.That(result.HasErrors, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateSimpleArithmetic() {
var result = EvaluateSimpleExpression("1 + 2 * 3 - 6 / 2");
Assert.That(result.HasErrors, Is.False);
Assert.That(result.Value, Is.EqualTo(4));
}
private EvaluationResult EvaluateSimpleExpression(string expression) {
var ast = new Parser(expression).Parse();
var result = new Interpreter().Evalutate(new EvaluationContext {
Tree = ast,
MethodInvocationCallback = (m, args) => null
});
return result;
}
}
}