Upsilon/UpsilonTests/GeneralTests/IfTests.cs

66 lines
1.7 KiB
C#

using Upsilon.Evaluator;
using Xunit;
namespace UpsilonTests.GeneralTests
{
public class IfTests : TestClass
{
public IfTests(StaticScriptFixture fix) : base(fix)
{
}
[Fact]
public void BasicIfTest()
{
const string input = @"
if true then
return true
end
return false";
var script = new Script(input, BoundScope, StaticScope);
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, BoundScope, StaticScope);
Assert.Empty(script.Diagnostics.Messages);
var actual = script.Evaluate<long>();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData("true", "false", 3, 8, 5, 3)]
[InlineData("false", "true", 3, 8, 5, 8)]
public void BasicIfElseIfElseTests(string condition1, string condition2, int in1, int in2, int in3, long expected)
{
var input =
$@"
if {condition1} then
val = {in1}
elseif {condition2} then
val = {in2}
else
val = {in3}
end";
var script = new Script(input, BoundScope, StaticScope);
Assert.Empty(script.Diagnostics.Messages);
var actual = script.Evaluate<long>();
Assert.Equal(expected, actual);
}
}
}