Skip to content

Commit 3bc84d2

Browse files
committed
Update tests to use the new visitor pattern
1 parent b445aa4 commit 3bc84d2

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

Tests/SwiftSyntaxTest/AbsolutePosition.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public class AbsolutePositionTestCase: XCTestCase {
6969
node.position.utf8Offset + node.leadingTrivia.byteSize)
7070
}
7171
}
72-
Visitor().visit(parsed)
72+
parsed.walk(Visitor())
7373
}())
7474
}
7575

Tests/SwiftSyntaxTest/DiagnosticTest.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,20 @@ public class DiagnosticTestCase: XCTestCase {
7676
self.url = url
7777
self.engine = engine
7878
}
79-
override func visit(_ function: FunctionDeclSyntax) {
79+
override func visit(_ function: FunctionDeclSyntax) -> Bool {
8080
let startLoc = function.identifier.startLocation(in: url)
8181
let endLoc = function.endLocation(in: url)
8282
engine.diagnose(.badFunction(function.identifier), location: startLoc) {
8383
$0.highlight(function.identifier.sourceRange(in: self.url))
8484
}
8585
engine.diagnose(.endOfFunction(function.identifier), location: endLoc)
86+
return true
8687
}
8788
}
8889

8990
XCTAssertNoThrow(try {
9091
let file = try SyntaxTreeParser.parse(url)
91-
Visitor(url: url, engine: engine).visit(file)
92+
file.walk(Visitor(url: url, engine: engine))
9293
}())
9394

9495
XCTAssertEqual(6, engine.diagnostics.count)

Tests/SwiftSyntaxTest/VisitorTest.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ public class SyntaxVisitorTestCase: XCTestCase {
1313
public func testBasic() {
1414
class FuncCounter: SyntaxVisitor {
1515
var funcCount = 0
16-
override func visit(_ node: FunctionDeclSyntax) {
16+
override func visit(_ node: FunctionDeclSyntax) -> Bool {
1717
funcCount += 1
18-
super.visit(node)
18+
return true
1919
}
2020
}
2121
XCTAssertNoThrow(try {
2222
let parsed = try SyntaxTreeParser.parse(getInput("visitor.swift"))
2323
let counter = FuncCounter()
2424
let hashBefore = parsed.hashValue
25-
counter.visit(parsed)
25+
parsed.walk(counter)
2626
XCTAssertEqual(counter.funcCount, 3)
2727
XCTAssertEqual(hashBefore, parsed.hashValue)
2828
}())
@@ -70,16 +70,16 @@ public class SyntaxVisitorTestCase: XCTestCase {
7070
class VisitCollections: SyntaxVisitor {
7171
var numberOfCodeBlockItems = 0
7272

73-
override func visit(_ items: CodeBlockItemListSyntax) {
73+
override func visit(_ items: CodeBlockItemListSyntax) -> Bool {
7474
numberOfCodeBlockItems += items.count
75-
super.visit(items)
75+
return true
7676
}
7777
}
7878

7979
XCTAssertNoThrow(try {
8080
let parsed = try SyntaxTreeParser.parse(getInput("nested-blocks.swift"))
8181
let visitor = VisitCollections()
82-
visitor.visit(parsed)
82+
parsed.walk(visitor)
8383
XCTAssertEqual(4, visitor.numberOfCodeBlockItems)
8484
}())
8585
}

0 commit comments

Comments
 (0)