Skip to content

Avoid long expression type checks #657

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
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
2 changes: 1 addition & 1 deletion Tests/RegexBuilderTests/AlgorithmsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import RegexBuilder
@available(SwiftStdlib 5.7, *)
class RegexConsumerTests: XCTestCase {
func testMatches() {
let regex = Capture(OneOrMore(.digit)) { 2 * Int($0)! }
let regex = Capture<(Substring, Int)>(OneOrMore(.digit)) { 2 * Int($0)! }
let str = "foo 160 bar 99 baz"
XCTAssertEqual(str.matches(of: regex).map(\.output.1), [320, 198])
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/RegexBuilderTests/CustomTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private struct IntParser: CustomConsumingRegexComponent {
guard index != bounds.upperBound else { return nil }

let r = Regex {
Capture(OneOrMore(.digit)) { Int($0) }
Capture<(Substring, Int?)>(OneOrMore(.digit)) { Int($0) }
}

guard let match = input[index..<bounds.upperBound].prefixMatch(of: r),
Expand Down Expand Up @@ -694,7 +694,7 @@ class CustomRegexComponentTests: XCTestCase {
OneOrMore {
CharacterClass("A"..."Z")
OneOrMore(CharacterClass("a"..."z"))
Capture(Repeat(.digit, count: 2)) { Int($0) }
Capture<(Substring, Int?)>(Repeat(.digit, count: 2)) { Int($0) }
}
}

Expand Down
10 changes: 5 additions & 5 deletions Tests/RegexBuilderTests/RegexDSLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ class RegexDSLTests: XCTestCase {
OneOrMore("a")
Capture {
TryCapture("b", transform: { Int($0) })
ZeroOrMore(
ZeroOrMore<(Substring, Double?)>(
TryCapture("c", transform: { Double($0) })
)
Optionally("e")
Expand Down Expand Up @@ -1542,12 +1542,12 @@ class RegexDSLTests: XCTestCase {
in bounds: Range<String.Index>
) throws -> (upperBound: String.Index, output: SemanticVersion)? {
let regex = Regex {
TryCapture(OneOrMore(.digit)) { Int($0) }
TryCapture<(Substring, Int)>(OneOrMore(.digit)) { Int($0) }
"."
TryCapture(OneOrMore(.digit)) { Int($0) }
TryCapture<(Substring, Int)>(OneOrMore(.digit)) { Int($0) }
Optionally {
"."
TryCapture(OneOrMore(.digit)) { Int($0) }
TryCapture<(Substring, Int)>(OneOrMore(.digit)) { Int($0) }
}
Optionally {
"-"
Expand Down Expand Up @@ -1876,7 +1876,7 @@ extension RegexDSLTests {
":"
regexWithTooManyCaptures
":"
TryCapture(OneOrMore(.word)) { Int($0) }
TryCapture<(Substring, Int)>(OneOrMore(.word)) { Int($0) }
#/:(\d+):/#
}
XCTAssert(type(of: dslWithTooManyCaptures).self
Expand Down