Properly handle scopes
This commit is contained in:
44
UpsilonTests/ScopeTests.cs
Normal file
44
UpsilonTests/ScopeTests.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
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
|
||||
b = a
|
||||
";
|
||||
var script = new Script(input);
|
||||
Assert.Empty(script.Diagnostics.Messages);
|
||||
var evaluate = script.Evaluate<NumberLong>();
|
||||
Assert.Empty(script.Diagnostics.Messages);
|
||||
Assert.Equal((long)10, evaluate);
|
||||
}
|
||||
|
||||
[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);
|
||||
var evaluate = script.Evaluate<NumberLong>();
|
||||
Assert.Empty(script.Diagnostics.Messages);
|
||||
Assert.Equal((long)100, evaluate);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
|
||||
Reference in New Issue
Block a user