@@ -31,6 +31,43 @@ class AllActiveVisitor: ActiveSyntaxAnyVisitor<TestingBuildConfiguration> {
31
31
}
32
32
}
33
33
34
+ class NameCheckingVisitor : ActiveSyntaxAnyVisitor < TestingBuildConfiguration > {
35
+ /// The set of names we are expected to visit. Any syntax nodes with
36
+ /// names that aren't here will be rejected, and each of the names listed
37
+ /// here must occur exactly once.
38
+ var expectedNames : Set < String >
39
+
40
+ init ( configuration: TestingBuildConfiguration , expectedNames: Set < String > ) {
41
+ self . expectedNames = expectedNames
42
+
43
+ super. init ( viewMode: . sourceAccurate, configuration: configuration)
44
+ }
45
+
46
+ deinit {
47
+ if !expectedNames. isEmpty {
48
+ XCTFail ( " No nodes with expected names visited: \( expectedNames) " )
49
+ }
50
+ }
51
+
52
+ func checkName( name: String , node: Syntax ) {
53
+ if !expectedNames. contains ( name) {
54
+ XCTFail ( " syntax node with unexpected name \( name) found: \( node. debugDescription) " )
55
+ }
56
+
57
+ expectedNames. remove ( name)
58
+ }
59
+
60
+ open override func visitAny( _ node: Syntax ) -> SyntaxVisitorContinueKind {
61
+ if let identified = node. asProtocol ( NamedDeclSyntax . self) {
62
+ checkName ( name: identified. name. text, node: node)
63
+ } else if let identPattern = node. as ( IdentifierPatternSyntax . self) {
64
+ // FIXME: Should the above be an IdentifiedDeclSyntax?
65
+ checkName ( name: identPattern. identifier. text, node: node)
66
+ }
67
+
68
+ return . visitChildren
69
+ }
70
+ }
34
71
public class VisitorTests : XCTestCase {
35
72
let linuxBuildConfig = TestingBuildConfiguration (
36
73
customConditions: [ " DEBUG " , " ASSERTS " ] ,
@@ -95,6 +132,12 @@ public class VisitorTests: XCTestCase {
95
132
#endif
96
133
}
97
134
#endif
135
+
136
+ #if hasAttribute(available)
137
+ func withAvail() { }
138
+ #else
139
+ func notAvail() { }
140
+ #endif
98
141
"""
99
142
100
143
func testAnyVisitorVisitsOnlyActive( ) throws {
@@ -104,56 +147,29 @@ public class VisitorTests: XCTestCase {
104
147
}
105
148
106
149
func testVisitsExpectedNodes( ) throws {
107
- class NameCheckingVisitor : ActiveSyntaxAnyVisitor < TestingBuildConfiguration > {
108
- /// The set of names we are expected to visit. Any syntax nodes with
109
- /// names that aren't here will be rejected, and each of the names listed
110
- /// here must occur exactly once.
111
- var expectedNames : Set < String >
112
-
113
- init ( configuration: TestingBuildConfiguration , expectedNames: Set < String > ) {
114
- self . expectedNames = expectedNames
115
-
116
- super. init ( viewMode: . sourceAccurate, configuration: configuration)
117
- }
118
-
119
- deinit {
120
- if !expectedNames. isEmpty {
121
- XCTFail ( " No nodes with expected names visited: \( expectedNames) " )
122
- }
123
- }
124
-
125
- func checkName( name: String , node: Syntax ) {
126
- if !expectedNames. contains ( name) {
127
- XCTFail ( " syntax node with unexpected name \( name) found: \( node. debugDescription) " )
128
- }
129
-
130
- expectedNames. remove ( name)
131
- }
132
-
133
- open override func visitAny( _ node: Syntax ) -> SyntaxVisitorContinueKind {
134
- if let identified = node. asProtocol ( NamedDeclSyntax . self) {
135
- checkName ( name: identified. name. text, node: node)
136
- } else if let identPattern = node. as ( IdentifierPatternSyntax . self) {
137
- // FIXME: Should the above be an IdentifiedDeclSyntax?
138
- checkName ( name: identPattern. identifier. text, node: node)
139
- }
140
-
141
- return . visitChildren
142
- }
143
- }
144
-
145
150
// Check that the right set of names is visited.
146
151
NameCheckingVisitor (
147
152
configuration: linuxBuildConfig,
148
- expectedNames: [ " f " , " h " , " i " , " S " , " generationCount " , " value " ]
153
+ expectedNames: [ " f " , " h " , " i " , " S " , " generationCount " , " value " , " withAvail " ]
149
154
) . walk ( inputSource)
150
155
151
156
NameCheckingVisitor (
152
157
configuration: iosBuildConfig,
153
- expectedNames: [ " g " , " h " , " i " , " a " , " S " , " generationCount " , " value " , " error " ]
158
+ expectedNames: [ " g " , " h " , " i " , " a " , " S " , " generationCount " , " value " , " error " , " withAvail " ]
154
159
) . walk ( inputSource)
155
160
}
156
161
162
+ func testVisitorWithErrors( ) throws {
163
+ var configuration = linuxBuildConfig
164
+ configuration. badAttributes. insert ( " available " )
165
+ let visitor = NameCheckingVisitor (
166
+ configuration: configuration,
167
+ expectedNames: [ " f " , " h " , " i " , " S " , " generationCount " , " value " , " withAvail " , " notAvail " ]
168
+ )
169
+ visitor. walk ( inputSource)
170
+ XCTAssertEqual ( visitor. diagnostics. count, 3 )
171
+ }
172
+
157
173
func testRemoveInactive( ) {
158
174
assertStringsEqualWithDiff (
159
175
inputSource. removingInactive ( in: linuxBuildConfig) . description,
@@ -179,6 +195,7 @@ public class VisitorTests: XCTestCase {
179
195
.c
180
196
.d()
181
197
}
198
+ func withAvail() { }
182
199
"""
183
200
)
184
201
}
0 commit comments