Exemplo n.º 1
0
 protected void Test(LNodeList input, MacroProcessor lemp, string expected, IParsingService outLang)
 {
     // The current printer affects the assert macro and contract macros,
     // so we'll want to set it up before running LeMP
     using (LNode.SetPrinter((ILNodePrinter)outLang))
     {
         var inputCode  = input;
         var results    = lemp.ProcessSynchronously(inputCode);
         var expectCode = outLang.Parse(expected, MessageSink.Default);
         if (!results.SequenceEqual(expectCode))
         {                       // TEST FAILED, print error
             string resultStr = results.Select(n => ((ILNodePrinter)outLang).Print(n)).Join("\n");
             Assert.AreEqual(TestCompiler.StripExtraWhitespace(expected),
                             TestCompiler.StripExtraWhitespace(resultStr));
             // In some tests, the text is equal even though the trees are different,
             // typically because of differences in #trivia attributes between the two.
             Console.WriteLine("(minor dif)");                     // it's OK, but print a hint that this occurred.
         }
     }
 }
Exemplo n.º 2
0
        protected void Test(string input, IParsingService inLang, string expected, IParsingService outLang, int maxExpand = 0xFFFF)
        {
            var lemp = NewLemp(maxExpand, inLang);

            using (ParsingService.PushCurrent(inLang))
            {
                var inputCode  = new VList <LNode>(inLang.Parse(input, MessageSink.Current));
                var results    = lemp.ProcessSynchronously(inputCode);
                var expectCode = outLang.Parse(expected, MessageSink.Current);
                if (!results.SequenceEqual(expectCode))
                {                       // TEST FAILED, print error
                    string resultStr = results.Select(n => outLang.Print(n)).Join("\n");
                    Assert.AreEqual(TestCompiler.StripExtraWhitespace(expected),
                                    TestCompiler.StripExtraWhitespace(resultStr));
                    // In some tests, the text is equal even though the trees are different,
                    // typically because of differences in #trivia attributes between the two.
                    Console.WriteLine();                     // it's OK, but print a hint that this occurred.
                }
            }
        }