KT-2752: fix some tests and make them slightly less fragile
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package helpers
|
||||
|
||||
fun checkJsNames(base: String, o: Any) {
|
||||
val regex = Regex("^$base(_[0-9a-zA-Z]+\\\$)?(_[0-9])?$")
|
||||
|
||||
val properties = getAllProperties(o).filter { it.startsWith("$base") }
|
||||
val distinctProperties = properties.mapNotNull { regex.match(it)?.groupValues?.get(1) }.distinct()
|
||||
if (distinctProperties.size != 2) {
|
||||
fail("Two distinct properties expected, ${properties.size} occurred: " + properties)
|
||||
}
|
||||
}
|
||||
|
||||
fun getAllProperties(o: dynamic): Array<String> = js("""
|
||||
var properties = [];
|
||||
for (property in o) {
|
||||
properties.push(property);
|
||||
}
|
||||
return properties;
|
||||
""")
|
||||
@@ -24,6 +24,7 @@ package main
|
||||
|
||||
import lib1.A
|
||||
import lib2.B
|
||||
import helpers.checkJsNames
|
||||
|
||||
class Derived1 : A, B {
|
||||
override fun bar() = super<A>.bar()
|
||||
@@ -33,13 +34,6 @@ class Derived2 : A, B {
|
||||
override fun bar() = super<B>.bar()
|
||||
}
|
||||
|
||||
// NOTE. This test is fragile, it may fail due to unexpected (and correct) changes in algorithm that assigns
|
||||
// unique identifiers to non-public declarations. However, we don't see any way of doing such test so that
|
||||
// it won't report false positives eventually. So be patient and just update this test whenever you changed
|
||||
// algorithm of assigning unique identifiers.
|
||||
// Please, check that A.foo and B.foo have different JS names.
|
||||
private fun checkJsNames(o: dynamic): Boolean = "foo_2pru9n\$_0" in o && "foo_2psha1\$_0" in o
|
||||
|
||||
fun box(): String {
|
||||
val a = Derived1()
|
||||
if (a.bar() != "A.foo") return "fail1: ${a.bar()}"
|
||||
@@ -47,8 +41,8 @@ fun box(): String {
|
||||
val b = Derived2()
|
||||
if (b.bar() != "B.foo") return "fail2: ${b.bar()}"
|
||||
|
||||
if (!checkJsNames(a)) return "fail3"
|
||||
if (!checkJsNames(b)) return "fail4"
|
||||
checkJsNames("foo", a)
|
||||
checkJsNames("foo", b)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -24,6 +24,7 @@ package main
|
||||
|
||||
import lib.A
|
||||
import lib.check
|
||||
import helpers.checkJsNames
|
||||
|
||||
class B : A() {
|
||||
private var x = 42
|
||||
@@ -31,13 +32,6 @@ class B : A() {
|
||||
fun bar() = x
|
||||
}
|
||||
|
||||
// NOTE. This test is fragile, it may fail due to unexpected (and correct) changes in algorithm that assigns
|
||||
// unique identifiers to non-public declarations. However, we don't see any way of doing such test so that
|
||||
// it won't report false positives eventually. So be patient and just update this test whenever you changed
|
||||
// algorithm of assigning unique identifiers.
|
||||
// Please, check that A.x and B.x have different JS names.
|
||||
private fun checkJsNames(o: dynamic): Boolean = "x_i8qwny\$_0" in o && "x_0" in o
|
||||
|
||||
fun box(): String {
|
||||
if (!check()) return "check failed: did not compile against old library"
|
||||
|
||||
@@ -47,7 +41,7 @@ fun box(): String {
|
||||
val b = B()
|
||||
if (b.foo() != 23) return "fail2: ${b.foo()}"
|
||||
if (b.bar() != 42) return "fail3: ${b.bar()}"
|
||||
if (!checkJsNames(b)) return "fail4"
|
||||
checkJsNames("x", b)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user