@@ -8,24 +8,7 @@ class VisitorTests: XCTestCase {
8
8
}
9
9
10
10
func testValidatesPathArgument( ) throws {
11
- struct VisitedElement : Equatable {
12
- let direction : VisitDirection
13
- let path : [ any IndexPathElement ]
14
-
15
- init ( _ direction: VisitDirection , _ path: [ any IndexPathElement ] ) {
16
- self . direction = direction
17
- self . path = path
18
- }
19
-
20
- static func == ( lhs: VisitedElement , rhs: VisitedElement ) -> Bool {
21
- return lhs. direction == rhs. direction &&
22
- zip ( lhs. path, rhs. path) . allSatisfy { lhs, rhs in
23
- lhs. description == rhs. description
24
- }
25
- }
26
- }
27
-
28
- var visited = [ VisitedElement] ( )
11
+ var visited = [ VisitedPath] ( )
29
12
let ast = try parse ( source: " { a } " , noLocation: true )
30
13
31
14
visit ( root: ast, visitor: . init(
@@ -513,36 +496,7 @@ class VisitorTests: XCTestCase {
513
496
}
514
497
515
498
func testProperlyVisitsTheKitchenSinkQuery( ) throws {
516
- struct VisitedElement : Equatable , CustomDebugStringConvertible {
517
- var debugDescription : String {
518
- " ( \( direction) , \( kind) , \( key. debugDescription) , \( parentKind. debugDescription) ) "
519
- }
520
-
521
- let direction : VisitDirection
522
- let kind : Kind
523
- let key : ( any IndexPathElement ) ?
524
- let parentKind : Kind ?
525
-
526
- init (
527
- _ direction: VisitDirection ,
528
- _ kind: Kind ,
529
- _ key: ( any IndexPathElement ) ? ,
530
- _ parentKind: Kind ?
531
- ) {
532
- self . direction = direction
533
- self . kind = kind
534
- self . key = key
535
- self . parentKind = parentKind
536
- }
537
-
538
- static func == ( lhs: VisitedElement , rhs: VisitedElement ) -> Bool {
539
- return lhs. direction == rhs. direction &&
540
- lhs. kind == rhs. kind &&
541
- lhs. key? . description == rhs. key? . description &&
542
- lhs. parentKind == rhs. parentKind
543
- }
544
- }
545
- var visited = [ VisitedElement] ( )
499
+ var visited = [ VisitedKindAndParent] ( )
546
500
547
501
guard
548
502
let url = Bundle . module. url ( forResource: " kitchen-sink " , withExtension: " graphql " ) ,
@@ -884,6 +838,59 @@ enum VisitDirection: Equatable {
884
838
case leave
885
839
}
886
840
841
+ struct VisitedPath {
842
+ let direction : VisitDirection
843
+ let path : [ any IndexPathElement ]
844
+
845
+ init ( _ direction: VisitDirection , _ path: [ any IndexPathElement ] ) {
846
+ self . direction = direction
847
+ self . path = path
848
+ }
849
+ }
850
+
851
+ extension VisitedPath : Equatable {
852
+ static func == ( lhs: VisitedPath , rhs: VisitedPath ) -> Bool {
853
+ return lhs. direction == rhs. direction &&
854
+ zip ( lhs. path, rhs. path) . allSatisfy { lhs, rhs in
855
+ lhs. description == rhs. description
856
+ }
857
+ }
858
+ }
859
+
860
+ struct VisitedKindAndParent {
861
+ let direction : VisitDirection
862
+ let kind : Kind
863
+ let key : ( any IndexPathElement ) ?
864
+ let parentKind : Kind ?
865
+
866
+ init (
867
+ _ direction: VisitDirection ,
868
+ _ kind: Kind ,
869
+ _ key: ( any IndexPathElement ) ? ,
870
+ _ parentKind: Kind ?
871
+ ) {
872
+ self . direction = direction
873
+ self . kind = kind
874
+ self . key = key
875
+ self . parentKind = parentKind
876
+ }
877
+ }
878
+
879
+ extension VisitedKindAndParent : Equatable {
880
+ static func == ( lhs: VisitedKindAndParent , rhs: VisitedKindAndParent ) -> Bool {
881
+ return lhs. direction == rhs. direction &&
882
+ lhs. kind == rhs. kind &&
883
+ lhs. key? . description == rhs. key? . description &&
884
+ lhs. parentKind == rhs. parentKind
885
+ }
886
+ }
887
+
888
+ extension VisitedKindAndParent : CustomDebugStringConvertible {
889
+ var debugDescription : String {
890
+ " ( \( direction) , \( kind) , \( key. debugDescription) , \( parentKind. debugDescription) ) "
891
+ }
892
+ }
893
+
887
894
func checkVisitorFnArgs(
888
895
_ ast: Document ,
889
896
_ node: Node ,
0 commit comments