Skip to content

Commit 0eaa800

Browse files
fix: Reformat Visitor types to support old Swift versions
1 parent 40d2ab2 commit 0eaa800

File tree

1 file changed

+55
-48
lines changed

1 file changed

+55
-48
lines changed

Tests/GraphQLTests/LanguageTests/VisitorTests.swift

Lines changed: 55 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,7 @@ class VisitorTests: XCTestCase {
88
}
99

1010
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]()
2912
let ast = try parse(source: "{ a }", noLocation: true)
3013

3114
visit(root: ast, visitor: .init(
@@ -513,36 +496,7 @@ class VisitorTests: XCTestCase {
513496
}
514497

515498
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]()
546500

547501
guard
548502
let url = Bundle.module.url(forResource: "kitchen-sink", withExtension: "graphql"),
@@ -884,6 +838,59 @@ enum VisitDirection: Equatable {
884838
case leave
885839
}
886840

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+
887894
func checkVisitorFnArgs(
888895
_ ast: Document,
889896
_ node: Node,

0 commit comments

Comments
 (0)