Upsilon/UpsilonTests/GeneralTests/ScopeTests.cs

49 lines
1.1 KiB
C#

using Upsilon.BaseTypes.Number;
using Upsilon.Evaluator;
using Xunit;
namespace UpsilonTests
{
public class ScopeTests : TestClass
{
public ScopeTests(StaticScriptFixture fix) : base(fix)
{
}
[Fact]
public void LocalInnerScopeDoesNotOverrideGlobal()
{
const string input = @"
a = 10
if true then
local a = 100
end
";
var script = new Script(input, BoundScope, StaticScope);
Assert.Empty(script.Diagnostics.Messages);
script.Evaluate();
Assert.Empty(script.Diagnostics.Messages);
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 = new Script(input, BoundScope, StaticScope);
Assert.Empty(script.Diagnostics.Messages);
script.Evaluate();
Assert.Empty(script.Diagnostics.Messages);
var a = script.GetVariable<long>("a");
Assert.Equal(100, a);
}
}
}