KT-2752: fix some tests and make them slightly less fragile

This commit is contained in:
Alexey Andreev
2016-09-23 15:20:36 +03:00
parent 9c7c82b151
commit 831ac97ecd
8 changed files with 96 additions and 80 deletions
+19
View File
@@ -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;
""")