Skip to content

Commit 7e059b7

Browse files
authored
Merge pull request #628 from apple/result_builder_changes_workaround
Add type annotations in RegexBuilder tests
2 parents 3ca8b13 + 6c4f291 commit 7e059b7

File tree

4 files changed

+29
-23
lines changed

4 files changed

+29
-23
lines changed

Sources/_StringProcessing/MatchingOptions.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
/// A type that represents the current state of regex matching options, with
1515
/// stack-based scoping.
1616
struct MatchingOptions {
17-
fileprivate var stack: [Representation]
17+
// FIXME: Workaround for rdar://104923020
18+
// fileprivate
19+
var stack: [Representation]
1820

1921
fileprivate func _invariantCheck() {
2022
assert(!stack.isEmpty, "Unbalanced call to endScope")
@@ -125,7 +127,9 @@ extension MatchingOptions {
125127
// MARK: - Implementation
126128
extension MatchingOptions {
127129
/// An option that changes the behavior of a regular expression.
128-
fileprivate enum Option: Int {
130+
// FIXME: Workaround for rdar://104923020
131+
// fileprivate
132+
enum Option: Int {
129133
// PCRE options
130134
case caseInsensitive
131135
case allowDuplicateGroupNames
@@ -212,7 +216,9 @@ extension MatchingOptions {
212216

213217
extension MatchingOptions {
214218
/// A set of matching options.
215-
fileprivate struct Representation: OptionSet, RawRepresentable {
219+
// FIXME: Workaround for rdar://104923020
220+
// fileprivate
221+
struct Representation: OptionSet, RawRepresentable {
216222
var rawValue: UInt32
217223

218224
/// Returns `true` if the option denoted by `kind` is a member of this set.

Tests/RegexBuilderTests/CustomTests.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class CustomRegexComponentTests: XCTestCase {
183183
// tests.
184184
func testCustomRegexComponents() throws {
185185
customTest(
186-
Regex {
186+
Regex<Substring> {
187187
Numbler()
188188
Asciibbler()
189189
},
@@ -194,7 +194,7 @@ class CustomRegexComponentTests: XCTestCase {
194194
("t4", .match, nil))
195195

196196
customTest(
197-
Regex {
197+
Regex<Substring> {
198198
OneOrMore { Numbler() }
199199
},
200200
("ab123c", .firstMatch, "123"),
@@ -425,7 +425,7 @@ class CustomRegexComponentTests: XCTestCase {
425425
)
426426

427427
customTest(
428-
Regex {
428+
Regex<CurrencyParser.Currency> {
429429
CurrencyParser()
430430
},
431431
("USD", .usd, nil),
@@ -437,7 +437,7 @@ class CustomRegexComponentTests: XCTestCase {
437437

438438
// No capture, two errors
439439
customTest(
440-
Regex {
440+
Regex<Substring> {
441441
IntParser()
442442
" "
443443
IntParser()
@@ -449,7 +449,7 @@ class CustomRegexComponentTests: XCTestCase {
449449
)
450450

451451
customTest(
452-
Regex {
452+
Regex<Substring> {
453453
CurrencyParser()
454454
IntParser()
455455
},
@@ -462,7 +462,7 @@ class CustomRegexComponentTests: XCTestCase {
462462
// One capture, two errors: One error is thrown from inside a capture,
463463
// while the other one is thrown from outside
464464
customTest(
465-
Regex {
465+
Regex<(Substring, CurrencyParser.Currency)> {
466466
Capture { CurrencyParser() }
467467
IntParser()
468468
},
@@ -473,7 +473,7 @@ class CustomRegexComponentTests: XCTestCase {
473473
)
474474

475475
customTest(
476-
Regex {
476+
Regex<(Substring, Int)> {
477477
CurrencyParser()
478478
Capture { IntParser() }
479479
},
@@ -485,7 +485,7 @@ class CustomRegexComponentTests: XCTestCase {
485485

486486
// One capture, two errors: Both errors are thrown from inside the capture
487487
customTest(
488-
Regex {
488+
Regex<(Substring, Substring)> {
489489
Capture {
490490
CurrencyParser()
491491
IntParser()
@@ -499,7 +499,7 @@ class CustomRegexComponentTests: XCTestCase {
499499

500500
// Two captures, two errors: Different erros are thrown from inside captures
501501
customTest(
502-
Regex {
502+
Regex<(Substring, CurrencyParser.Currency, Int)> {
503503
Capture(CurrencyParser())
504504
Capture(IntParser())
505505
},

Tests/RegexBuilderTests/MotivationTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ extension RegexDSLTests {
309309
"CREDIT"
310310
"DEBIT"
311311
}
312-
} transform: {
313-
TransactionKind(rawValue: String($0))
312+
} transform: { (s: Substring) in
313+
TransactionKind(rawValue: String(s))
314314
}
315315

316316
OneOrMore(.whitespace)
@@ -322,8 +322,8 @@ extension RegexDSLTests {
322322
Repeat(.digit, count: 2)
323323
Repeat(.digit, count: 2)
324324
Repeat(.digit, count: 4)
325-
} transform: {
326-
Date(mmddyyyy: String($0))
325+
} transform: { (s: Substring) in
326+
Date(mmddyyyy: String(s))
327327
}
328328

329329
OneOrMore(.whitespace)
@@ -345,8 +345,8 @@ extension RegexDSLTests {
345345
OneOrMore(.digit)
346346
"."
347347
Repeat(.digit, count: 2)
348-
} transform: {
349-
Double($0)
348+
} transform: { (s: Substring) in
349+
Double(s)
350350
}
351351
}
352352

Tests/RegexBuilderTests/RegexDSLTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,8 +1253,8 @@ class RegexDSLTests: XCTestCase {
12531253
TryCapture(as: b) {
12541254
"#"
12551255
OneOrMore(.digit)
1256-
} transform: {
1257-
Int($0.dropFirst())
1256+
} transform: { (s: Substring) in
1257+
Int(s.dropFirst())
12581258
}
12591259
}
12601260
a
@@ -1271,14 +1271,14 @@ class RegexDSLTests: XCTestCase {
12711271
do {
12721272
let a = Reference(Substring.self)
12731273
let b = Reference(Int.self)
1274-
let regex = Regex {
1274+
let regex = Regex<(Substring, Substring, Int?, Int?, Substring?)> {
12751275
Capture("abc", as: a)
12761276
ZeroOrMore {
12771277
TryCapture(as: b) {
12781278
"#"
12791279
OneOrMore(.digit)
1280-
} transform: {
1281-
Int($0.dropFirst())
1280+
} transform: { (s: Substring) -> Int? in
1281+
Int(s.dropFirst())
12821282
}
12831283
}
12841284
a

0 commit comments

Comments
 (0)