Beispiel #1
0
        protected override MessageHolder Test(Mode mode, int errorsExpected, LNodePrinterOptions printerOptions, string text, params LNode[] expected)
        {
            var messages = new MessageHolder();
            var les3     = Les3LanguageService.Value;
            var results  = les3.Parse(text, messages, mode == Mode.Expr ? ParsingMode.Expressions : ParsingMode.Statements, true).ToList();

            if (messages.List.Count != System.Math.Max(errorsExpected, 0))
            {
                messages.WriteListTo(ConsoleMessageSink.Value);
                int errorCount = messages.List.Count(msg => msg.Severity >= Severity.Error);
                AreEqual(errorsExpected, errorCount,
                         "Error count was {0} for «{1}»", errorCount, text);                // fail
            }
            for (int i = 0; i < expected.Length; i++)
            {
                LNode expect = expected[i], actual = results.TryGet(i, null);
                if (!expect.Equals(actual, LNode.CompareMode.TypeMarkers))
                {
                    var options = new Les3PrinterOptions {
                        PrintTriviaExplicitly = true, IndentString = "  "
                    };
                    AreEqual(les3.Print(expect, null, null, options), les3.Print(actual, null, null, options));
                    AreEqual(expect, actual);
                    Fail("{0} has a different type marker than {1}", expect, actual);
                }
            }
            AreEqual(expected.Length, results.Count, "Got more result nodes than expected");
            return(messages);
        }
Beispiel #2
0
        protected override MessageHolder Test(Mode mode, int parseErrors, string expected, params LNode[] inputs)
        {
            var messages = new MessageHolder();
            var options  = new Les3PrinterOptions {
                IndentString = "  "
            };

            if (parseErrors == 0)
            {
                if (mode == Mode.Exact)
                {
                    var result = Les3LanguageService.Value.Print(inputs, messages, ParsingMode.Statements, options);
                    Assert.AreEqual(expected, result);
                }
                else
                {
                    // Start by parsing. If parsing fails, just stop; such errors are
                    // already reported by LesParserTests so we need not report them here.
                    var _ = Les3LanguageService.Value.Parse(expected, msgs: messages);
                    if (messages.List.All(msg => msg.Severity < Severity.Error))
                    {
                        foreach (LNode input in inputs)
                        {
                            DoPrinterTest(input);
                        }
                    }
                }
            }
            return(messages);
        }