Upsilon/UpsilonTests/IfTests.cs

38 lines
987 B
C#
Raw Normal View History

2018-11-13 12:54:51 +00:00
using Upsilon.BaseTypes.Number;
2018-11-13 11:48:50 +00:00
using Upsilon.Evaluator;
using Xunit;
namespace UpsilonTests
{
public class IfTests
{
[Fact]
public void BasicIfTest()
{
2018-11-13 12:54:51 +00:00
var input = "if true then val = true end";
2018-11-13 11:48:50 +00:00
var script = new Script(input);
Assert.Empty(script.Diagnostics.Messages);
var actual = script.Evaluate<bool>();
Assert.True(actual);
}
2018-11-13 12:54:51 +00:00
[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);
}
2018-11-13 11:48:50 +00:00
}
}