59 lines
1.2 KiB
C#
59 lines
1.2 KiB
C#
using Upsilon;
|
|
using Upsilon.Evaluator;
|
|
using Xunit;
|
|
|
|
namespace UpsilonTests.GeneralTests
|
|
{
|
|
public class ScopeTests : TestClass
|
|
{
|
|
public ScopeTests(StaticScriptFixture fix) : base(fix)
|
|
{
|
|
}
|
|
|
|
[Fact]
|
|
public void LocalInnerScopeDoesNotOverrideGlobal()
|
|
{
|
|
const string input = @"
|
|
a = 10
|
|
function testFunc()
|
|
local a = 100
|
|
end
|
|
testFunc()
|
|
";
|
|
var script = Executor.ParseInputAndEvaluate(input, Options);
|
|
var a = script.GetVariable<long>("a");
|
|
Assert.Equal(10, a);
|
|
}
|
|
|
|
[Fact]
|
|
public void InnerScopeDoesOverrideGlobal()
|
|
{
|
|
const string input = @"
|
|
a = 10
|
|
if true then
|
|
a = 100
|
|
end
|
|
b = a
|
|
";
|
|
var script = Executor.ParseInputAndEvaluate(input, Options);
|
|
var a = script.GetVariable<long>("a");
|
|
Assert.Equal(100, a);
|
|
}
|
|
|
|
[Fact]
|
|
public void InnerScopeDefinesToUpperLocalIfLogical()
|
|
{
|
|
const string input = @"
|
|
arr = {100, 56, 28}
|
|
local value = 0
|
|
for key, val in ipairs(arr) do
|
|
value = value + val
|
|
end
|
|
return value
|
|
";
|
|
var result = Executor.EvaluateScript<long>(input, Options);
|
|
Assert.Equal(184, result);
|
|
}
|
|
|
|
}
|
|
} |