mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Initial interpreter implemenation
--HG-- branch : dev
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user