2018-11-14 15:39:52 +00:00
|
|
|
using Upsilon.BaseTypes.Number;
|
|
|
|
using Upsilon.Evaluator;
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace UpsilonTests
|
|
|
|
{
|
|
|
|
public class ScopeTests
|
|
|
|
{
|
|
|
|
[Fact]
|
|
|
|
public void LocalInnerScopeDoesNotOverrideGlobal()
|
|
|
|
{
|
|
|
|
const string input = @"
|
|
|
|
a = 10
|
|
|
|
if true then
|
|
|
|
local a = 100
|
|
|
|
end
|
|
|
|
";
|
|
|
|
var script = new Script(input);
|
|
|
|
Assert.Empty(script.Diagnostics.Messages);
|
2018-11-14 16:04:04 +00:00
|
|
|
script.Evaluate();
|
2018-11-14 15:39:52 +00:00
|
|
|
Assert.Empty(script.Diagnostics.Messages);
|
2018-11-14 16:04:04 +00:00
|
|
|
Assert.True(script.Scope.TryGet("a", out var obj));
|
|
|
|
Assert.Equal((long)10, (NumberLong)obj);
|
2018-11-14 15:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void InnerScopeDoesOverrideGlobal()
|
|
|
|
{
|
|
|
|
const string input = @"
|
|
|
|
a = 10
|
|
|
|
if true then
|
|
|
|
a = 100
|
|
|
|
end
|
|
|
|
b = a
|
|
|
|
";
|
|
|
|
var script = new Script(input);
|
|
|
|
Assert.Empty(script.Diagnostics.Messages);
|
2018-11-14 16:04:04 +00:00
|
|
|
script.Evaluate();
|
2018-11-14 15:39:52 +00:00
|
|
|
Assert.Empty(script.Diagnostics.Messages);
|
2018-11-14 16:04:04 +00:00
|
|
|
Assert.True(script.Scope.TryGet("a", out var obj));
|
|
|
|
Assert.Equal((long)100, (NumberLong)obj);
|
2018-11-14 15:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|