Handle if else statements

This commit is contained in:
2018-11-13 13:54:51 +01:00
parent 1aee448999
commit 56f3777053
11 changed files with 142 additions and 16 deletions

View File

@@ -1,3 +1,4 @@
using Upsilon.BaseTypes.Number;
using Upsilon.Evaluator;
using Xunit;
@@ -8,11 +9,30 @@ namespace UpsilonTests
[Fact]
public void BasicIfTest()
{
var input = "if true then val = true end";
var input = "if true then val = true end";
var script = new Script(input);
Assert.Empty(script.Diagnostics.Messages);
var actual = script.Evaluate<bool>();
Assert.True(actual);
}
[Theory]
[InlineData("true", 3, 8, 3)]
[InlineData("false", 3, 8, 8)]
[InlineData("5 == 5", 500, 349, 500)]
public void BasicIfElseTests(string condition, int in1, int in2, long expected)
{
var input =
$@"
if {condition} then
val = {in1}
else
val = {in2}
end";
var script = new Script(input);
Assert.Empty(script.Diagnostics.Messages);
var actual = (long)(NumberLong)script.Evaluate();
Assert.Equal(expected, actual);
}
}
}