Exemple #1
0
        /// <summary>
        /// Parses the given chunk of code and verifies that it matches the expected pretty-printed result
        /// </summary>
        /// <param name="source"></param>
        /// <param name="expected"></param>
        public void Test(string source, string expected)
        {
            var    lexer  = new Lexer(source);
            Parser parser = new BantamParser(lexer);

            try
            {
                var result  = parser.ParseExpression();
                var builder = new StringBuilder();
                result.Print(builder);
                var actual = builder.ToString();

                if (expected.Equals(actual))
                {
                    _passed++;
                }
                else
                {
                    _failed++;
                    Console.Out.WriteLine("[FAIL] Expected: " + expected);
                    Console.Out.WriteLine("         Actual: " + actual);
                }
            }
            catch (ParseException ex)
            {
                _failed++;
                Console.Out.WriteLine("[FAIL] Expected: " + expected);
                Console.Out.WriteLine("          Error: " + ex.Message);
            }
        }
Exemple #2
0
        /// <summary>
        /// Parses the given chunk of code and verifies that it matches the expected pretty-printed result
        /// </summary>
        /// <param name="source"></param>
        /// <param name="expected"></param>
        public void Test(string source, string expected)
        {
            var lexer = new Lexer(source);
            Parser parser = new BantamParser(lexer);

            try
            {
                var result = parser.ParseExpression();
                var builder = new StringBuilder();
                result.Print(builder);
                var actual = builder.ToString();

                if (expected.Equals(actual))
                {
                    _passed++;
                }
                else
                {
                    _failed++;
                    Console.Out.WriteLine("[FAIL] Expected: " + expected);
                    Console.Out.WriteLine("         Actual: " + actual);
                }
            }
            catch (ParseException ex)
            {
                _failed++;
                Console.Out.WriteLine("[FAIL] Expected: " + expected);
                Console.Out.WriteLine("          Error: " + ex.Message);
            }
        }