JS: move more test to box tests

This commit is contained in:
Alexey Andreev
2016-08-30 13:59:50 +03:00
parent 9bf124af3f
commit 7e2d5b04de
68 changed files with 607 additions and 578 deletions
@@ -0,0 +1,50 @@
package foo
interface A {
val bal: Int
get() {
return 42
}
}
open class B {
open val bal = 239
}
class C1 : B(), A {
override val bal: Int = 14
fun getBalA(): Int {
return super<A>.bal
}
fun getBalB(): Int {
return super<B>.bal
}
}
class C2 : A, B() {
override val bal: Int = 14
fun getBalA(): Int {
return super<A>.bal
}
fun getBalB(): Int {
return super<B>.bal
}
}
fun box(): String {
val c1 = C1();
if (c1.bal != 14) return "c1.bal != 14, it: ${c1.bal}"
if (c1.getBalA() != 42) return "c1.getBalA() != 42, it: ${c1.getBalA()}"
if (c1.getBalB() != 239) return "c1.getBalB() != 239, it: ${c1.getBalB()}"
val c2 = C2();
if (c2.bal != 14) return "c2.bal != 14, it: ${c2.bal}"
if (c2.getBalA() != 42) return "c2.getBalA() != 42, it: ${c2.getBalA()}"
if (c2.getBalB() != 239) return "c2.getBalB() != 239, it: ${c2.getBalB()}"
return "OK"
}
@@ -0,0 +1,21 @@
// Test for KT-5673
package foo
interface Holder {
val element: String
}
class BasicHolder : Holder {
override val element: String
init {
element = "ok"
}
}
fun box(): String {
assertEquals("ok", BasicHolder().element)
return "OK"
}
@@ -0,0 +1,30 @@
// Test for KT-5673
package foo
interface Holder {
val element: String
}
open class BasicHolder : Holder {
override val element: String
get() = field + field
init {
element = "1"
}
}
class AdvancedHolder : BasicHolder() {
override val element: String
init {
element = super.element + super.element
}
}
fun box(): String {
assertEquals("1111", AdvancedHolder().element)
return "OK"
}
@@ -0,0 +1,21 @@
// Test for KT-5673
package foo
interface Holder {
val element: String
}
class BasicHolder : Holder {
override val element: String
init {
this.element = "ok"
}
}
fun box(): String {
assertEquals("ok", BasicHolder().element)
return "OK"
}
@@ -0,0 +1,21 @@
// Test for KT-5673
package foo
interface Holder {
var element: String
}
class BasicHolder : Holder {
override var element: String = "not ok"
init {
element = "ok"
}
}
fun box(): String {
assertEquals("ok", BasicHolder().element)
return "OK"
}
@@ -0,0 +1,28 @@
package foo
open class A {
private val a = 1
private val b = 2
get() {
return field + 10 + 100 * a
}
fun getBInA(): Int {
return b
}
}
class B : A() {
val a = 13
val b = 42
}
fun box(): String {
val b = B()
if (b.getBInA() != 112) return "b.getBInA() != 112, it: ${b.getBInA()}"
if (b.a != 13) return "b.a != 13, it: ${b.a}"
if (b.b != 42) return "b.b != 42, it: ${b.b}"
return "OK"
}
@@ -0,0 +1,25 @@
package foo
class T
open class A {
open val T.foo: Int
get() {
return 34
}
fun test(): Int {
return T().foo
}
}
class B : A() {
override val T.foo: Int get() = 5
}
fun box(): String {
if (A().test() != 34) return "A().test() != 34, it: ${A().test() != 34}"
if (B().test() != 5) return "B().test() != 5, it: ${B().test() != 5}"
return "OK"
}
@@ -0,0 +1,35 @@
package foo
open class A {
open var a = 1
fun getAInA(): Int = a
}
open class AA : A()
class B : AA() {
override var a = 2
fun getSuperA(): Int {
return super.a
}
fun setSuperA(value: Int) {
super.a = value
}
}
fun box(): String {
val a = A()
val b = B()
if (a.getAInA() != 1) return "a.getAInA() != 1, it: ${a.getAInA()}"
if (b.getAInA() != 2) return "b.getAInA() != 2, it: ${b.getAInA()}"
if (b.getSuperA() != 1) return "b.getSuperA() != 1, it: ${b.getSuperA()}"
b.setSuperA(3)
if (b.getSuperA() != 3) return "b.getSuperA() != 3, it: ${b.getSuperA()}"
if (b.getAInA() != 2) return "b.getAInA() != 2 after b.setAInB(3), it: ${b.getAInA()}"
return "OK"
}
@@ -0,0 +1,99 @@
package foo
interface A {
val bal: Int
get() {
return 5
}
var bar: Int
get() {
return realBar
}
set(value: Int) {
realBar = value
}
var realBar: Int
}
interface B {
val bal: Int
get() {
return 42
}
var bar: Int
get() {
return realBar + 1000
}
set(value: Int) {
realBar = value + 1000
}
var realBar: Int
}
class C : A, B {
override val bal: Int = 1
override var bar: Int = 2
get() {
return field + 20
}
set(value: Int) {
field = value + 20
}
override var realBar: Int = 3
fun supBalA(): Int {
return super<A>.bal
}
fun supBalB(): Int {
return super<B>.bal
}
fun supBarA(): Int {
return super<A>.bar
}
fun supBarB(): Int {
return super<B>.bar
}
fun setBarA(value: Int) {
super<A>.bar = value
}
fun setBarB(value: Int) {
super<B>.bar = value
}
}
fun box(): String {
val c = C()
if (c.bal != 1) return "c.bal != 1, it: ${c.bal}"
if (c.bar != 22) return "c.bar != 22, it: ${c.bar}"
if (c.realBar != 3) return "c.realBar != 3, it: ${c.realBar}"
c.bar = 50
if (c.bar != 90) return "c.bar != 90, it: ${c.bar}"
if (c.supBalA() != 5) return "c.supBalA() != 5, it: ${c.supBalA()}"
if (c.supBalB() != 42) return "c.supBalB() != 42, it: ${c.supBalB()}"
if (c.supBarA() != 3) return "c.supBarA() != 3, it: ${c.supBarA()}"
if (c.supBarB() != 1003) return "c.supBarB() != 1003, it: ${c.supBarB()}"
c.setBarA(239)
if (c.realBar != 239) return "c.realBar != 239, it: ${c.realBar}"
if (c.supBarA() != 239) return "c.supBarA() != 239, it: ${c.supBarA()}"
if (c.supBarB() != 1239) return "c.supBarB() != 1239, it: ${c.supBarB()}"
c.setBarB(239)
if (c.realBar != 1239) return "c.realBar != 1239, it: ${c.realBar}"
if (c.supBarA() != 1239) return "c.supBarA() != 1239, it: ${c.supBarA()}"
if (c.supBarB() != 2239) return "c.supBarB() != 2239, it: ${c.supBarB()}"
return "OK"
}
@@ -0,0 +1,25 @@
package foo
open class A {
open val a = 2
get() {
return field + 1
}
}
class B : A() {
override val a: Int = 5
get() {
return super.a + 10 * field + 100
}
}
fun box(): String {
val a = A()
val b = B()
if (a.a != 3) return "a.a != 3, it: ${a.a}"
if (b.a != 153) return "b.a != 153, it: ${b.a}"
return "OK"
}
@@ -0,0 +1,33 @@
package foo
open class A {
open var a = 1
fun getAInA(): Int = a
}
class B : A() {
override var a = 2
fun getSuperA(): Int {
return super.a
}
fun setSuperA(value: Int) {
super.a = value
}
}
fun box(): String {
val a = A()
val b = B()
if (a.getAInA() != 1) return "a.getAInA() != 1, it: ${a.getAInA()}"
if (b.getAInA() != 2) return "b.getAInA() != 2, it: ${b.getAInA()}"
if (b.getSuperA() != 1) return "b.getSuperA() != 1, it: ${b.getSuperA()}"
b.setSuperA(3)
if (b.getSuperA() != 3) return "b.getSuperA() != 3, it: ${b.getSuperA()}"
if (b.getAInA() != 2) return "b.getAInA() != 2 after b.setAInB(3), it: ${b.getAInA()}"
return "OK"
}