Beispiel #1
0
        private void DoPrinterTest(LNode node, StringBuilder sb)
        {
            sb.Length = 0;
            _messages.List.Clear();
            var p = LesNodePrinter.New(sb, "\t", "\n", _messages);

            p.Print(node);
            Assert.AreEqual(0, _messages.List.Count);
            var reparsed = LesLanguageService.Value.Parse(sb.ToString(), _messages);

            Assert.AreEqual(0, _messages.List.Count);
            Assert.AreEqual(1, reparsed.Count);
            Assert.AreEqual(node, reparsed[0]);
        }
Beispiel #2
0
        protected override MessageHolder Test(Mode mode, int parseErrors, string str, params LNode[] nodes)
        {
            var messages = new MessageHolder();

            if (parseErrors == 0)
            {
                if (mode == Mode.Exact)
                {
                    var sb      = new StringBuilder();
                    var printer = LesNodePrinter.New(sb, "  ", "\n", messages);
                    var sep     = "";
                    foreach (LNode node in nodes)
                    {
                        sb.Append(sep);
                        sep = "\n";
                        printer.Print(node);
                    }
                    Assert.AreEqual(str, sb.ToString());
                }
                else
                {
                    // Start by parsing. If parsing fails, just stop; such errors are
                    // already reported by LesParserTests so we need not report them here.
                    var results = LesLanguageService.Value.Parse(str, messages);
                    if (messages.List.Count == 0)
                    {
                        var sb = new StringBuilder();
                        foreach (LNode node in nodes)
                        {
                            DoPrinterTest(node, sb);
                        }
                    }
                }
            }
            return(messages);
        }