mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Implement evaluation of method calls
--HG-- branch : dev
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System.Diagnostics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Widgets.SimpleScripting.Compiler;
|
||||
|
||||
@@ -33,11 +35,25 @@ namespace Orchard.Tests.Modules.SimpleScripting {
|
||||
Assert.That(result.Value, Is.EqualTo(4));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EvaluateSimpleMethodCall() {
|
||||
var result = EvaluateSimpleExpression("print 1 + 2 * 3 - 6 / 2",
|
||||
(m, args) => (m == "print") ? (int)args[0] * 2 : 0);
|
||||
Assert.That(result.IsError, Is.False);
|
||||
Assert.That(result.Value, Is.EqualTo(4 * 2));
|
||||
}
|
||||
|
||||
private EvaluationResult EvaluateSimpleExpression(string expression) {
|
||||
return EvaluateSimpleExpression(expression, (m, args) => null);
|
||||
}
|
||||
|
||||
private EvaluationResult EvaluateSimpleExpression(
|
||||
string expression, Func<string, IList<object>, object> methodInvocationCallback) {
|
||||
|
||||
var ast = new Parser(expression).Parse();
|
||||
var result = new Interpreter().Evalutate(new EvaluationContext {
|
||||
Tree = ast,
|
||||
MethodInvocationCallback = (m, args) => null
|
||||
MethodInvocationCallback = methodInvocationCallback
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user