JS: move more test to box tests

This commit is contained in:
Alexey Andreev
2016-08-29 12:37:13 +03:00
parent efb82a044f
commit cdf2212c73
70 changed files with 484 additions and 749 deletions
@@ -0,0 +1,56 @@
// CHECK_LABELS_COUNT: function=test0 count=0
// CHECK_LABELS_COUNT: function=test1 count=0
// CHECK_LABELS_COUNT: function=test2 count=0
// CHECK_LABELS_COUNT: function=test3 count=0
package foo
fun <R> myRun(f: () -> R) = f()
fun test0() {
val a = aa@ 1
assertEquals(1, a)
assertEquals(3, l1@ a + l2@ 2)
val b = bb@ if (true) t@ "then block" else e@ "else block"
assertEquals("then block", b)
}
fun test1() {
run label@ {
return@label false
}
}
fun test2() {
myRun label@ {
return@label false
}
}
// KT-7487
public fun test3() {
val f = Foo()
f.iter label@ {
return@label false
}
}
class Foo {
inline fun iter(body: ()->Boolean) {
for (i in 0 .. 10) {
if (!body()) break
}
}
}
fun box(): String {
test0()
test1()
test2()
test3()
return "OK"
}
@@ -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,46 @@
package foo
var state = false
inline fun blockImpl(p: () -> Unit) {
if (state) return
p()
}
inline fun block(p: () -> Unit) {
if (state) return
blockImpl(p)
}
fun test(x: Int): Int {
block outer@ {
block inner@ {
if (x < 10) return@inner
if (x == 10) return@outer
block innermost@ {
if (x > 500) {
return 500500
}
}
return x
}
if (x < 5) return@outer
return x + 10
}
return x + 100
}
fun box(): String {
assertEquals(16, test(6))
assertEquals(104, test(4))
assertEquals(110, test(110))
assertEquals(11, test(11))
assertEquals(500500, test(502))
return "OK"
}
+28
View File
@@ -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
}
internal inline fun test1(state: State) {
loop@ for (i in 1..10) {
state.value++
if (i == 2) break@loop
}
}
internal inline fun test2(state: State) {
loop@ for (i in 1..10) {
test1(state)
if (i == 2) break@loop
}
}
internal inline fun test3(state: State) {
loop@ for (i in 1..10) {
test2(state)
if (i == 2) break@loop
}
}
internal fun test(state: State) {
test3(state)
}
fun box(): String {
val state = State()
test(state)
assertEquals(8, state.value)
return "OK"
}
@@ -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
}
internal 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"
}
+27
View File
@@ -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
}
fun testNoinline(): Int {
return testInline()
}
fun box(): String {
assertEquals(4, testNoinline())
return "OK"
}
@@ -0,0 +1,49 @@
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
loop@ for (i in 1..10) {
if (i == 1) continue@loop
a += i
if (i == 2) break@loop
}
loop@ for (i in 1..10) {
if (i == 1) continue@loop
a += i
if (i == 2) break@loop
}
return a
}
fun testLabel(): String {
var a = 0
loop@ for (i in 1..10) {
if (i == 1) continue@loop
a += testLabelInline()
if (i == 2) break@loop
}
if (a != 4) return a.toString()
return "OK"
}
fun box(): String {
assertEquals("OK", testLabel())
return "OK"
}
+35
View File
@@ -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
}
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
}
fun testContinueNoinline() {
assertEquals(6, testContinue(), "continue")
}
fun box(): String {
testContinue()
return "OK"
}