Add pattern and options properties to common Regex
And add a test that accesses them and checks they work as expected.
This commit is contained in:
@@ -43,6 +43,9 @@ expect class Regex {
|
|||||||
constructor(pattern: String, option: RegexOption)
|
constructor(pattern: String, option: RegexOption)
|
||||||
constructor(pattern: String, options: Set<RegexOption>)
|
constructor(pattern: String, options: Set<RegexOption>)
|
||||||
|
|
||||||
|
val pattern: String
|
||||||
|
val options: Set<RegexOption>
|
||||||
|
|
||||||
fun matchEntire(input: CharSequence): MatchResult?
|
fun matchEntire(input: CharSequence): MatchResult?
|
||||||
infix fun matches(input: CharSequence): Boolean
|
infix fun matches(input: CharSequence): Boolean
|
||||||
fun containsMatchIn(input: CharSequence): Boolean
|
fun containsMatchIn(input: CharSequence): Boolean
|
||||||
|
|||||||
@@ -7,6 +7,17 @@ import kotlin.test.*
|
|||||||
|
|
||||||
class RegexTest {
|
class RegexTest {
|
||||||
|
|
||||||
|
@Test fun properties() {
|
||||||
|
val pattern = "\\s+$"
|
||||||
|
val regex1 = Regex(pattern, RegexOption.IGNORE_CASE)
|
||||||
|
assertEquals(pattern, regex1.pattern)
|
||||||
|
assertEquals(setOf(RegexOption.IGNORE_CASE), regex1.options)
|
||||||
|
|
||||||
|
val options2 = setOf(RegexOption.MULTILINE, RegexOption.IGNORE_CASE)
|
||||||
|
val regex2 = Regex(pattern, options2)
|
||||||
|
assertEquals(options2, regex2.options)
|
||||||
|
}
|
||||||
|
|
||||||
@Test fun matchResult() {
|
@Test fun matchResult() {
|
||||||
val p = "\\d+".toRegex()
|
val p = "\\d+".toRegex()
|
||||||
val input = "123 456 789"
|
val input = "123 456 789"
|
||||||
|
|||||||
Reference in New Issue
Block a user