Skip to content

Commit a231b21

Browse files
tihonovcoreromanart
authored andcommitted
[JS BE] add tests for es6-classes
1 parent adf6831 commit a231b21

20 files changed

+581
-0
lines changed

js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrBoxJsTestGenerated.java

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// EXPECTED_REACHABLE_NODES: 1331
2+
fun box(): String {
3+
val s = String()
4+
val ints = Array<Int>(2) { i -> (i + 2) * 2 }
5+
6+
assertEquals(4, ints[0])
7+
assertEquals(6, ints[1])
8+
9+
return "OK" + s
10+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// EXPECTED_REACHABLE_NODES: 1344
2+
open class A(var value: Int) {
3+
init {
4+
value *= 2
5+
}
6+
}
7+
8+
class B : A {
9+
init {
10+
value /= 6
11+
}
12+
13+
constructor(x: Int) : super(x) {
14+
value *= 18
15+
}
16+
17+
constructor() : this(18) {
18+
value *= 12
19+
}
20+
}
21+
22+
fun box(): String {
23+
val bs1 = B(15)
24+
assertEquals(90, bs1.value)
25+
26+
val bs2 = B()
27+
assertEquals(72 * 18, bs2.value)
28+
29+
return "OK"
30+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// EXPECTED_REACHABLE_NODES: 1347
2+
var sideEffect = ""
3+
4+
abstract class A {
5+
fun print(a: Any) { sideEffect += "#$a" }
6+
7+
constructor(x: Int, y: Int) {
8+
print(x + y)
9+
print(foo())
10+
}
11+
12+
abstract fun foo(): String
13+
14+
init {
15+
print("init: " + foo())
16+
}
17+
}
18+
19+
class O(val x: String) {
20+
inner class I() : A(13, 37) {
21+
override fun foo() = x
22+
}
23+
}
24+
25+
fun box(): String {
26+
val o = O("OK")
27+
val i = o.I()
28+
29+
assertEquals("#init: OK#50#OK", sideEffect)
30+
31+
return i.foo()
32+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class E {
2+
constructor() { }
3+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//IGNORE_BACKEND: JS, JS_IR
2+
3+
var sideEffect = ""
4+
5+
open external class E()
6+
abstract class A : E {
7+
fun print(a: Any) { sideEffect += "#$a" }
8+
9+
constructor(x: Int, y: Int) : super() {
10+
print(x + y)
11+
print(foo())
12+
}
13+
14+
constructor(x: Int) : super() {
15+
print(x)
16+
print(foo())
17+
}
18+
19+
abstract fun foo(): String
20+
21+
init {
22+
print("init: " + foo())
23+
}
24+
}
25+
26+
class O(val x: String) {
27+
inner class I() : A(1337) {
28+
override fun foo() = x
29+
}
30+
}
31+
32+
fun box(): String {
33+
val o = O("OK")
34+
val i = o.I()
35+
36+
assertEquals("#init: OK#1337#OK", sideEffect)
37+
38+
return i.foo()
39+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// EXPECTED_REACHABLE_NODES: 1355
2+
var sideEffect = ""
3+
4+
open class Summator(x: Int, y: Int) {
5+
val sum = x + y
6+
}
7+
8+
abstract class A : Summator {
9+
fun print(a: Any) { sideEffect += "#$a" }
10+
11+
constructor(x: Int, y: Int) : super(x, y) { //try pass `foo()`
12+
print(sum)
13+
print(foo())
14+
}
15+
16+
abstract fun foo(): String
17+
18+
init {
19+
print("init: " + foo())
20+
}
21+
}
22+
23+
class O(val x: String) {
24+
inner class I() : A(13, 37) {
25+
override fun foo() = x
26+
}
27+
}
28+
29+
fun box(): String {
30+
val o = O("OK")
31+
val i = o.I()
32+
33+
assertEquals("#init: OK#50#OK", sideEffect)
34+
35+
return i.foo()
36+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// EXPECTED_REACHABLE_NODES: 1359
2+
open class A(val x: Int) {
3+
constructor(): this(100)
4+
}
5+
6+
class PrimaryToPrimary(val p: Int): A(p * p)
7+
class PrimaryToSecondary(val p: Int): A()
8+
9+
class SecondaryToPrimary : A {
10+
constructor() : super(8)
11+
}
12+
class SecondaryToSecondary: A {
13+
constructor() : super()
14+
}
15+
16+
fun box(): String {
17+
val ptp = PrimaryToPrimary(5)
18+
assertEquals(ptp.p, 5)
19+
assertEquals(ptp.x, 25)
20+
21+
val pts = PrimaryToSecondary(9)
22+
assertEquals(pts.p, 9)
23+
assertEquals(pts.x, 100)
24+
25+
val stp = SecondaryToPrimary()
26+
assertEquals(stp.x, 8)
27+
28+
val sts = SecondaryToSecondary()
29+
assertEquals(sts.x, 100)
30+
31+
return "OK"
32+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// EXPECTED_REACHABLE_NODES: 1340
2+
open class A(val x: Int)
3+
4+
class B(val p: Int, val q: Int): A(p + q)
5+
6+
fun box(): String {
7+
val b = B(2, 3)
8+
assertEquals(b.p, 2)
9+
assertEquals(b.q, 3)
10+
assertEquals(b.x, 5)
11+
12+
return "OK"
13+
}

0 commit comments

Comments
 (0)