[K/N and WASM] Fix ESCAPE and COMMENTS modes
This commit is contained in:
committed by
Space
parent
7b46738796
commit
1cb5cab28f
@@ -10,6 +10,7 @@ package test.text
|
||||
import test.regexSplitUnicodeCodePointHandling
|
||||
import test.supportsNamedCapturingGroup
|
||||
import test.supportsOctalLiteralInRegex
|
||||
import test.supportsEscapeAnyCharInRegex
|
||||
import test.BackReferenceHandling
|
||||
import test.HandlingOption
|
||||
import kotlin.test.*
|
||||
@@ -59,6 +60,20 @@ class RegexTest {
|
||||
assertEquals(null, p.find(input, input.length))
|
||||
}
|
||||
|
||||
@Test fun matchEscapeSurrogatePair() {
|
||||
if (!supportsEscapeAnyCharInRegex) return
|
||||
|
||||
val regex = "\\\uD83D\uDE00".toRegex()
|
||||
assertTrue(regex.matches("\uD83D\uDE00"))
|
||||
}
|
||||
|
||||
@Test fun matchEscapeRandomChar() {
|
||||
if (!supportsEscapeAnyCharInRegex) return
|
||||
|
||||
val regex = "\\-".toRegex()
|
||||
assertTrue(regex.matches("-"))
|
||||
}
|
||||
|
||||
@Test fun matchIgnoreCase() {
|
||||
for (input in listOf("ascii", "shrödinger"))
|
||||
assertTrue(input.uppercase().matches(input.lowercase().toRegex(RegexOption.IGNORE_CASE)))
|
||||
@@ -177,12 +192,9 @@ class RegexTest {
|
||||
@Test fun matchDuplicateGroupName() {
|
||||
if (!supportsNamedCapturingGroup) return
|
||||
|
||||
assertFailsWith<IllegalArgumentException> {
|
||||
"(?<hi>hi)|(?<hi>bye)".toRegex()
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException> {
|
||||
Regex("(?<first>\\d+)-(?<first>\\d+)")
|
||||
}
|
||||
// should fail with IllegalArgumentException, but JS fails with SyntaxError
|
||||
assertFails { "(?<hi>hi)|(?<hi>bye)".toRegex() }
|
||||
assertFails { "(?<first>\\d+)-(?<first>\\d+)".toRegex() }
|
||||
}
|
||||
|
||||
@Test fun matchOptionalNamedGroup() {
|
||||
@@ -286,7 +298,7 @@ class RegexTest {
|
||||
HandlingOption.IGNORE_BACK_REFERENCE_EXPRESSION ->
|
||||
assertEquals(matchValue, pattern.toRegex().find(input)?.value)
|
||||
HandlingOption.THROW ->
|
||||
// TODO: should fail with IllegalArgumentException, but JS fails with SyntaxError
|
||||
// should fail with IllegalArgumentException, but JS fails with SyntaxError
|
||||
assertFails { pattern.toRegex() }
|
||||
HandlingOption.MATCH_NOTHING ->
|
||||
assertNull(pattern.toRegex().find(input))
|
||||
@@ -296,7 +308,7 @@ class RegexTest {
|
||||
@Test fun invalidNamedGroupDeclaration() {
|
||||
if (!supportsNamedCapturingGroup) return
|
||||
|
||||
// TODO: should fail with IllegalArgumentException, but JS fails with SyntaxError
|
||||
// should fail with IllegalArgumentException, but JS fails with SyntaxError
|
||||
|
||||
assertFails {
|
||||
"(?<".toRegex()
|
||||
@@ -318,10 +330,6 @@ class RegexTest {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Test comment mode enabled and group name is separated by space, (before, in the middle, after)
|
||||
// TODO: Test comment mode enabled and back reference group index is separated by space, (before, in the middle, after)
|
||||
// TODO: IllegalArgumentException to java.util.regex.PatternSyntaxException where possible
|
||||
|
||||
@Test fun matchMultiline() {
|
||||
val regex = "^[a-z]*$".toRegex(setOf(RegexOption.IGNORE_CASE, RegexOption.MULTILINE))
|
||||
val matchedValues = regex.findAll("test\n\nLine").map { it.value }.toList()
|
||||
|
||||
Reference in New Issue
Block a user