JS: create new common directory for all generated tests, migrate several tests there
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package foo
|
||||
|
||||
open abstract class A() {
|
||||
abstract var pos: Int
|
||||
}
|
||||
|
||||
class B() : A() {
|
||||
override var pos: Int = 2
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
val a: A = B()
|
||||
if (a.pos != 2) {
|
||||
return "fail1: ${a.pos}"
|
||||
}
|
||||
if (B().pos != 2) {
|
||||
return "fail2"
|
||||
}
|
||||
a.pos = 3;
|
||||
if (a.pos != 3) {
|
||||
return "fail3: ${a.pos}"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -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,19 @@
|
||||
package foo
|
||||
|
||||
var x = false
|
||||
|
||||
open class A {
|
||||
init {
|
||||
x = (this as B).a != 3
|
||||
}
|
||||
}
|
||||
|
||||
class B(val a: Int = 3) : A() {
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
B()
|
||||
if (!x) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package foo
|
||||
|
||||
|
||||
class A() : B() {
|
||||
|
||||
}
|
||||
|
||||
open class B() {
|
||||
|
||||
val a = 3
|
||||
}
|
||||
|
||||
fun box() = if (A().a == 3) "OK" else "fail"
|
||||
@@ -0,0 +1,37 @@
|
||||
package foo
|
||||
|
||||
open class A() {
|
||||
|
||||
var order = ""
|
||||
init {
|
||||
order = order + "A"
|
||||
}
|
||||
}
|
||||
|
||||
open class B() : A() {
|
||||
init {
|
||||
order = order + "B"
|
||||
}
|
||||
}
|
||||
|
||||
class C() : B() {
|
||||
init {
|
||||
order = order + "C"
|
||||
}
|
||||
}
|
||||
|
||||
class D() : B() {
|
||||
init {
|
||||
order = order + "D"
|
||||
}
|
||||
}
|
||||
|
||||
class E() : A() {
|
||||
init {
|
||||
order = order + "E"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if ((C().order == "ABC") && (D().order == "ABD") && (E().order == "AE")) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package foo
|
||||
|
||||
class C() : B() {
|
||||
init {
|
||||
order = order + "C"
|
||||
}
|
||||
}
|
||||
|
||||
class D() : B() {
|
||||
init {
|
||||
order = order + "D"
|
||||
}
|
||||
}
|
||||
|
||||
class E() : A() {
|
||||
init {
|
||||
order = order + "E"
|
||||
}
|
||||
}
|
||||
|
||||
open class B() : A() {
|
||||
init {
|
||||
order = order + "B"
|
||||
}
|
||||
}
|
||||
|
||||
open class A() : G() {
|
||||
|
||||
var order = ""
|
||||
init {
|
||||
order = order + "A"
|
||||
}
|
||||
}
|
||||
|
||||
// KT-3437
|
||||
abstract class G : H()
|
||||
abstract class K : H()
|
||||
abstract class L
|
||||
abstract class H : L()
|
||||
abstract class Dummy
|
||||
|
||||
fun box(): String {
|
||||
return if ((C().order == "ABC") && (D().order == "ABD") && (E().order == "AE")) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package foo
|
||||
|
||||
class FromAny : Any()
|
||||
|
||||
class FromIterable(val n: Int) : Iterable<Int> {
|
||||
override fun iterator() = object: Iterator<Int> {
|
||||
var i = 0
|
||||
override fun next() = i++
|
||||
override fun hasNext() = i < n
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> Iterable<T>.stringify(): String {
|
||||
var s = ""
|
||||
for (i in this) s += i
|
||||
return s
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = FromAny()
|
||||
val it = FromIterable(3)
|
||||
|
||||
val s = it.stringify()
|
||||
if (s != "012") return "s /*$s*/ != 012"
|
||||
|
||||
var ao = object : Any() {
|
||||
}
|
||||
var ito = object : Iterable<Int> {
|
||||
override public fun iterator() = object: Iterator<Int> {
|
||||
var i = 0
|
||||
override fun next(): Int {
|
||||
var r = i
|
||||
i += 2
|
||||
return r
|
||||
}
|
||||
override fun hasNext() = i < 9
|
||||
}
|
||||
}
|
||||
|
||||
val so = ito.stringify()
|
||||
if (so != "02468") return "so /*$so*/ != 02468"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package foo
|
||||
|
||||
class MyCharIterator : CharIterator() {
|
||||
val data = arrayOf('O', 'K')
|
||||
var i = 0
|
||||
|
||||
override fun hasNext(): Boolean = i < data.size
|
||||
override fun nextChar(): Char = data[i++]
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var r = ""
|
||||
|
||||
for (v in MyCharIterator()) {
|
||||
r += v
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package foo
|
||||
|
||||
open class A() {
|
||||
|
||||
var order = ""
|
||||
init {
|
||||
order = order + "A"
|
||||
}
|
||||
}
|
||||
|
||||
open class B() : A() {
|
||||
init {
|
||||
order = order + "B"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class C() : B() {
|
||||
init {
|
||||
order = order + "C"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if ((C().order == "ABC") && (B().order == "AB") && (A().order == "A")) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
open class A() {
|
||||
var a = 3;
|
||||
}
|
||||
|
||||
class B() : A() {
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = B().a
|
||||
return if (a == 3) "OK" else "Fail, a = $a"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package foo
|
||||
|
||||
interface A : B, E
|
||||
interface B
|
||||
open class C {
|
||||
fun foo() = true
|
||||
}
|
||||
interface D
|
||||
interface E
|
||||
interface F : G, D
|
||||
interface G
|
||||
|
||||
fun box() = if (C().foo()) "OK" else "fail"
|
||||
@@ -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,39 @@
|
||||
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 === other
|
||||
}
|
||||
override fun hashCode(): Int = name.myHashCode()
|
||||
override fun toString(): String = "Foo($name)"
|
||||
}
|
||||
|
||||
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,15 @@
|
||||
package foo
|
||||
|
||||
open class C() {
|
||||
open val a = 1
|
||||
}
|
||||
|
||||
class D() : C() {
|
||||
override val a = 2
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val d: C = D()
|
||||
if (d.a != 2) return "fail: ${d.a}"
|
||||
return "OK"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package foo
|
||||
|
||||
open class C(a: Int) {
|
||||
val b = a
|
||||
}
|
||||
|
||||
class D(c: Int) : C(c + 2) {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (D(0).b == 2) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package foo
|
||||
|
||||
class A(val ok: String) {
|
||||
fun initialize() = ok
|
||||
}
|
||||
|
||||
fun box(): String = A("OK").initialize()
|
||||
|
||||
Reference in New Issue
Block a user