JS backend: added tests for labels
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package foo
|
||||
|
||||
// CHECK_LABELS_COUNT: function=test1 name=loop$ count=1
|
||||
// CHECK_LABELS_COUNT: function=test2 name=loop$ count=1
|
||||
|
||||
fun test1() {
|
||||
var `loop$` = 0
|
||||
|
||||
@loop for (i in 1..10) {
|
||||
`loop$` = i
|
||||
if (i == 5) break@loop
|
||||
}
|
||||
|
||||
assertEquals(5, `loop$`, "test1")
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
var loop = 0
|
||||
|
||||
@loop for (i in 1..10) {
|
||||
loop = i
|
||||
if (i == 5) break@loop
|
||||
}
|
||||
|
||||
assertEquals(5, loop, "test2")
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
test1()
|
||||
test2()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package foo
|
||||
|
||||
// CHECK_LABELS_COUNT: function=test name=loop$ count=1
|
||||
// CHECK_LABELS_COUNT: function=test name=loop$_0 count=1
|
||||
|
||||
fun test() {
|
||||
var i = 0
|
||||
var j = 0
|
||||
|
||||
@loop for (k in 1..10) {
|
||||
@loop for (m in 1..10) {
|
||||
if (m == 4) break @loop
|
||||
j = m
|
||||
}
|
||||
|
||||
if (k == 8) break @loop
|
||||
i = k
|
||||
}
|
||||
|
||||
assertEquals(3, j)
|
||||
assertEquals(7, i)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package foo
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: test
|
||||
// CHECK_LABELS_COUNT: function=test name=loop$ count=1
|
||||
// CHECK_LABELS_COUNT: function=test name=loop$_0 count=1
|
||||
// CHECK_LABELS_COUNT: function=test name=loop$_1 count=1
|
||||
|
||||
class State() {
|
||||
public var value: Int = 0
|
||||
}
|
||||
|
||||
inline fun test1(state: State) {
|
||||
@loop for (i in 1..10) {
|
||||
state.value++
|
||||
if (i == 2) break@loop
|
||||
}
|
||||
}
|
||||
|
||||
inline fun test2(state: State) {
|
||||
@loop for (i in 1..10) {
|
||||
test1(state)
|
||||
if (i == 2) break@loop
|
||||
}
|
||||
}
|
||||
|
||||
inline fun test3(state: State) {
|
||||
@loop for (i in 1..10) {
|
||||
test2(state)
|
||||
if (i == 2) break@loop
|
||||
}
|
||||
}
|
||||
|
||||
noinline fun test(state: State) {
|
||||
test3(state)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val state = State()
|
||||
test(state)
|
||||
assertEquals(8, state.value)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package foo
|
||||
|
||||
// CHECK_LABELS_COUNT: function=test name=loop$ count=1
|
||||
// CHECK_LABELS_COUNT: function=test name=loop$_0 count=1
|
||||
// CHECK_LABELS_COUNT: function=test name=loop$_1 count=1
|
||||
|
||||
class State() {
|
||||
public var value: Int = 0
|
||||
}
|
||||
|
||||
noinline fun test(state: State) {
|
||||
[inline] fun test3() {
|
||||
[inline] fun test2() {
|
||||
[inline] fun test1() {
|
||||
@loop for (i in 1..10) {
|
||||
state.value++
|
||||
if (i == 2) break@loop
|
||||
}
|
||||
}
|
||||
|
||||
@loop for (i in 1..10) {
|
||||
test1()
|
||||
if (i == 2) break@loop
|
||||
}
|
||||
}
|
||||
|
||||
@loop for (i in 1..10) {
|
||||
test2()
|
||||
if (i == 2) break@loop
|
||||
}
|
||||
}
|
||||
|
||||
test3()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val state = State()
|
||||
test(state)
|
||||
assertEquals(8, state.value)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package foo
|
||||
|
||||
// CHECK_LABELS_COUNT: function=test name=loop$ count=2
|
||||
|
||||
fun test() {
|
||||
var i = 0
|
||||
var j = 0
|
||||
|
||||
@loop for (m in 1..10) {
|
||||
if (m == 4) break @loop
|
||||
j = m
|
||||
}
|
||||
|
||||
@loop for (k in 1..10) {
|
||||
if (k == 4) break @loop
|
||||
i = k
|
||||
}
|
||||
|
||||
assertEquals(3, j)
|
||||
assertEquals(3, i)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package foo
|
||||
|
||||
// CHECK_NOT_CALLED: testInline
|
||||
// CHECK_LABELS_COUNT: function=testNoinline name=loop$ count=2
|
||||
|
||||
inline fun testInline(): Int {
|
||||
var c = 0
|
||||
|
||||
@loop for (i in 1..9) {
|
||||
c++
|
||||
if (c == 2) break@loop
|
||||
}
|
||||
|
||||
|
||||
@loop for (j in 1..9) {
|
||||
c++
|
||||
if (c == 4) break@loop
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
noinline fun testNoinline(): Int {
|
||||
return testInline()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(4, testNoinline())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+4
@@ -1,5 +1,9 @@
|
||||
package foo
|
||||
|
||||
// CHECK_NOT_CALLED: testLabelInline
|
||||
// CHECK_LABELS_COUNT: function=testLabel name=loop$ count=1
|
||||
// CHECK_LABELS_COUNT: function=testLabel name=loop$_0 count=2
|
||||
|
||||
inline fun testLabelInline(): Int {
|
||||
var a = 0
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package foo
|
||||
|
||||
// CHECK_LABELS_COUNT: function=testBreak name=loop$ count=1
|
||||
// CHECK_LABELS_COUNT: function=testContinue name=loop$ count=1
|
||||
|
||||
fun testBreak() {
|
||||
var i = 0
|
||||
|
||||
@loop for (j in 1..10) {
|
||||
if (j == 5) break @loop
|
||||
|
||||
i = j
|
||||
}
|
||||
|
||||
assertEquals(4, i, "break")
|
||||
}
|
||||
|
||||
fun testContinue() {
|
||||
var sum = 0
|
||||
|
||||
@loop for (j in 1..5) {
|
||||
if (j % 2 != 0) continue @loop
|
||||
|
||||
sum += j
|
||||
}
|
||||
|
||||
assertEquals(6, sum, "continue")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
testBreak()
|
||||
testContinue()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package foo
|
||||
|
||||
// CHECK_NOT_CALLED: testBreak
|
||||
// CHECK_NOT_CALLED: testContinue
|
||||
// CHECK_LABELS_COUNT: function=testBreakNoinline name=loop$ count=1
|
||||
// CHECK_LABELS_COUNT: function=testContinueNoinline name=loop$ count=1
|
||||
|
||||
inline fun testBreak(): Int {
|
||||
var i = 0
|
||||
|
||||
@loop for (j in 1..10) {
|
||||
if (j == 5) break @loop
|
||||
|
||||
i = j
|
||||
}
|
||||
|
||||
return i
|
||||
}
|
||||
|
||||
noinline fun testBreakNoinline() {
|
||||
assertEquals(4, testBreak(), "break")
|
||||
}
|
||||
|
||||
inline fun testContinue(): Int {
|
||||
var sum = 0
|
||||
|
||||
@loop for (j in 1..5) {
|
||||
if (j % 2 != 0) continue @loop
|
||||
|
||||
sum += j
|
||||
}
|
||||
|
||||
return sum
|
||||
}
|
||||
|
||||
noinline fun testContinueNoinline() {
|
||||
assertEquals(6, testContinue(), "continue")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
testContinue()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user