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,28 @@
package foo
fun Any.foo1(): () -> String {
return { "239" + this }
}
fun Int.foo2(): (i: Int) -> Int {
return { x -> x + this }
}
fun fooT1<T>(t: T) = { t.toString() }
fun fooT2<T>(t: T) = {(x: T) -> t.toString() + x.toString() }
fun box(): Any? {
if ( (10.foo1())() != "23910") return "foo1 fail"
if ( (10.foo2())(1) != 11 ) return "foo2 fail"
if (1.{ Int.() -> this + 1 }() != 2) return "test 3 failed";
if ( { 1 }() != 1) return "test 4 failed";
if ( {(x: Int) -> x }(1) != 1) return "test 5 failed";
if ( 1.{ Int.(x: Int) -> x + this }(1) != 2) return "test 6 failed";
val tmp = 1.({ Int.() -> this })()
if (+tmp != 1) return "test 7 failed, res: $tmp ${tmp is Int}";
if ( (fooT1<String>("mama"))() != "mama") return "test 8 failed";
if ( (fooT2<String>("mama"))("papa") != "mamapapa") return "test 9 failed";
return "OK"
}
@@ -0,0 +1,18 @@
// KT-2995 creating factory methods to simulate overloaded constructors don't work in JavaScript
package foo
class Foo(val name: String)
fun Foo() = Foo("<default-name>")
fun assertEquals(expected: Any, actual: Any) {
if (expected != actual) throw Exception("expected = $expected, actual = $actual")
}
fun box(): String {
assertEquals("<default-name>", Foo().name)
assertEquals("BarBaz", Foo("BarBaz").name)
return "OK"
}
@@ -0,0 +1,26 @@
// KT-2219 if function overload overridden function its name doesn't translated correctly
package foo
fun assertEquals(expected: Any, actual: Any) {
if (expected != actual) throw Exception("expected = $expected, actual = $actual")
}
trait I {
fun test(): String
}
class P : I {
override fun test(): String = "foo" + test("bar")
private fun test(p: String) = p
fun test(s: String, i: Int) = "$i $s"
}
fun box(): String {
assertEquals("foobar", P().test())
assertEquals("35 baz", P().test("baz", 35))
return "OK"
}
@@ -13,12 +13,12 @@ class C : A, B {
}
fun assertEquals(expected: Any, actual: Any) {
if (expected != actual) throw Exception("expected = $expected\nactual = $actual")
if (expected != actual) throw Exception("expected = $expected, actual = $actual")
}
fun box(): String {
assertEquals(C().foo(1), "A")
assertEquals(C().foo(""), "B")
assertEquals(C().foo(), "C")
assertEquals("A", C().foo(1))
assertEquals("B", C().foo(""))
assertEquals("C", C().foo())
return "OK"
}