Find correct next match after matchAt and matchEntire KT-47676
This commit is contained in:
committed by
teamcityserver
parent
28a0698463
commit
455fee29e4
@@ -168,6 +168,7 @@ class RegexTest {
|
||||
assertEquals("3c", m.value)
|
||||
assertEquals(3, m.groups.size)
|
||||
assertEquals(listOf("3c", "3", "c"), m.groups.map { it!!.value })
|
||||
assertNull(m.next())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,6 +180,17 @@ class RegexTest {
|
||||
assertEquals("aaaabbbb", regex.matchEntire(input)!!.value)
|
||||
}
|
||||
|
||||
@Test fun matchEntireNext() {
|
||||
val regex = ".*".toRegex()
|
||||
val input = "abc"
|
||||
val match = regex.matchEntire(input)!!
|
||||
assertEquals(input, match.value)
|
||||
val next = assertNotNull(match.next())
|
||||
assertEquals("", next.value)
|
||||
assertEquals(input.length until input.length, next.range)
|
||||
assertNull(next.next())
|
||||
}
|
||||
|
||||
@Test fun matchAt() {
|
||||
val regex = Regex("[a-z][1-5]", RegexOption.IGNORE_CASE)
|
||||
val input = "...a4...B1"
|
||||
@@ -196,6 +208,11 @@ class RegexTest {
|
||||
assertEquals(input.substring(match.range), match.value)
|
||||
}
|
||||
|
||||
matches.zipWithNext { (_, m1), (_, m2) ->
|
||||
assertEquals(m2.range, assertNotNull(m1.next()).range)
|
||||
}
|
||||
assertNull(matches.last().second.next())
|
||||
|
||||
for (index in listOf(-1, input.length + 1)) {
|
||||
assertFailsWith<IndexOutOfBoundsException> { regex.matchAt(input, index) }
|
||||
assertFailsWith<IndexOutOfBoundsException> { regex.matchesAt(input, index) }
|
||||
|
||||
Reference in New Issue
Block a user