2018-11-14 15:39:52 +00:00
|
|
|
using Upsilon.BaseTypes.Number;
|
|
|
|
using Upsilon.Evaluator;
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace UpsilonTests
|
|
|
|
{
|
2018-11-23 11:55:28 +00:00
|
|
|
public class ScopeTests : TestClass
|
2018-11-14 15:39:52 +00:00
|
|
|
{
|
2018-11-23 11:55:28 +00:00
|
|
|
public ScopeTests(StaticScriptFixture fix) : base(fix)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-11-14 15:39:52 +00:00
|
|
|
[Fact]
|
|
|
|
public void LocalInnerScopeDoesNotOverrideGlobal()
|
|
|
|
{
|
|
|
|
const string input = @"
|
|
|
|
a = 10
|
|
|
|
if true then
|
|
|
|
local a = 100
|
|
|
|
end
|
|
|
|
";
|
2018-11-23 11:55:28 +00:00
|
|
|
var script = new Script(input, BoundScope, StaticScope);
|
2018-11-14 15:39:52 +00:00
|
|
|
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-17 11:40:28 +00:00
|
|
|
var a = script.GetVariable<long>("a");
|
|
|
|
Assert.Equal(10, a);
|
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
|
|
|
|
";
|
2018-11-23 11:55:28 +00:00
|
|
|
var script = new Script(input, BoundScope, StaticScope);
|
2018-11-14 15:39:52 +00:00
|
|
|
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-17 11:40:28 +00:00
|
|
|
var a = script.GetVariable<long>("a");
|
|
|
|
Assert.Equal(100, a);
|
2018-11-14 15:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|