Skip to content

Add type annotations in RegexBuilder tests #628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Sources/_StringProcessing/MatchingOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
/// A type that represents the current state of regex matching options, with
/// stack-based scoping.
struct MatchingOptions {
fileprivate var stack: [Representation]
// FIXME: Workaround for rdar://104923020
// fileprivate
var stack: [Representation]

fileprivate func _invariantCheck() {
assert(!stack.isEmpty, "Unbalanced call to endScope")
Expand Down Expand Up @@ -125,7 +127,9 @@ extension MatchingOptions {
// MARK: - Implementation
extension MatchingOptions {
/// An option that changes the behavior of a regular expression.
fileprivate enum Option: Int {
// FIXME: Workaround for rdar://104923020
// fileprivate
enum Option: Int {
// PCRE options
case caseInsensitive
case allowDuplicateGroupNames
Expand Down Expand Up @@ -212,7 +216,9 @@ extension MatchingOptions {

extension MatchingOptions {
/// A set of matching options.
fileprivate struct Representation: OptionSet, RawRepresentable {
// FIXME: Workaround for rdar://104923020
// fileprivate
struct Representation: OptionSet, RawRepresentable {
var rawValue: UInt32

/// Returns `true` if the option denoted by `kind` is a member of this set.
Expand Down
18 changes: 9 additions & 9 deletions Tests/RegexBuilderTests/CustomTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class CustomRegexComponentTests: XCTestCase {
// tests.
func testCustomRegexComponents() throws {
customTest(
Regex {
Regex<Substring> {
Numbler()
Asciibbler()
},
Expand All @@ -194,7 +194,7 @@ class CustomRegexComponentTests: XCTestCase {
("t4", .match, nil))

customTest(
Regex {
Regex<Substring> {
OneOrMore { Numbler() }
},
("ab123c", .firstMatch, "123"),
Expand Down Expand Up @@ -425,7 +425,7 @@ class CustomRegexComponentTests: XCTestCase {
)

customTest(
Regex {
Regex<CurrencyParser.Currency> {
CurrencyParser()
},
("USD", .usd, nil),
Expand All @@ -437,7 +437,7 @@ class CustomRegexComponentTests: XCTestCase {

// No capture, two errors
customTest(
Regex {
Regex<Substring> {
IntParser()
" "
IntParser()
Expand All @@ -449,7 +449,7 @@ class CustomRegexComponentTests: XCTestCase {
)

customTest(
Regex {
Regex<Substring> {
CurrencyParser()
IntParser()
},
Expand All @@ -462,7 +462,7 @@ class CustomRegexComponentTests: XCTestCase {
// One capture, two errors: One error is thrown from inside a capture,
// while the other one is thrown from outside
customTest(
Regex {
Regex<(Substring, CurrencyParser.Currency)> {
Capture { CurrencyParser() }
IntParser()
},
Expand All @@ -473,7 +473,7 @@ class CustomRegexComponentTests: XCTestCase {
)

customTest(
Regex {
Regex<(Substring, Int)> {
CurrencyParser()
Capture { IntParser() }
},
Expand All @@ -485,7 +485,7 @@ class CustomRegexComponentTests: XCTestCase {

// One capture, two errors: Both errors are thrown from inside the capture
customTest(
Regex {
Regex<(Substring, Substring)> {
Capture {
CurrencyParser()
IntParser()
Expand All @@ -499,7 +499,7 @@ class CustomRegexComponentTests: XCTestCase {

// Two captures, two errors: Different erros are thrown from inside captures
customTest(
Regex {
Regex<(Substring, CurrencyParser.Currency, Int)> {
Capture(CurrencyParser())
Capture(IntParser())
},
Expand Down
12 changes: 6 additions & 6 deletions Tests/RegexBuilderTests/MotivationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ extension RegexDSLTests {
"CREDIT"
"DEBIT"
}
} transform: {
TransactionKind(rawValue: String($0))
} transform: { (s: Substring) in
TransactionKind(rawValue: String(s))
}

OneOrMore(.whitespace)
Expand All @@ -322,8 +322,8 @@ extension RegexDSLTests {
Repeat(.digit, count: 2)
Repeat(.digit, count: 2)
Repeat(.digit, count: 4)
} transform: {
Date(mmddyyyy: String($0))
} transform: { (s: Substring) in
Date(mmddyyyy: String(s))
}

OneOrMore(.whitespace)
Expand All @@ -345,8 +345,8 @@ extension RegexDSLTests {
OneOrMore(.digit)
"."
Repeat(.digit, count: 2)
} transform: {
Double($0)
} transform: { (s: Substring) in
Double(s)
}
}

Expand Down
10 changes: 5 additions & 5 deletions Tests/RegexBuilderTests/RegexDSLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1253,8 +1253,8 @@ class RegexDSLTests: XCTestCase {
TryCapture(as: b) {
"#"
OneOrMore(.digit)
} transform: {
Int($0.dropFirst())
} transform: { (s: Substring) in
Int(s.dropFirst())
}
}
a
Expand All @@ -1271,14 +1271,14 @@ class RegexDSLTests: XCTestCase {
do {
let a = Reference(Substring.self)
let b = Reference(Int.self)
let regex = Regex {
let regex = Regex<(Substring, Substring, Int?, Int?, Substring?)> {
Capture("abc", as: a)
ZeroOrMore {
TryCapture(as: b) {
"#"
OneOrMore(.digit)
} transform: {
Int($0.dropFirst())
} transform: { (s: Substring) -> Int? in
Int(s.dropFirst())
}
}
a
Expand Down