Skip to content

Commit 856a350

Browse files
committed
In AssertParse, by default assert that parsing does not produce any diagnostics
1 parent dc9f279 commit 856a350

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

Tests/SwiftParserTest/Assertions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func AssertEqualTokens(_ actual: [Lexer.Lexeme], _ expected: [Lexer.Lexeme], fil
5151

5252
func AssertParse<Node: RawSyntaxNodeProtocol>(
5353
_ parseSyntax: (inout Parser) -> Node,
54-
allowErrors: Bool = true,
54+
allowErrors: Bool = false,
5555
file: StaticString = #file,
5656
line: UInt = #line,
5757
_ source: () -> String

Tests/SwiftParserTest/Declarations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ final class DeclarationTests: XCTestCase {
139139
"""
140140
}
141141

142-
try AssertParse({ $0.parseSourceFile() }) {
142+
try AssertParse({ $0.parseSourceFile() }, allowErrors: true) {
143143
"_ = foo/* */?.description"
144144
}
145145

Tests/SwiftParserTest/Expressions.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ final class ExpressionTests: XCTestCase {
164164
"""
165165
}
166166

167-
try AssertParse({ $0.parseExpression() }) {
167+
try AssertParse({ $0.parseExpression() }, allowErrors: true) {
168168
"[,"
169169
}
170170

171-
try AssertParse({ $0.parseExpression() }) {
171+
try AssertParse({ $0.parseExpression() }, allowErrors: true) {
172172
"""
173173
([1:)
174174
"""
@@ -197,7 +197,7 @@ final class ExpressionTests: XCTestCase {
197197
"""#
198198
}
199199

200-
try AssertParse({ $0.parseExpression() }) {
200+
try AssertParse({ $0.parseExpression() }, allowErrors: true) {
201201
#"" >> \( abc } ) << ""#
202202
}
203203

@@ -213,7 +213,7 @@ final class ExpressionTests: XCTestCase {
213213
"""##
214214
}
215215

216-
try AssertParse({ $0.parseExpression() }) {
216+
try AssertParse({ $0.parseExpression() }, allowErrors: true) {
217217
#""\","#
218218
}
219219

@@ -249,35 +249,35 @@ final class ExpressionTests: XCTestCase {
249249
"""
250250
}
251251

252-
try AssertParse({ $0.parseExpression() }, allowErrors: false) {
252+
try AssertParse({ $0.parseExpression() }) {
253253
##"""
254254
#"""#
255255
"""##
256256
}
257257

258-
try AssertParse({ $0.parseExpression() }, allowErrors: false) {
258+
try AssertParse({ $0.parseExpression() }) {
259259
##"""
260260
#"""""#
261261
"""##
262262
}
263263

264-
try AssertParse({ $0.parseExpression() }, allowErrors: false) {
264+
try AssertParse({ $0.parseExpression() }) {
265265
##"""
266266
#"""
267267
multiline raw
268268
"""#
269269
"""##
270270
}
271271

272-
try AssertParse({ $0.parseExpression() }, allowErrors: false) {
272+
try AssertParse({ $0.parseExpression() }) {
273273
#"""
274274
"\(x)"
275275
"""#
276276
}
277277
}
278278

279279
func testRangeSubscript() throws {
280-
try AssertParse({ $0.parseExpression() }, allowErrors: false) {
280+
try AssertParse({ $0.parseExpression() }) {
281281
"""
282282
text[...]
283283
"""

Tests/SwiftParserTest/RecoveryTests.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public class RecoveryTests: XCTestCase {
1919
}
2020

2121
func testBogusKeypathBaseRecovery() throws {
22-
try AssertParse({ $0.parseSourceFile() }) {
23-
"func nestThoseIfs() {\\n if false != true {\\n print \"\\(i)\"\\n"
22+
try AssertParse({ $0.parseSourceFile() }, allowErrors: true) {
23+
#"func nestThoseIfs() {\n if false != true {\n print "\(i)\"\n"#
2424
}
2525
}
2626

@@ -37,7 +37,7 @@ public class RecoveryTests: XCTestCase {
3737
}
3838

3939
func testMissingSubscriptReturnClause() throws {
40-
try AssertParse({ $0.parseSourceFile() }) {
40+
try AssertParse({ $0.parseSourceFile() }, allowErrors: true) {
4141
"""
4242
struct Foo {
4343
subscript(x: String) {}
@@ -55,7 +55,7 @@ public class RecoveryTests: XCTestCase {
5555
}
5656

5757
func testClassWithLeadingNumber() throws {
58-
try AssertParse({ $0.parseSourceFile() }) {
58+
try AssertParse({ $0.parseSourceFile() }, allowErrors: true) {
5959
"""
6060
class 23class {
6161
// expected-error@-1 {{class name can only start with a letter or underscore, not a number}}
@@ -82,7 +82,7 @@ public class RecoveryTests: XCTestCase {
8282
}
8383

8484
func testMissingArrowInArrowExpr() throws {
85-
try AssertParse({ $0.parseSourceFile() }) {
85+
try AssertParse({ $0.parseSourceFile() }, allowErrors: true) {
8686
"""
8787
[(Int) -> throws Int]()
8888
let _ = [Int throws Int]()
@@ -130,7 +130,7 @@ public class RecoveryTests: XCTestCase {
130130
}
131131

132132
func testStringBogusClosingDelimiters() throws {
133-
try AssertParse({ $0.parseSourceFile() }) {
133+
try AssertParse({ $0.parseSourceFile() }, allowErrors: true) {
134134
#"\\("#
135135
}
136136

@@ -140,21 +140,21 @@ public class RecoveryTests: XCTestCase {
140140
"""##
141141
}
142142

143-
try AssertParse({ $0.parseStringLiteral() }) {
143+
try AssertParse({ $0.parseStringLiteral() }, allowErrors: true) {
144144
#"""
145145
"
146146
"""#
147147
}
148148

149-
try AssertParse({ $0.parseStringLiteral() }) {
149+
try AssertParse({ $0.parseStringLiteral() }, allowErrors: true) {
150150
#"""
151151
"'
152152
"""#
153153
}
154154
}
155155

156156
func testMissingArgumentToAttribute() throws {
157-
try AssertParse({ $0.parseSourceFile() }) {
157+
try AssertParse({ $0.parseSourceFile() }, allowErrors: true) {
158158
"""
159159
@_dynamicReplacement(
160160
func test_dynamic_replacement_for2() {
@@ -193,7 +193,7 @@ public class RecoveryTests: XCTestCase {
193193
}
194194

195195
func testExpressionMember() throws {
196-
try AssertParse({ $0.parseSourceFile() }) {
196+
try AssertParse({ $0.parseSourceFile() }, allowErrors: true) {
197197
"""
198198
struct S {
199199
/ ###line 25 "line-directive.swift"
@@ -213,7 +213,7 @@ public class RecoveryTests: XCTestCase {
213213
}
214214

215215
func testExtraSyntaxInDirective() throws {
216-
try AssertParse({ $0.parseDeclaration() }) {
216+
try AssertParse({ $0.parseDeclaration() }, allowErrors: true) {
217217
"""
218218
#if os(iOS)
219219
func foo() {}
@@ -343,7 +343,7 @@ public class RecoveryTests: XCTestCase {
343343
}
344344

345345
func testTextRecovery() throws {
346-
try AssertParse({ $0.parseSourceFile() }) {
346+
try AssertParse({ $0.parseSourceFile() }, allowErrors: true) {
347347
"""
348348
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
349349
"""

Tests/SwiftParserTest/Statements.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ final class StatementTests: XCTestCase {
1010
"""
1111
}
1212

13-
try AssertParse({ $0.parseIfStatement() }) {
13+
try AssertParse({ $0.parseIfStatement() }, allowErrors: true) {
1414
"""
1515
if case* ! = x {
1616
bar()

0 commit comments

Comments
 (0)