Skip to content

Commit

Permalink
fix: Reformat Visitor types to support old Swift versions
Browse files Browse the repository at this point in the history
  • Loading branch information
NeedleInAJayStack committed Nov 9, 2023
1 parent 40d2ab2 commit 0eaa800
Showing 1 changed file with 55 additions and 48 deletions.
103 changes: 55 additions & 48 deletions Tests/GraphQLTests/LanguageTests/VisitorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,7 @@ class VisitorTests: XCTestCase {
}

func testValidatesPathArgument() throws {
struct VisitedElement: Equatable {
let direction: VisitDirection
let path: [any IndexPathElement]

init(_ direction: VisitDirection, _ path: [any IndexPathElement]) {
self.direction = direction
self.path = path
}

static func == (lhs: VisitedElement, rhs: VisitedElement) -> Bool {
return lhs.direction == rhs.direction &&
zip(lhs.path, rhs.path).allSatisfy { lhs, rhs in
lhs.description == rhs.description
}
}
}

var visited = [VisitedElement]()
var visited = [VisitedPath]()
let ast = try parse(source: "{ a }", noLocation: true)

visit(root: ast, visitor: .init(
Expand Down Expand Up @@ -513,36 +496,7 @@ class VisitorTests: XCTestCase {
}

func testProperlyVisitsTheKitchenSinkQuery() throws {
struct VisitedElement: Equatable, CustomDebugStringConvertible {
var debugDescription: String {
"(\(direction), \(kind), \(key.debugDescription), \(parentKind.debugDescription))"
}

let direction: VisitDirection
let kind: Kind
let key: (any IndexPathElement)?
let parentKind: Kind?

init(
_ direction: VisitDirection,
_ kind: Kind,
_ key: (any IndexPathElement)?,
_ parentKind: Kind?
) {
self.direction = direction
self.kind = kind
self.key = key
self.parentKind = parentKind
}

static func == (lhs: VisitedElement, rhs: VisitedElement) -> Bool {
return lhs.direction == rhs.direction &&
lhs.kind == rhs.kind &&
lhs.key?.description == rhs.key?.description &&
lhs.parentKind == rhs.parentKind
}
}
var visited = [VisitedElement]()
var visited = [VisitedKindAndParent]()

guard
let url = Bundle.module.url(forResource: "kitchen-sink", withExtension: "graphql"),
Expand Down Expand Up @@ -884,6 +838,59 @@ enum VisitDirection: Equatable {
case leave
}

struct VisitedPath {
let direction: VisitDirection
let path: [any IndexPathElement]

init(_ direction: VisitDirection, _ path: [any IndexPathElement]) {
self.direction = direction
self.path = path
}
}

extension VisitedPath: Equatable {
static func == (lhs: VisitedPath, rhs: VisitedPath) -> Bool {
return lhs.direction == rhs.direction &&
zip(lhs.path, rhs.path).allSatisfy { lhs, rhs in
lhs.description == rhs.description
}
}
}

struct VisitedKindAndParent {
let direction: VisitDirection
let kind: Kind
let key: (any IndexPathElement)?
let parentKind: Kind?

init(
_ direction: VisitDirection,
_ kind: Kind,
_ key: (any IndexPathElement)?,
_ parentKind: Kind?
) {
self.direction = direction
self.kind = kind
self.key = key
self.parentKind = parentKind
}
}

extension VisitedKindAndParent: Equatable {
static func == (lhs: VisitedKindAndParent, rhs: VisitedKindAndParent) -> Bool {
return lhs.direction == rhs.direction &&
lhs.kind == rhs.kind &&
lhs.key?.description == rhs.key?.description &&
lhs.parentKind == rhs.parentKind
}
}

extension VisitedKindAndParent: CustomDebugStringConvertible {
var debugDescription: String {
"(\(direction), \(kind), \(key.debugDescription), \(parentKind.debugDescription))"
}
}

func checkVisitorFnArgs(
_ ast: Document,
_ node: Node,
Expand Down

0 comments on commit 0eaa800

Please sign in to comment.