Skip to content

Commit

Permalink
Expand variadic compilation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
natecook1000 committed Apr 23, 2024
1 parent 9430a76 commit a82307b
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions Tests/RegexBuilderTests/RegexDSLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1842,6 +1842,8 @@ fileprivate let regexWithCapture = #/:(\d+):/#
fileprivate let regexWithLabeledCapture = #/:(?<number>\d+):/#
@available(SwiftStdlib 5.7, *)
fileprivate let regexWithNonCapture = #/:(?:\d+):/#
@available(SwiftStdlib 5.7, *)
fileprivate let regexWithMultipleCaptures = #/:(\d+):(.+):(\d+):/#

@available(SwiftStdlib 5.7, *)
extension RegexDSLTests {
Expand Down Expand Up @@ -1949,6 +1951,7 @@ extension RegexDSLTests {
XCTAssertEqual(match.output.1, "AAA")
// FIXME (Variadics): match.output.2 is no longer an `Int`
// XCTAssertEqual(match.output.2, 123)
// FIXME (Variadics): match.output.3 is now the second letter of `regexWithTooManyCaptures`, i.e. "b"
XCTAssertEqual(match.output.3, "456")

// All captures groups are available through `AnyRegexOutput`.
Expand Down Expand Up @@ -2029,6 +2032,93 @@ extension RegexDSLTests {
XCTAssertEqual(match.output.2, "b")
XCTAssertNil(match.output.3)
}

func testVariadicNesting_Compilation() {
let regex_OC = Regex { // sOCsco
"a"
Optionally {
Capture { "b" }
}
}
let _: Regex<(Substring, Substring?)> = regex_OC

let regex_OCC = Regex {
"a"
Optionally {
Capture { "b" }
Capture { "c" }
}
}
let _: Regex<(Substring, Substring?, Substring?)> = regex_OCC

let regex_O_OC = Regex {
Optionally {
regex_OC
}
}
let _: Regex<(Substring, Substring??)> = regex_O_OC

let regex_O_OCC = Regex {
Optionally {
regex_OCC
}
}
let _: Regex<(Substring, Substring??, Substring??)> = regex_O_OCC

let regex_O_OC_OC = Regex {
Optionally {
regex_OC
regex_OC
}
}
let _: Regex<(Substring, Substring??, Substring??)> = regex_O_OC_OC

let regex_O_OCC_OC = Regex {
Optionally {
regex_OCC
regex_OC
}
}
let _: Regex<(Substring, Substring??, Substring??, Substring??)> = regex_O_OCC_OC

let regex_O_OCC_OCC = Regex {
Optionally {
regex_OCC
regex_OCC
}
}
let _: Regex<(Substring, Substring??, Substring??, Substring??, Substring??)> = regex_O_OCC_OCC

let regexChoices_CCOC = Regex {
ChoiceOf {
Capture { "A" }
"b"
"c"
Capture { "D" }
Optionally {
Capture {
"E"
}
}
}
}
let _: Regex<(Substring, Substring?, Substring?, Substring??)> = regexChoices_CCOC

let regex_Zr3Mr3MOr3 = Regex {
ZeroOrMore {
regexWithMultipleCaptures
}
OneOrMore {
regexWithMultipleCaptures
}
OneOrMore {
Optionally {
regexWithMultipleCaptures
}
}
}
let _: Regex<(Substring, Substring?, Substring?, Substring?, Substring, Substring, Substring, Substring?, Substring?, Substring?)> = regex_Zr3Mr3MOr3
}
}

extension Unicode.Scalar {
Expand Down

0 comments on commit a82307b

Please sign in to comment.