JS backend: add RegressionMergeEcmaTest
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package foo
|
||||
|
||||
open class A {
|
||||
val a = "OK"
|
||||
}
|
||||
|
||||
class B: A()
|
||||
|
||||
fun box(): String {
|
||||
|
||||
return B().a
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
Reference in New Issue
Block a user