示例#1
0
        public void IfElseExpressionTest1()
        {
            var tests = new StatementEvalTestCase[]
            {
                new() { Input = "if (true) { 10 }", Expected = 10 },
                new() { Input = "if (false) { 10 }", Expected = null },
                new() { Input = "if (1) { 10 }", Expected = 10 },
                new() { Input = "if (1 < 2) { 10 }", Expected = 10 },
                new() { Input = "if (1 > 2) { 10 }", Expected = null },
                new() { Input = "if (1 > 2) { 10 } else { 20 }", Expected = 20 },
                new() { Input = "if (1 < 2) { 10 } else { 20 }", Expected = 10 }
            };

            foreach (var boolEvalTestCase in tests)
            {
                var evaluated = StaticTests.TestEval(boolEvalTestCase.Input);
                if (boolEvalTestCase.Expected is null)
                {
                    Assert.True(StaticTests.TestNullObject(evaluated),
                                $"evaluated object is not Null, got {evaluated}");
                }
                else
                {
                    StaticTests.TestIntegerObject(evaluated, boolEvalTestCase.Expected);
                }
            }
        }