diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/RegressionMergeEcmaTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/RegressionMergeEcmaTest.java new file mode 100644 index 00000000000..1421889755c --- /dev/null +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/RegressionMergeEcmaTest.java @@ -0,0 +1,70 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.k2js.test.semantics; + +import org.jetbrains.k2js.test.SingleFileTranslationTest; + +public class RegressionMergeEcmaTest extends SingleFileTranslationTest { + public RegressionMergeEcmaTest() { + super("mergeEcma/"); + } + + public void testObjectWithMethods() throws Exception { + fooBoxTest(); + } + + public void testEcmaDelegate() throws Exception { + checkFooBoxIsOk(); + } + + public void testEcmaObject() throws Exception { + checkFooBoxIsOk(); + } + + public void testEcmaSimple() throws Exception { + checkFooBoxIsOk(); + } + + public void testMethodOverride() throws Exception { + checkFooBoxIsOk(); + } + + public void testMethodInClass() throws Exception { + checkFooBoxIsOk(); + } + + public void testGetSetProperty() throws Exception { + checkFooBoxIsOk(); + } + + public void testRootValInit() throws Exception { + checkFooBoxIsOk(); + } + + //TODO + public void TestRootPackageValInit() throws Exception { + checkFooBoxIsOk(); + } + + public void testClassInitializer() throws Exception { + checkFooBoxIsOk(); + } + + public void testExtensionClass() throws Exception { + checkFooBoxIsOk(); + } +} diff --git a/js/js.translator/testFiles/mergeEcma/cases/classInitializer.kt b/js/js.translator/testFiles/mergeEcma/cases/classInitializer.kt new file mode 100644 index 00000000000..e1c6b1e02f8 --- /dev/null +++ b/js/js.translator/testFiles/mergeEcma/cases/classInitializer.kt @@ -0,0 +1,19 @@ +package foo + +class B(val name: String) + +class A(val a: Int, var b: B) { + var copyB: B + { + copyB = b + } +} + +fun box(): String { + val a = A(5, B("OK")) + if (a.a != 5) return "a.a != 5, it: ${a.a}" + if (a.b.name != "OK") return "a.b.name != 'OK', it: ${a.b.name}" + if (a.copyB!!.name != "OK") return "a.b.name != 'OK', it: ${a.copyB!!.name}" + + return "OK" +} \ No newline at end of file diff --git a/js/js.translator/testFiles/mergeEcma/cases/ecmaDelegate.kt b/js/js.translator/testFiles/mergeEcma/cases/ecmaDelegate.kt new file mode 100644 index 00000000000..8378be611ee --- /dev/null +++ b/js/js.translator/testFiles/mergeEcma/cases/ecmaDelegate.kt @@ -0,0 +1,21 @@ +package foo + +class Delegate { + var inner = 1 + fun get(t: Any?, p: PropertyMetadata): Int = inner + fun set(t: Any?, p: PropertyMetadata, i: Int) { inner = i } +} + +val p = Delegate() + +class A { + var prop: Int by p +} + +fun box(): String { + val c = A() + if(c.prop != 1) return "fail get" + c.prop = 2 + if (c.prop != 2) return "fail set" + return "OK" +} diff --git a/js/js.translator/testFiles/mergeEcma/cases/ecmaObject.kt b/js/js.translator/testFiles/mergeEcma/cases/ecmaObject.kt new file mode 100644 index 00000000000..22655927dd7 --- /dev/null +++ b/js/js.translator/testFiles/mergeEcma/cases/ecmaObject.kt @@ -0,0 +1,14 @@ +package foo + +open class A(val name: String) { + fun foo(): String { + return name + } +} + +object B : A("OK") + +fun box(): String { + val OK = B.foo() + return OK +} \ No newline at end of file diff --git a/js/js.translator/testFiles/mergeEcma/cases/ecmaSimple.kt b/js/js.translator/testFiles/mergeEcma/cases/ecmaSimple.kt new file mode 100644 index 00000000000..c7a16af175f --- /dev/null +++ b/js/js.translator/testFiles/mergeEcma/cases/ecmaSimple.kt @@ -0,0 +1,12 @@ +package foo + +open class A { + val a = "OK" +} + +class B: A() + +fun box(): String { + + return B().a +} \ No newline at end of file diff --git a/js/js.translator/testFiles/mergeEcma/cases/extensionClass.kt b/js/js.translator/testFiles/mergeEcma/cases/extensionClass.kt new file mode 100644 index 00000000000..e23d550c7e2 --- /dev/null +++ b/js/js.translator/testFiles/mergeEcma/cases/extensionClass.kt @@ -0,0 +1,14 @@ +package foo + +open class A(val name: String) + +class B(val age: Int, name: String) : A(name) + +fun box(): String { + val b = B(12, "Mike") + + if (b.age != 12) return "b.age != 12, it: ${b.age}" + if (b.name != "Mike") return "b.name != 'Mike', it: ${b.name}" + + return "OK" +} \ No newline at end of file diff --git a/js/js.translator/testFiles/mergeEcma/cases/getSetProperty.kt b/js/js.translator/testFiles/mergeEcma/cases/getSetProperty.kt new file mode 100644 index 00000000000..fdf5784051a --- /dev/null +++ b/js/js.translator/testFiles/mergeEcma/cases/getSetProperty.kt @@ -0,0 +1,27 @@ +package foo + +class A { + val a: Int + get() { + return 2 + } + + var b: Int = 1 + get() { + return $b + 1; + } + set(value: Int) { + $b = value; + } +} + +fun box(): String { + val a = A() + if (a.a != 2) return "a.a != 2, it: ${a.a}" + + if (a.b != 2) return "a.b != 2, it: ${a.b}" + a.b = 3 + + if (a.b != 4) return "a.b != 4, it: ${a.b}" + return "OK" +} \ No newline at end of file diff --git a/js/js.translator/testFiles/mergeEcma/cases/methodInClass.kt b/js/js.translator/testFiles/mergeEcma/cases/methodInClass.kt new file mode 100644 index 00000000000..ab5bfaadc46 --- /dev/null +++ b/js/js.translator/testFiles/mergeEcma/cases/methodInClass.kt @@ -0,0 +1,14 @@ +package foo + +class A { + fun foo(): Int { + return 1 + } + +} + +fun box(): String { + val a = A() + if (a.foo() != 1) return "a.foo() != 1, it: ${a.foo()}" + return "OK" +} \ No newline at end of file diff --git a/js/js.translator/testFiles/mergeEcma/cases/methodOverride.kt b/js/js.translator/testFiles/mergeEcma/cases/methodOverride.kt new file mode 100644 index 00000000000..e25befd297f --- /dev/null +++ b/js/js.translator/testFiles/mergeEcma/cases/methodOverride.kt @@ -0,0 +1,27 @@ +package foo + +open class A { + fun f1(): Int { + return 1 + } + open fun f2(): Int { + return 3 + } +} + +class B: A() { + override fun f2(): Int { + return 2 + } +} + +fun box(): String { + val a = A() + if (a.f1() != 1) return "a.f1() != 1, it: ${a.f1()}" + if (a.f2() != 3) return "a.f2() != 3, it: ${a.f2()}" + + val b = B(); + if (b.f1() != 1) return "b.f1() != 1, it: ${b.f1()}" + if (b.f2() != 2) return "b.f2() != 2, it: ${b.f2()}" + return "OK" +} \ No newline at end of file diff --git a/js/js.translator/testFiles/mergeEcma/cases/objectWithMethods.kt b/js/js.translator/testFiles/mergeEcma/cases/objectWithMethods.kt new file mode 100644 index 00000000000..a05fd859306 --- /dev/null +++ b/js/js.translator/testFiles/mergeEcma/cases/objectWithMethods.kt @@ -0,0 +1,22 @@ +package foo + +class Test { + private val a = object { + fun c() = 3 + fun b() = 2 + } + + fun doTest(): Boolean { + if (a.c() != 3) { + return false; + } + if (a.b() != 2) { + return false; + } + return true; + } +} + +fun box(): Boolean { + return Test().doTest(); +} diff --git a/js/js.translator/testFiles/mergeEcma/cases/rootPackageValInit.kt b/js/js.translator/testFiles/mergeEcma/cases/rootPackageValInit.kt new file mode 100644 index 00000000000..104c8765e2e --- /dev/null +++ b/js/js.translator/testFiles/mergeEcma/cases/rootPackageValInit.kt @@ -0,0 +1,11 @@ +class A(val a: Int) + +val x = 1 +val a = A(2) + +fun box(): String { + if (x != 1) return "x != 1, it: $x" + if (a.a != 2) return "a.a != 2, it: ${a.a}" + + return "OK" +} \ No newline at end of file diff --git a/js/js.translator/testFiles/mergeEcma/cases/rootValInit.kt b/js/js.translator/testFiles/mergeEcma/cases/rootValInit.kt new file mode 100644 index 00000000000..a454c906c4d --- /dev/null +++ b/js/js.translator/testFiles/mergeEcma/cases/rootValInit.kt @@ -0,0 +1,16 @@ +package foo + +class A(val a: Int) + +class Empty + +val x = 1 +val a = A(2) +val e = Empty() + +fun box(): String { + if (x != 1) return "x != 1, it: $x" + if (a.a != 2) return "a.a != 2, it: ${a.a}" + + return "OK" +} \ No newline at end of file