From 10639eaf6ae2a4a22c688b365f66973ccfb9a9d7 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Fri, 22 Dec 2017 21:19:51 +0300 Subject: [PATCH] Add pattern and options properties to common Regex And add a test that accesses them and checks they work as expected. --- libraries/stdlib/common/src/kotlin/TextH.kt | 3 +++ libraries/stdlib/test/text/RegexTest.kt | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/libraries/stdlib/common/src/kotlin/TextH.kt b/libraries/stdlib/common/src/kotlin/TextH.kt index 928dad577f9..2819cf3afd2 100644 --- a/libraries/stdlib/common/src/kotlin/TextH.kt +++ b/libraries/stdlib/common/src/kotlin/TextH.kt @@ -43,6 +43,9 @@ expect class Regex { constructor(pattern: String, option: RegexOption) constructor(pattern: String, options: Set) + val pattern: String + val options: Set + fun matchEntire(input: CharSequence): MatchResult? infix fun matches(input: CharSequence): Boolean fun containsMatchIn(input: CharSequence): Boolean diff --git a/libraries/stdlib/test/text/RegexTest.kt b/libraries/stdlib/test/text/RegexTest.kt index 449f0d46394..522dcdd1433 100644 --- a/libraries/stdlib/test/text/RegexTest.kt +++ b/libraries/stdlib/test/text/RegexTest.kt @@ -7,6 +7,17 @@ import kotlin.test.* 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() { val p = "\\d+".toRegex() val input = "123 456 789"