Upsilon/UpsilonTests/GeneralTests/IfTests.cs

61 lines
1.4 KiB
C#
Raw Permalink Normal View History

2018-11-26 15:55:10 +00:00
using Upsilon;
2018-11-13 11:48:50 +00:00
using Upsilon.Evaluator;
using Xunit;
2018-11-23 13:38:45 +00:00
namespace UpsilonTests.GeneralTests
2018-11-13 11:48:50 +00:00
{
2018-11-23 11:55:28 +00:00
public class IfTests : TestClass
2018-11-13 11:48:50 +00:00
{
2018-11-23 11:55:28 +00:00
public IfTests(StaticScriptFixture fix) : base(fix)
{
}
2018-11-13 11:48:50 +00:00
[Fact]
public void BasicIfTest()
{
2018-11-23 11:55:28 +00:00
const string input = @"
if true then
return true
end
return false";
2018-11-26 15:55:10 +00:00
var actual = Executor.EvaluateScript<bool>(input, Options);
2018-11-13 11:48:50 +00:00
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
return {in1}
2018-11-13 12:54:51 +00:00
else
return {in2}
2018-11-13 12:54:51 +00:00
end";
2018-11-26 15:55:10 +00:00
var actual = Executor.EvaluateScript<long>(input, Options);
2018-11-13 12:54:51 +00:00
Assert.Equal(expected, actual);
}
2018-11-13 14:15:44 +00:00
[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
return {in1}
2018-11-13 14:15:44 +00:00
elseif {condition2} then
return {in2}
2018-11-13 14:15:44 +00:00
else
return {in3}
2018-11-13 14:15:44 +00:00
end";
2018-11-26 15:55:10 +00:00
var actual = Executor.EvaluateScript<long>(input, Options);
2018-11-13 14:15:44 +00:00
Assert.Equal(expected, actual);
}
2018-11-13 11:48:50 +00:00
}
}