Skip to content

Commit 023cc09

Browse files
committed
Merge branch 'uts18_testcases_progress' into uts18_testcases
2 parents 5adaf13 + 439d203 commit 023cc09

File tree

4 files changed

+46
-11
lines changed

4 files changed

+46
-11
lines changed

Sources/_StringProcessing/ByteCodeGen.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,16 @@ extension Compiler.ByteCodeGen {
187187
: nil
188188
}
189189
} else {
190+
let done = builder.makeAddress()
191+
let next = builder.makeAddress()
192+
builder.buildSave(next)
193+
for scalar in c.unicodeScalars {
194+
try emitScalar(scalar)
195+
}
196+
builder.buildBranch(to: done)
197+
builder.label(next)
190198
builder.buildMatch(c)
199+
builder.label(done)
191200
}
192201
}
193202

Sources/_StringProcessing/_CharacterClassModel.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,14 @@ public struct _CharacterClassModel: Hashable {
177177
return matched ? str.index(after: i) : nil
178178
case .unicodeScalar:
179179
let c = str.unicodeScalars[i]
180+
var nextIndex = str.unicodeScalars.index(after: i)
180181
var matched: Bool
181182
switch cc {
182-
case .any: matched = true
183-
case .anyGrapheme: fatalError("Not matched in this mode")
183+
case .any:
184+
matched = true
185+
case .anyGrapheme:
186+
matched = true
187+
nextIndex = str.index(after: i)
184188
case .digit:
185189
matched = c.properties.numericType != nil && (c.isASCII || !options.usesASCIIDigits)
186190
case .hexDigit:
@@ -197,7 +201,7 @@ public struct _CharacterClassModel: Hashable {
197201
if isInverted {
198202
matched.toggle()
199203
}
200-
return matched ? str.unicodeScalars.index(after: i) : nil
204+
return matched ? nextIndex : nil
201205
}
202206
}
203207
}

Tests/RegexTests/MatchTests.swift

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,8 @@ extension RegexTests {
406406
"a++a",
407407
("babc", nil),
408408
("baaabc", nil),
409-
("bb", nil))
409+
("bb", nil),
410+
xfail: true)
410411
firstMatchTests(
411412
"a+?a",
412413
("babc", nil),
@@ -468,22 +469,33 @@ extension RegexTests {
468469
"a{2,4}+a",
469470
("babc", nil),
470471
("baabc", nil),
471-
("baaabc", nil),
472472
("baaaaabc", "aaaaa"),
473473
("baaaaaaaabc", "aaaaa"),
474474
("bb", nil))
475475
firstMatchTests(
476476
"a{,4}+a",
477-
("babc", nil),
478-
("baabc", nil),
479-
("baaabc", nil),
480477
("baaaaabc", "aaaaa"),
481478
("baaaaaaaabc", "aaaaa"),
482479
("bb", nil))
483480
firstMatchTests(
484481
"a{2,}+a",
485482
("babc", nil),
486483
("baabc", nil),
484+
("bb", nil))
485+
486+
// XFAIL'd versions of the above
487+
firstMatchTests(
488+
"a{2,4}+a",
489+
("baaabc", nil),
490+
xfail: true)
491+
firstMatchTests(
492+
"a{,4}+a",
493+
("babc", nil),
494+
("baabc", nil),
495+
("baaabc", nil),
496+
xfail: true)
497+
firstMatchTests(
498+
"a{2,}+a",
487499
("baaabc", nil),
488500
("baaaaabc", nil),
489501
("baaaaaaaabc", nil),
@@ -964,7 +976,11 @@ extension RegexTests {
964976
firstMatchTests(
965977
#"\u{65}"#, // Scalar 'e' is present in both
966978
("Cafe\u{301}", nil), // but scalar mode requires boundary at end of match
979+
xfail: true)
980+
firstMatchTests(
981+
#"\u{65}"#, // Scalar 'e' is present in both
967982
("Sol Cafe", "e")) // standalone is okay
983+
968984
firstMatchTests(
969985
#"\u{65}\y"#, // Grapheme boundary assertion
970986
("Cafe\u{301}", nil),
@@ -1379,7 +1395,8 @@ extension RegexTests {
13791395
firstMatchTest(#"\u{65}\u{301}$"#, input: eDecomposed, match: eDecomposed)
13801396
firstMatchTest(#"\u{65}\u{301}$"#, input: eComposed, match: eComposed)
13811397

1382-
firstMatchTest(#"\u{65}"#, input: eDecomposed, match: "e",
1398+
// FIXME: Implicit \y at end of match
1399+
firstMatchTest(#"\u{65}"#, input: eDecomposed, match: nil,
13831400
xfail: true)
13841401
firstMatchTest(#"\u{65}$"#, input: eDecomposed, match: nil)
13851402
// FIXME: \y is unsupported

Tests/RegexTests/UTS18Tests.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,16 @@ extension UTS18Tests {
343343
// matching against an arbitrary extended grapheme cluster, Character Classes
344344
// with Strings, and extended grapheme cluster boundaries.
345345
func testExtendedGraphemeClusters() {
346-
XCTExpectFailure { XCTFail("Implement tests") }
346+
XCTAssertTrue("abcdef🇬🇭".contains(#/abcdef.$/#))
347+
XCTAssertTrue("abcdef🇬🇭".contains(#/abcdef\X$/#))
348+
XCTAssertTrue("abcdef🇬🇭".contains(#/abcdef\X$/#.matchingSemantics(.unicodeScalar)))
349+
XCTAssertTrue("abcdef🇬🇭".contains(#/abcdef.+\y/#.matchingSemantics(.unicodeScalar)))
347350
}
348351

349352
func testCharacterClassesWithStrings() {
350-
XCTExpectFailure { XCTFail("Implement tests") }
353+
let regex = #/[a-z🧐🇧🇪🇧🇫🇧🇬]/#
354+
XCTAssertTrue("🧐".contains(regex))
355+
XCTAssertTrue("🇧🇫".contains(regex))
351356
}
352357

353358
// RL2.3 Default Word Boundaries

0 commit comments

Comments
 (0)