Esempio n. 1
0
        private static void EvaluateSyntaxTreeNode(ErrorCollector collector, SyntaxTreeNode actual, SyntaxTreeNode expected)
        {
            if (actual == null)
            {
                AddNullActualError(collector, actual, expected);
            }

            if (actual.IsBlock != expected.IsBlock)
            {
                AddMismatchError(collector, actual, expected);
            }
            else
            {
                if (expected.IsBlock)
                {
                    EvaluateBlock(collector, (Block)actual, (Block)expected);
                }
                else
                {
                    EvaluateSpan(collector, (Span)actual, (Span)expected);
                }
            }
        }
Esempio n. 2
0
 private static void AddNullActualError(ErrorCollector collector, SyntaxTreeNode actual, SyntaxTreeNode expected)
 {
     collector.AddError("{0} - FAILED :: Actual: << Null >>", expected);
 }
Esempio n. 3
0
 private static void AddMismatchError(ErrorCollector collector, SyntaxTreeNode actual, SyntaxTreeNode expected)
 {
     collector.AddError("{0} - FAILED :: Actual: {1}", expected, actual);
 }
Esempio n. 4
0
 private static void AddPassedMessage(ErrorCollector collector, SyntaxTreeNode expected)
 {
     collector.AddMessage("{0} - PASSED", expected);
 }
 private static void AddNullActualError(ErrorCollector collector, SyntaxTreeNode actual, SyntaxTreeNode expected)
 {
     collector.AddError("{0} - FAILED :: Actual: << Null >>", expected);
 }
 private static void AddMismatchError(ErrorCollector collector, SyntaxTreeNode actual, SyntaxTreeNode expected)
 {
     collector.AddError("{0} - FAILED :: Actual: {1}", expected, actual);
 }
 private static void AddPassedMessage(ErrorCollector collector, SyntaxTreeNode expected)
 {
     collector.AddMessage("{0} - PASSED", expected);
 }
 private static void EvaluateBlock(ErrorCollector collector, Block actual, Block expected)
 {
     if (actual.Type != expected.Type || !expected.CodeGenerator.Equals(actual.CodeGenerator))
     {
         AddMismatchError(collector, actual, expected);
     }
     else
     {
         AddPassedMessage(collector, expected);
         using (collector.Indent())
         {
             IEnumerator<SyntaxTreeNode> expectedNodes = expected.Children.GetEnumerator();
             IEnumerator<SyntaxTreeNode> actualNodes = actual.Children.GetEnumerator();
             while (expectedNodes.MoveNext())
             {
                 if (!actualNodes.MoveNext())
                 {
                     collector.AddError("{0} - FAILED :: No more elements at this node", expectedNodes.Current);
                 }
                 else
                 {
                     EvaluateSyntaxTreeNode(collector, actualNodes.Current, expectedNodes.Current);
                 }
             }
             while (actualNodes.MoveNext())
             {
                 collector.AddError("End of Node - FAILED :: Found Node: {0}", actualNodes.Current);
             }
         }
     }
 }
 private static void EvaluateSpan(ErrorCollector collector, Span actual, Span expected)
 {
     if (!Equals(expected, actual))
     {
         AddMismatchError(collector, actual, expected);
     }
     else
     {
         AddPassedMessage(collector, expected);
     }
 }
        private static void EvaluateSyntaxTreeNode(ErrorCollector collector, SyntaxTreeNode actual, SyntaxTreeNode expected)
        {
            if (actual == null)
            {
                AddNullActualError(collector, actual, expected);
            }

            if (actual.IsBlock != expected.IsBlock)
            {
                AddMismatchError(collector, actual, expected);
            }
            else
            {
                if (expected.IsBlock)
                {
                    EvaluateBlock(collector, (Block)actual, (Block)expected);
                }
                else
                {
                    EvaluateSpan(collector, (Span)actual, (Span)expected);
                }
            }
        }
        public static void EvaluateParseTree(Block actualRoot, Block expectedRoot)
        {
            // Evaluate the result
            ErrorCollector collector = new ErrorCollector();

            // Link all the nodes
            expectedRoot.LinkNodes();

            if (expectedRoot == null)
            {
                Assert.Null(actualRoot);
            }
            else
            {
                Assert.NotNull(actualRoot);
                EvaluateSyntaxTreeNode(collector, actualRoot, expectedRoot);
                if (collector.Success)
                {
                    WriteTraceLine("Parse Tree Validation Succeeded:\r\n{0}", collector.Message);
                }
                else
                {
                    Assert.True(false, String.Format("\r\n{0}", collector.Message));
                }
            }
        }
Esempio n. 12
0
 private static void EvaluateSpan(ErrorCollector collector, SourceLocationTracker tracker, Span actual, Span expected) {
     if (!actual.Equals(expected)) {
         AddMismatchError(collector, tracker, actual, expected);
     }
     else {
         AddPassedMessage(collector, tracker, expected);
     }
 }
Esempio n. 13
0
        public static void EvaluateParseTree(TestContext context, Block actualRoot, Block expectedRoot) {
            // Evaluate the result
            ErrorCollector collector = new ErrorCollector();
            SourceLocationTracker tracker = new SourceLocationTracker();

            // Link all the nodes
            Span first = null;
            Span previous = null;
            foreach (Span span in expectedRoot.Flatten()) {
                if(first == null) {
                    first = span;
                }
                span.Previous = previous;
                if (previous != null) {
                    previous.Next = span;
                }
                previous = span;
            }
            Span.ClearCachedStartPoints(first);

            if (expectedRoot == null) {
                Assert.IsNull(actualRoot, "Expected an empty document.  Actual: {0}", actualRoot);
            }
            else {
                Assert.IsNotNull(actualRoot, "Expected a valid document, but it was empty");
                EvaluateSyntaxTreeNode(collector, tracker, actualRoot, expectedRoot);
                if (collector.Success) {
                    if (context != null) {
                        context.WriteLine("Parse Tree Validation Succeeded:\r\n{0}", collector.Message);
                    }
                }
                else {
                    Assert.Fail("\r\n{0}", collector.Message);
                }
            }
        }