Esempio n. 1
0
        public void LetStatementsTest1()
        {
            var tests = new[]
            {
                new LetStatementTestCases {
                    Input = "let x = 5;", ExpectedIdentifier = "x"
                }.ExpectedValueSet(5),
                new LetStatementTestCases {
                    Input = "let y = true;", ExpectedIdentifier = "y"
                }
                .ExpectedValueSet(true),
                new LetStatementTestCases {
                    Input = "let foo = y;", ExpectedIdentifier = "foo"
                }
                .ExpectedValueSet("y")
            };

            foreach (var letStatementTestCases in tests)
            {
                var lexer   = new Lexer(letStatementTestCases.Input);
                var parser  = new Parser(lexer);
                var program = parser.ParseCode();

                StaticTests.CheckParserErrors(parser);

                Assert.AreEqual(1, program.Statements.Count);

                var stmt = program.Statements.First() as LetStatement;

                StaticTests.TestLetStatement(stmt, letStatementTestCases.ExpectedIdentifier);

                var value = stmt.Value;

                StaticTests.TestLiteralExpression(value, letStatementTestCases.ExpectedValueGet());
            }
        }