[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))
|
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
|
* Regression test for https://github.com/JetBrains/kotlin-native/issues/2297
|
||||||
*/
|
*/
|
||||||
@@ -458,16 +471,9 @@ class MatchResultTest {
|
|||||||
assertTrue(Regex("[^a]").matches("b"))
|
assertTrue(Regex("[^a]").matches("b"))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Test fun kt28158() {
|
||||||
* Regression test for HARMONY-3360
|
val comment = "😃😃😃😃😃😃"
|
||||||
*/
|
val regex = Regex("(.{3,})\\1+", RegexOption.IGNORE_CASE)
|
||||||
@Test fun testGeneralPunctuationCategory() {
|
assertTrue(comment.contains(regex))
|
||||||
val s = arrayOf(",", "!", "\"", "#", "%", "&", "'", "(", ")", "-", ".", "/")
|
|
||||||
val regexp = "\\p{P}"
|
|
||||||
|
|
||||||
for (i in s.indices) {
|
|
||||||
val regex = Regex(regexp)
|
|
||||||
assertTrue(regex.containsMatchIn(s[i]))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -157,7 +157,7 @@ public actual class Regex internal constructor(internal val nativePattern: Patte
|
|||||||
*/
|
*/
|
||||||
actual fun find(input: CharSequence, startIndex: Int): MatchResult? {
|
actual fun find(input: CharSequence, startIndex: Int): MatchResult? {
|
||||||
if (startIndex < 0 || startIndex > input.length) {
|
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)
|
val matchResult = MatchResultImpl(input, this)
|
||||||
matchResult.mode = Mode.FIND
|
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 {
|
fun add(start: Int, end: Int): CharClass {
|
||||||
if (start > end)
|
if (start > end)
|
||||||
throw IllegalArgumentException()
|
throw IllegalArgumentException("Incorrect range of symbols (start > end)")
|
||||||
val minSurrogate = Char.MIN_SURROGATE.toInt()
|
val minSurrogate = Char.MIN_SURROGATE.toInt()
|
||||||
val maxSurrogate = Char.MAX_SURROGATE.toInt()
|
val maxSurrogate = Char.MAX_SURROGATE.toInt()
|
||||||
if (ignoreCase) {
|
if (ignoreCase) {
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ constructor (internal val input: CharSequence,
|
|||||||
|
|
||||||
private fun checkGroup(group: Int) {
|
private fun checkGroup(group: Int) {
|
||||||
if (group < 0 || group > groupCount) {
|
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 */
|
/** Compiles the given pattern */
|
||||||
init {
|
init {
|
||||||
if (flags != 0 && flags or flagsBitMask != flagsBitMask) {
|
if (flags != 0 && flags or flagsBitMask != flagsBitMask) {
|
||||||
throw IllegalArgumentException()
|
throw IllegalArgumentException("Invalid match flags value")
|
||||||
}
|
}
|
||||||
startNode = processExpression(-1, this.flags, null)
|
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.
|
* 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() {
|
internal class Quantifier(val min: Int, val max: Int = min) : SpecialToken() {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (min < 0 || max < -1) {
|
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
|
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_STAR, Lexer.QUANT_STAR_P, Lexer.QUANT_STAR_R -> starQuantifier
|
||||||
Lexer.QUANT_ALT, Lexer.QUANT_ALT_P, Lexer.QUANT_ALT_R -> altQuantifier
|
Lexer.QUANT_ALT, Lexer.QUANT_ALT_P, Lexer.QUANT_ALT_R -> altQuantifier
|
||||||
Lexer.QUANT_PLUS, Lexer.QUANT_PLUS_P, Lexer.QUANT_PLUS_R -> plusQuantifier
|
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
|
get() = super.innerSet
|
||||||
set(innerSet) {
|
set(innerSet) {
|
||||||
if (innerSet !is LeafSet)
|
if (innerSet !is LeafSet)
|
||||||
throw RuntimeException()
|
throw RuntimeException("Internal Error")
|
||||||
super.innerSet = innerSet
|
super.innerSet = innerSet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user