Minor in JS backend: added regression tests.

#{KT-2219, KT-2470, KT-2507, KT-2222, KT-2995, KT-2221} Obsolete
This commit is contained in:
Zalim Bashorov
2014-03-13 21:40:29 +04:00
parent 604e062f91
commit 7b503bbe6f
15 changed files with 182 additions and 36 deletions
@@ -0,0 +1,43 @@
package foo
native
fun String.charCodeAt(i: Int): Int = noImpl
// Because String in JS doesn't have hashCode method
fun String.myHashCode(): Int {
var hash = 0
for (i in 0..size - 1) {
hash = 31 * hash + charCodeAt(i)
}
return hash
}
class Foo(val name: String) {
override fun equals(other: Any?): Boolean {
if (other is Foo) return name == other.name
return this identityEquals other
}
override fun hashCode(): Int = name.myHashCode()
override fun toString(): String = "Foo($name)"
}
fun assertEquals(expected: Any, actual: Any) {
if (expected != actual) throw Exception("expected = $expected, actual = $actual")
}
fun box(): String {
val james = Foo("James")
val anotherJames = Foo("James")
val max = Foo("Max")
assertEquals(true, james == anotherJames)
assertEquals(false, james == max)
assertEquals("James".myHashCode(), james.hashCode())
assertEquals("Max".myHashCode(), max.hashCode())
assertEquals("Foo(James)", james.toString())
assertEquals("Foo(Max)", max.toString())
return "OK"
}
@@ -0,0 +1,8 @@
package foo
class A(val ok: String) {
fun initialize() = ok
}
fun box(): String = A("OK").initialize()