示例#1
0
        public void AllowsEarlyExitWhileVisiting()
        {
            var ast = Parser.Parse("{ a, b { x }, c }", new ParseOptions
            {
                NoLocation = true,
            });
            var visitor = new VisitedNodes(node =>
            {
                if (node is Name && (node as Name).Value == "x")
                {
                    throw new Visitor <INode> .BreakException();
                }
                return(node);
            });

            visitor.VisitWithBreak(ast);
            visitor.Visited.ShouldBeEquivalentTo(ImmutableArray.Create(
                                                     Tuple.Create(true, NodeType.Document, (object)null),
                                                     Tuple.Create(true, NodeType.OperationDefinition, (object)null),
                                                     Tuple.Create(true, NodeType.SelectionSet, (object)null),
                                                     Tuple.Create(true, NodeType.Field, (object)null),
                                                     Tuple.Create(true, NodeType.Name, (object)"a"),
                                                     Tuple.Create(false, NodeType.Name, (object)"a"),
                                                     Tuple.Create(false, NodeType.Field, (object)null),
                                                     Tuple.Create(true, NodeType.Field, (object)null),
                                                     Tuple.Create(true, NodeType.Name, (object)"b"),
                                                     Tuple.Create(false, NodeType.Name, (object)"b"),
                                                     Tuple.Create(true, NodeType.SelectionSet, (object)null),
                                                     Tuple.Create(true, NodeType.Field, (object)null),
                                                     Tuple.Create(true, NodeType.Name, (object)"x")
                                                     ));
        }
示例#2
0
 public void AllowsEarlyExitWhileVisiting()
 {
     var ast = Parser.Parse("{ a, b { x }, c }", new ParseOptions
     {
         NoLocation = true,
     });
     var visitor = new VisitedNodes(node =>
     {
         if (node is Name && (node as Name).Value == "x")
         {
             throw new Visitor<INode>.BreakException();
         }
         return node;
     });
     visitor.VisitWithBreak(ast);
     visitor.Visited.ShouldBeEquivalentTo(ImmutableArray.Create(
         Tuple.Create(true, NodeType.Document, (object)null),
         Tuple.Create(true, NodeType.OperationDefinition, (object)null),
         Tuple.Create(true, NodeType.SelectionSet, (object)null),
         Tuple.Create(true, NodeType.Field, (object)null),
         Tuple.Create(true, NodeType.Name, (object)"a"),
         Tuple.Create(false, NodeType.Name, (object)"a"),
         Tuple.Create(false, NodeType.Field, (object)null),
         Tuple.Create(true, NodeType.Field, (object)null),
         Tuple.Create(true, NodeType.Name, (object)"b"),
         Tuple.Create(false, NodeType.Name, (object)"b"),
         Tuple.Create(true, NodeType.SelectionSet, (object)null),
         Tuple.Create(true, NodeType.Field, (object)null),
         Tuple.Create(true, NodeType.Name, (object)"x")
     ));
 }