Rename Pattern to Regex.
toRegex now converts string to our regex, and toPattern converts to JVM Pattern.
This commit is contained in:
+3
-3
@@ -5,13 +5,13 @@ import kotlin.text.*
|
||||
import org.junit.Test as test
|
||||
|
||||
|
||||
class PatternJVMTest {
|
||||
class RegexJVMTest {
|
||||
|
||||
test fun matchGroups() {
|
||||
val input = "1a 2b 3c"
|
||||
val pattern = "(\\d)(\\w)".toPattern()
|
||||
val regex = "(\\d)(\\w)".toRegex()
|
||||
|
||||
val matches = pattern.matchAll(input).toList()
|
||||
val matches = regex.matchAll(input).toList()
|
||||
assertTrue(matches.all { it.groups.size() == 3 })
|
||||
val m1 = matches[0]
|
||||
assertEquals("1a", m1.groups[0]?.value)
|
||||
@@ -5,10 +5,10 @@ import kotlin.text.*
|
||||
import kotlin.test.*
|
||||
import org.junit.Test as test
|
||||
|
||||
class PatternTest {
|
||||
class RegexTest {
|
||||
|
||||
test fun matchResult() {
|
||||
val p = "\\d+".toPattern()
|
||||
val p = "\\d+".toRegex()
|
||||
val input = "123 456 789"
|
||||
|
||||
val first = p.match(input)
|
||||
@@ -30,7 +30,7 @@ class PatternTest {
|
||||
|
||||
test fun matchSequence() {
|
||||
val input = "123 456 789"
|
||||
val pattern = "\\d+".toPattern()
|
||||
val pattern = "\\d+".toRegex()
|
||||
|
||||
val matches = pattern.matchAll(input)
|
||||
val values = matches.map { it.value }
|
||||
@@ -43,7 +43,7 @@ class PatternTest {
|
||||
|
||||
test fun matchGroups() {
|
||||
val input = "1a 2b 3c"
|
||||
val pattern = "(\\d)(\\w)".toPattern()
|
||||
val pattern = "(\\d)(\\w)".toRegex()
|
||||
|
||||
val matches = pattern.matchAll(input).toList()
|
||||
assertTrue(matches.all { it.groups.size() == 3 })
|
||||
@@ -58,7 +58,7 @@ class PatternTest {
|
||||
}
|
||||
|
||||
test fun matchOptionalGroup() {
|
||||
val pattern = "(hi)|(bye)".toPattern(PatternOption.IGNORE_CASE)
|
||||
val pattern = "(hi)|(bye)".toRegex(RegexOption.IGNORE_CASE)
|
||||
|
||||
val m1 = pattern.match("Hi!")!!
|
||||
assertEquals(3, m1.groups.size())
|
||||
@@ -5,8 +5,8 @@ import kotlin.test.*
|
||||
import org.junit.Test as test
|
||||
|
||||
class StringUtilTest() {
|
||||
test fun toRegex() {
|
||||
val re = """foo""".toRegex()
|
||||
test fun toPattern() {
|
||||
val re = """foo""".toPattern()
|
||||
val list = re.split("hellofoobar").toList()
|
||||
assertEquals(listOf("hello", "bar"), list)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user