Fix js RegExp test not to rely on array equality. #KT-8283

This commit is contained in:
Ilya Gorbunov
2016-09-14 19:11:07 +03:00
parent 7b99730e39
commit 3471b3311f
2 changed files with 6 additions and 9 deletions
+4 -1
View File
@@ -39,7 +39,7 @@ public fun RegExp.reset() {
lastIndex = 0
}
// TODO: Inherit from array or introduce asArray() extension
@native public interface RegExpMatch {
public val index: Int
public val input: String
@@ -48,3 +48,6 @@ public fun RegExp.reset() {
@nativeGetter
public operator fun get(index: Int): String?
}
public inline fun RegExpMatch.asArray(): Array<out String?> = this.asDynamic()
+2 -8
View File
@@ -55,22 +55,16 @@ class RegExpTest {
val string = "R2D2 beats A5D5 "
var re = RegExp("""(\w\d)(\w\d)""", "g")
val m1 = re.exec(string)!!
assertEquals(arrayOf("R2D2", "R2", "D2"), m1.toArray())
assertEquals(listOf("R2D2", "R2", "D2"), m1.asArray().asList())
assertEquals(0, m1.index)
assertEquals(4, re.lastIndex)
val m2 = re.exec(string)!!
assertEquals(arrayOf("A5D5", "A5", "D5"), m2.toArray())
assertEquals(listOf("A5D5", "A5", "D5"), m2.asArray().asList())
assertEquals(string.indexOf(m2[0]!!), m2.index)
val noMatch = re.exec(string)
assertEquals(null, noMatch)
assertEquals(0, re.lastIndex)
}
fun RegExpMatch.toArray(): Array<out String?> {
val array = arrayOfNulls<String>(length)
array.indices.forEach { array[it] = this[it] }
return array
}
}