[regex] Add missing exception messages
This commit is contained in:
committed by
Ilya Matveev
parent
f8bbd5eff0
commit
aa0f0f169d
@@ -435,6 +435,19 @@ class MatchResultTest {
|
||||
assertFalse(regex.containsMatchIn(str))
|
||||
}
|
||||
|
||||
/**
|
||||
* Regression test for HARMONY-3360
|
||||
*/
|
||||
@Test fun testGeneralPunctuationCategory() {
|
||||
val s = arrayOf(",", "!", "\"", "#", "%", "&", "'", "(", ")", "-", ".", "/")
|
||||
val regexp = "\\p{P}"
|
||||
|
||||
for (i in s.indices) {
|
||||
val regex = Regex(regexp)
|
||||
assertTrue(regex.containsMatchIn(s[i]))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Regression test for https://github.com/JetBrains/kotlin-native/issues/2297
|
||||
*/
|
||||
@@ -458,16 +471,9 @@ class MatchResultTest {
|
||||
assertTrue(Regex("[^a]").matches("b"))
|
||||
}
|
||||
|
||||
/**
|
||||
* Regression test for HARMONY-3360
|
||||
*/
|
||||
@Test fun testGeneralPunctuationCategory() {
|
||||
val s = arrayOf(",", "!", "\"", "#", "%", "&", "'", "(", ")", "-", ".", "/")
|
||||
val regexp = "\\p{P}"
|
||||
|
||||
for (i in s.indices) {
|
||||
val regex = Regex(regexp)
|
||||
assertTrue(regex.containsMatchIn(s[i]))
|
||||
}
|
||||
@Test fun kt28158() {
|
||||
val comment = "😃😃😃😃😃😃"
|
||||
val regex = Regex("(.{3,})\\1+", RegexOption.IGNORE_CASE)
|
||||
assertTrue(comment.contains(regex))
|
||||
}
|
||||
}
|
||||
@@ -157,7 +157,7 @@ public actual class Regex internal constructor(internal val nativePattern: Patte
|
||||
*/
|
||||
actual fun find(input: CharSequence, startIndex: Int): MatchResult? {
|
||||
if (startIndex < 0 || startIndex > input.length) {
|
||||
throw IndexOutOfBoundsException() // TODO: Add a message.
|
||||
throw IndexOutOfBoundsException("Start index out of bounds: $startIndex")
|
||||
}
|
||||
val matchResult = MatchResultImpl(input, this)
|
||||
matchResult.mode = Mode.FIND
|
||||
|
||||
@@ -213,7 +213,7 @@ internal class CharClass(val ignoreCase: Boolean = false, negative: Boolean = fa
|
||||
|
||||
fun add(start: Int, end: Int): CharClass {
|
||||
if (start > end)
|
||||
throw IllegalArgumentException()
|
||||
throw IllegalArgumentException("Incorrect range of symbols (start > end)")
|
||||
val minSurrogate = Char.MIN_SURROGATE.toInt()
|
||||
val maxSurrogate = Char.MAX_SURROGATE.toInt()
|
||||
if (ignoreCase) {
|
||||
|
||||
@@ -218,7 +218,7 @@ constructor (internal val input: CharSequence,
|
||||
|
||||
private fun checkGroup(group: Int) {
|
||||
if (group < 0 || group > groupCount) {
|
||||
throw IndexOutOfBoundsException()
|
||||
throw IndexOutOfBoundsException("Group index out of bounds: $group")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ internal class Pattern(val pattern: String, flags: Int = 0) {
|
||||
/** Compiles the given pattern */
|
||||
init {
|
||||
if (flags != 0 && flags or flagsBitMask != flagsBitMask) {
|
||||
throw IllegalArgumentException()
|
||||
throw IllegalArgumentException("Invalid match flags value")
|
||||
}
|
||||
startNode = processExpression(-1, this.flags, null)
|
||||
|
||||
|
||||
@@ -26,17 +26,17 @@ import kotlin.IllegalArgumentException
|
||||
|
||||
/**
|
||||
* Represents RE quantifier; contains two fields responsible for min and max number of repetitions.
|
||||
* Negative value for maximum number of repetition represents infinity(i.e. +,*)
|
||||
* -1 as a maximum number of repetition represents infinity(i.e. +,*).
|
||||
*/
|
||||
internal class Quantifier(val min: Int, val max: Int = min) : SpecialToken() {
|
||||
|
||||
init {
|
||||
if (min < 0 || max < -1) {
|
||||
throw IllegalArgumentException()
|
||||
throw IllegalArgumentException("Incorrect quantifier value: $this")
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString() = "{$min, ${if (max == -1) "" else max}}"
|
||||
override fun toString() = "{$min, ${if (max == INF) "" else max}}"
|
||||
|
||||
override val type: Type = SpecialToken.Type.QUANTIFIER
|
||||
|
||||
@@ -51,7 +51,7 @@ internal class Quantifier(val min: Int, val max: Int = min) : SpecialToken() {
|
||||
Lexer.QUANT_STAR, Lexer.QUANT_STAR_P, Lexer.QUANT_STAR_R -> starQuantifier
|
||||
Lexer.QUANT_ALT, Lexer.QUANT_ALT_P, Lexer.QUANT_ALT_R -> altQuantifier
|
||||
Lexer.QUANT_PLUS, Lexer.QUANT_PLUS_P, Lexer.QUANT_PLUS_R -> plusQuantifier
|
||||
else -> throw IllegalArgumentException()
|
||||
else -> throw IllegalArgumentException("Unknown quantifier token: $token")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ open internal class LeafQuantifierSet(var quantifier: Quantifier,
|
||||
get() = super.innerSet
|
||||
set(innerSet) {
|
||||
if (innerSet !is LeafSet)
|
||||
throw RuntimeException()
|
||||
throw RuntimeException("Internal Error")
|
||||
super.innerSet = innerSet
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user