Skip to content

Commit 510e76d

Browse files
committed
Move options from RegexComponent to Regex
1 parent 7752047 commit 510e76d

File tree

2 files changed

+44
-27
lines changed

2 files changed

+44
-27
lines changed

Sources/_StringProcessing/Regex/Options.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@_implementationOnly import _RegexParser
1313

1414
@available(SwiftStdlib 5.7, *)
15-
extension RegexComponent {
15+
extension Regex {
1616
/// Returns a regular expression that ignores case when matching.
1717
///
1818
/// - Parameter ignoresCase: A Boolean value indicating whether to ignore case.

Tests/RegexBuilderTests/RegexDSLTests.swift

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,10 @@ class RegexDSLTests: XCTestCase {
238238
("abcabc", "abcabc"),
239239
("abcABCaBc", "abcABCaBc"),
240240
matchType: Substring.self, ==) {
241-
OneOrMore {
242-
"abc"
241+
Regex {
242+
OneOrMore {
243+
"abc"
244+
}
243245
}.ignoresCase(true)
244246
}
245247

@@ -251,8 +253,10 @@ class RegexDSLTests: XCTestCase {
251253
("abcabc", "abcabc"),
252254
("abcABCaBc", "abcABCaBc"),
253255
matchType: Substring.self, ==) {
254-
OneOrMore {
255-
"abc"
256+
Regex {
257+
OneOrMore {
258+
"abc"
259+
}
256260
}
257261
.ignoresCase(true)
258262
.ignoresCase(false)
@@ -268,9 +272,13 @@ class RegexDSLTests: XCTestCase {
268272
("abcabc", "abcabc"),
269273
("abcdeABCdeaBcde", "abcdeABCdeaBcde"),
270274
matchType: Substring.self, ==) {
271-
OneOrMore {
272-
"abc".ignoresCase(true)
273-
Optionally("de")
275+
Regex {
276+
OneOrMore {
277+
Regex {
278+
"abc"
279+
}.ignoresCase(true)
280+
Optionally("de")
281+
}
274282
}
275283
.ignoresCase(false)
276284
}
@@ -307,11 +315,13 @@ class RegexDSLTests: XCTestCase {
307315
"stop"
308316
" "
309317

310-
Capture {
311-
OneOrMore(.word)
312-
Anchor.wordBoundary
313-
}
314-
.wordBoundaryKind(.unicodeLevel1)
318+
Regex {
319+
Capture {
320+
OneOrMore(.word)
321+
Anchor.wordBoundary
322+
}
323+
}.wordBoundaryKind(.unicodeLevel1)
324+
315325
OneOrMore(.any, .reluctant)
316326
"stop"
317327
}
@@ -321,15 +331,17 @@ class RegexDSLTests: XCTestCase {
321331
matchType: (Substring, Substring, Substring).self, ==) {
322332
Capture {
323333
// Reluctant behavior due to option
324-
OneOrMore(.anyOf("abcd"))
325-
.repetitionBehavior(.reluctant)
334+
Regex {
335+
OneOrMore(.anyOf("abcd"))
336+
}.repetitionBehavior(.reluctant)
326337
}
327338
ZeroOrMore("a"..."z")
328339

329340
Capture {
330341
// Eager behavior due to explicit parameter, despite option
331-
OneOrMore(.digit, .eager)
332-
.repetitionBehavior(.reluctant)
342+
Regex {
343+
OneOrMore(.digit, .eager)
344+
}.repetitionBehavior(.reluctant)
333345
}
334346
ZeroOrMore(.digit)
335347
}
@@ -338,10 +350,11 @@ class RegexDSLTests: XCTestCase {
338350
("abcdefg", ("abcdefg", "abcdefg")),
339351
("abcdéfg", ("abcdéfg", "abcd")),
340352
matchType: (Substring, Substring).self, ==) {
341-
Capture {
342-
OneOrMore(.word)
343-
}
344-
.asciiOnlyWordCharacters()
353+
Regex {
354+
Capture {
355+
OneOrMore(.word)
356+
}
357+
}.asciiOnlyWordCharacters()
345358

346359
ZeroOrMore(.any)
347360
}
@@ -372,8 +385,10 @@ class RegexDSLTests: XCTestCase {
372385
("abc1def2", ("abc1def2", "1")),
373386
matchType: (Substring, Substring).self, ==)
374387
{
375-
OneOrMore(.reluctant) {
376-
One(.word)
388+
Regex {
389+
OneOrMore(.reluctant) {
390+
One(.word)
391+
}
377392
}.repetitionBehavior(.possessive)
378393
Capture(.digit)
379394
ZeroOrMore(.any)
@@ -425,8 +440,9 @@ class RegexDSLTests: XCTestCase {
425440
{
426441
Regex {
427442
Capture {
428-
OneOrMore("a")
429-
.repetitionBehavior(.eager)
443+
Regex {
444+
OneOrMore("a")
445+
}.repetitionBehavior(.eager)
430446
}
431447
OneOrMore("a")
432448
}.repetitionBehavior(.possessive)
@@ -438,8 +454,9 @@ class RegexDSLTests: XCTestCase {
438454
{
439455
Regex {
440456
Capture {
441-
OneOrMore("a")
442-
.repetitionBehavior(.reluctant)
457+
Regex {
458+
OneOrMore("a")
459+
}.repetitionBehavior(.reluctant)
443460
}
444461
OneOrMore("a")
445462
}.repetitionBehavior(.possessive)

0 commit comments

Comments
 (0)