Fix regular expression tests.
This commit is contained in:
@@ -25,8 +25,8 @@ class PatternSyntaxExceptionTest {
|
|||||||
val regex = "("
|
val regex = "("
|
||||||
try {
|
try {
|
||||||
Regex(regex)
|
Regex(regex)
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
// TODO: Check the exception's properties.
|
// TODO: Check the exception's properties.
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,8 +36,8 @@ class PatternSyntaxExceptionTest {
|
|||||||
val regex = "[4-"
|
val regex = "[4-"
|
||||||
try {
|
try {
|
||||||
Regex(regex)
|
Regex(regex)
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -238,32 +238,32 @@ class PatternTest {
|
|||||||
var pattern = "b)a"
|
var pattern = "b)a"
|
||||||
try {
|
try {
|
||||||
Regex(pattern)
|
Regex(pattern)
|
||||||
fail("Expected a PatternSyntaxException when compiling pattern: " + pattern)
|
fail("Expected a IllegalArgumentException when compiling pattern: " + pattern)
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
// pass
|
// pass
|
||||||
}
|
}
|
||||||
|
|
||||||
pattern = "bcde)a"
|
pattern = "bcde)a"
|
||||||
try {
|
try {
|
||||||
Regex(pattern)
|
Regex(pattern)
|
||||||
fail("Expected a PatternSyntaxException when compiling pattern: " + pattern)
|
fail("Expected a IllegalArgumentException when compiling pattern: " + pattern)
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
// pass
|
// pass
|
||||||
}
|
}
|
||||||
|
|
||||||
pattern = "bbg())a"
|
pattern = "bbg())a"
|
||||||
try {
|
try {
|
||||||
Regex(pattern)
|
Regex(pattern)
|
||||||
fail("Expected a PatternSyntaxException when compiling pattern: " + pattern)
|
fail("Expected a IllegalArgumentException when compiling pattern: " + pattern)
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
// pass
|
// pass
|
||||||
}
|
}
|
||||||
|
|
||||||
pattern = "cdb(?i))a"
|
pattern = "cdb(?i))a"
|
||||||
try {
|
try {
|
||||||
Regex(pattern)
|
Regex(pattern)
|
||||||
fail("Expected a PatternSyntaxException when compiling pattern: " + pattern)
|
fail("Expected a IllegalArgumentException when compiling pattern: " + pattern)
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
// pass
|
// pass
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,8 +286,8 @@ class PatternTest {
|
|||||||
for (element in patterns) {
|
for (element in patterns) {
|
||||||
try {
|
try {
|
||||||
Regex(element)
|
Regex(element)
|
||||||
fail("PatternSyntaxException was expected, but compilation succeeds")
|
fail("IllegalArgumentException was expected, but compilation succeeds")
|
||||||
} catch (pse: PatternSyntaxException) {
|
} catch (pse: IllegalArgumentException) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,8 +350,8 @@ class PatternTest {
|
|||||||
for (element in neg_patterns) {
|
for (element in neg_patterns) {
|
||||||
try {
|
try {
|
||||||
Regex(element)
|
Regex(element)
|
||||||
fail("PatternSyntaxException was expected: " + element)
|
fail("IllegalArgumentException was expected: " + element)
|
||||||
} catch (pse: PatternSyntaxException) {
|
} catch (pse: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -393,8 +393,8 @@ class PatternTest {
|
|||||||
@Test fun testOrphanQuantifiers() {
|
@Test fun testOrphanQuantifiers() {
|
||||||
try {
|
try {
|
||||||
Regex("+++++")
|
Regex("+++++")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (pse: PatternSyntaxException) {
|
} catch (pse: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -402,8 +402,8 @@ class PatternTest {
|
|||||||
@Test fun testOrphanQuantifiers2() {
|
@Test fun testOrphanQuantifiers2() {
|
||||||
try {
|
try {
|
||||||
Regex("\\d+*")
|
Regex("\\d+*")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (pse: PatternSyntaxException) {
|
} catch (pse: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -561,8 +561,8 @@ class PatternTest {
|
|||||||
@Test fun testIllegalEscape() {
|
@Test fun testIllegalEscape() {
|
||||||
try {
|
try {
|
||||||
Regex("\\y")
|
Regex("\\y")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (pse: PatternSyntaxException) {
|
} catch (pse: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -742,7 +742,7 @@ class PatternTest {
|
|||||||
Regex("(?:)", setOf(RegexOption.CANON_EQ, RegexOption.IGNORE_CASE))
|
Regex("(?:)", setOf(RegexOption.CANON_EQ, RegexOption.IGNORE_CASE))
|
||||||
Regex("(?:)", setOf(RegexOption.CANON_EQ, RegexOption.COMMENTS, RegexOption.UNIX_LINES))
|
Regex("(?:)", setOf(RegexOption.CANON_EQ, RegexOption.COMMENTS, RegexOption.UNIX_LINES))
|
||||||
isCompiled = true
|
isCompiled = true
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
println(e)
|
println(e)
|
||||||
}
|
}
|
||||||
assertTrue(isCompiled)
|
assertTrue(isCompiled)
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ class PatternTest2 {
|
|||||||
assertNotNull(result)
|
assertNotNull(result)
|
||||||
assertEquals(6, result!!.range.start)
|
assertEquals(6, result!!.range.start)
|
||||||
assertEquals(9, result.range.endInclusive + 1)
|
assertEquals(9, result.range.endInclusive + 1)
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
println(e.message)
|
println(e.message)
|
||||||
fail()
|
fail()
|
||||||
}
|
}
|
||||||
@@ -249,51 +249,51 @@ class PatternTest2 {
|
|||||||
// Test invalid unicode sequences // TODO: Double check it.
|
// Test invalid unicode sequences // TODO: Double check it.
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\u")
|
regex = Regex("\\u")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\u;")
|
regex = Regex("\\u;")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\u002")
|
regex = Regex("\\u002")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\u002;")
|
regex = Regex("\\u002;")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test invalid hex sequences
|
// Test invalid hex sequences
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\x")
|
regex = Regex("\\x")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\x;")
|
regex = Regex("\\x;")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\xa")
|
regex = Regex("\\xa")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\xa;")
|
regex = Regex("\\xa;")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test \0 (octal) sequences (1, 2 and 3 digit)
|
// Test \0 (octal) sequences (1, 2 and 3 digit)
|
||||||
@@ -312,20 +312,20 @@ class PatternTest2 {
|
|||||||
// Test invalid octal sequences
|
// Test invalid octal sequences
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\08")
|
regex = Regex("\\08")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\0")
|
regex = Regex("\\0")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\0;")
|
regex = Regex("\\0;")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test \c (control character) sequence
|
// Test \c (control character) sequence
|
||||||
@@ -364,8 +364,8 @@ class PatternTest2 {
|
|||||||
// Test invalid control escapes
|
// Test invalid control escapes
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\c")
|
regex = Regex("\\c")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -456,8 +456,8 @@ class PatternTest2 {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
regex = Regex("[[abc]&&")
|
regex = Regex("[[abc]&&")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
regex = Regex("[[abc]\\&&[xyz]]")
|
regex = Regex("[[abc]\\&&[xyz]]")
|
||||||
@@ -561,38 +561,38 @@ class PatternTest2 {
|
|||||||
// Invalid uses of \p{Lower}
|
// Invalid uses of \p{Lower}
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\p")
|
regex = Regex("\\p")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\p;")
|
regex = Regex("\\p;")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\p{")
|
regex = Regex("\\p{")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\p{;")
|
regex = Regex("\\p{;")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\p{Lower")
|
regex = Regex("\\p{Lower")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\p{Lower;")
|
regex = Regex("\\p{Lower;")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test \p{Upper}
|
// Test \p{Upper}
|
||||||
@@ -608,14 +608,14 @@ class PatternTest2 {
|
|||||||
// Invalid uses of \p{Upper}
|
// Invalid uses of \p{Upper}
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\p{Upper")
|
regex = Regex("\\p{Upper")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\p{Upper;")
|
regex = Regex("\\p{Upper;")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test \p{ASCII}
|
// Test \p{ASCII}
|
||||||
@@ -636,14 +636,14 @@ class PatternTest2 {
|
|||||||
// Invalid uses of \p{ASCII}
|
// Invalid uses of \p{ASCII}
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\p{ASCII")
|
regex = Regex("\\p{ASCII")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
regex = Regex("\\p{ASCII;")
|
regex = Regex("\\p{ASCII;")
|
||||||
fail("PatternSyntaxException expected")
|
fail("IllegalArgumentException expected")
|
||||||
} catch (e: PatternSyntaxException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test \p{Alpha}
|
// Test \p{Alpha}
|
||||||
|
|||||||
Reference in New Issue
Block a user