Implement defining functions
This commit is contained in:
30
UpsilonTests/FunctionTests.cs
Normal file
30
UpsilonTests/FunctionTests.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Upsilon.BaseTypes;
|
||||
using Upsilon.BaseTypes.Number;
|
||||
using Upsilon.Evaluator;
|
||||
using Xunit;
|
||||
|
||||
namespace UpsilonTests
|
||||
{
|
||||
public class FunctionTests
|
||||
{
|
||||
[Fact]
|
||||
public void BasicFunctionTest()
|
||||
{
|
||||
const string input = @"
|
||||
function testFunc ()
|
||||
a = 100
|
||||
end
|
||||
a = 50
|
||||
testFunc()
|
||||
";
|
||||
var script = new Script(input);
|
||||
Assert.Empty(script.Diagnostics.Messages);
|
||||
script.Evaluate();
|
||||
Assert.Empty(script.Diagnostics.Messages);
|
||||
Assert.True(script.Scope.TryGet("testFunc", out var func));
|
||||
Assert.IsType<LuaFunction>(func);
|
||||
Assert.True(script.Scope.TryGet("a", out var a));
|
||||
Assert.Equal(100, (long)(NumberLong)a);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user