Add BE tests for 'break' and 'continue' inside 'when'

This commit is contained in:
Dmitry Petrov
2019-09-10 15:56:23 +03:00
parent f06f6f4660
commit f3837e91e3
7 changed files with 142 additions and 0 deletions
@@ -0,0 +1,43 @@
// !LANGUAGE: +AllowBreakAndContinueInsideWhen
fun testFor() {
val xs = IntArray(10) { i -> i }
var k = 0
for (x in xs) {
when {
k > 2 -> break
}
++k
}
if (k != 3) throw AssertionError()
}
fun testWhile() {
var k = 0
while (k < 10) {
when {
k > 2 -> break
}
++k
}
if (k != 3) throw AssertionError()
}
fun testDoWhile() {
var k = 0
do {
when {
k > 2 -> break
}
++k
} while (k < 10)
if (k != 3) throw AssertionError()
}
fun box(): String {
testFor()
testWhile()
testDoWhile()
return "OK"
}
@@ -0,0 +1,49 @@
// !LANGUAGE: +AllowBreakAndContinueInsideWhen
fun testFor() {
val xs = IntArray(10) { i -> i }
var k = 0
var s = ""
for (x in xs) {
++k
when {
k > 2 -> continue
}
s += "$k;"
}
if (s != "1;2;") throw AssertionError(s)
}
fun testWhile() {
var k = 0
var s = ""
while (k < 10) {
++k
when {
k > 2 -> continue
}
s += "$k;"
}
if (s != "1;2;") throw AssertionError(s)
}
fun testDoWhile() {
var k = 0
var s = ""
do {
++k
when {
k > 2 -> continue
}
s += "$k;"
} while (k < 10)
if (s != "1;2;") throw AssertionError(s)
}
fun box(): String {
testFor()
testWhile()
testDoWhile()
return "OK"
}
@@ -4683,6 +4683,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/controlStructures/breakInFinally.kt");
}
@TestMetadata("breakInWhen.kt")
public void testBreakInWhen() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/breakInWhen.kt");
}
@TestMetadata("compareBoxedIntegerToZero.kt")
public void testCompareBoxedIntegerToZero() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/compareBoxedIntegerToZero.kt");
@@ -4708,6 +4713,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/controlStructures/continueInForCondition.kt");
}
@TestMetadata("continueInWhen.kt")
public void testContinueInWhen() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/continueInWhen.kt");
}
@TestMetadata("continueInWhile.kt")
public void testContinueInWhile() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/continueInWhile.kt");
@@ -4683,6 +4683,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/controlStructures/breakInFinally.kt");
}
@TestMetadata("breakInWhen.kt")
public void testBreakInWhen() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/breakInWhen.kt");
}
@TestMetadata("compareBoxedIntegerToZero.kt")
public void testCompareBoxedIntegerToZero() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/compareBoxedIntegerToZero.kt");
@@ -4708,6 +4713,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/controlStructures/continueInForCondition.kt");
}
@TestMetadata("continueInWhen.kt")
public void testContinueInWhen() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/continueInWhen.kt");
}
@TestMetadata("continueInWhile.kt")
public void testContinueInWhile() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/continueInWhile.kt");
@@ -4653,6 +4653,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/controlStructures/breakInFinally.kt");
}
@TestMetadata("breakInWhen.kt")
public void testBreakInWhen() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/breakInWhen.kt");
}
@TestMetadata("compareBoxedIntegerToZero.kt")
public void testCompareBoxedIntegerToZero() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/compareBoxedIntegerToZero.kt");
@@ -4678,6 +4683,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/controlStructures/continueInForCondition.kt");
}
@TestMetadata("continueInWhen.kt")
public void testContinueInWhen() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/continueInWhen.kt");
}
@TestMetadata("continueInWhile.kt")
public void testContinueInWhile() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/continueInWhile.kt");
@@ -3808,6 +3808,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/controlStructures/breakInFinally.kt");
}
@TestMetadata("breakInWhen.kt")
public void testBreakInWhen() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/breakInWhen.kt");
}
@TestMetadata("compareBoxedIntegerToZero.kt")
public void testCompareBoxedIntegerToZero() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/compareBoxedIntegerToZero.kt");
@@ -3833,6 +3838,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/controlStructures/continueInForCondition.kt");
}
@TestMetadata("continueInWhen.kt")
public void testContinueInWhen() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/continueInWhen.kt");
}
@TestMetadata("continueInWhile.kt")
public void testContinueInWhile() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/continueInWhile.kt");
@@ -3818,6 +3818,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/controlStructures/breakInFinally.kt");
}
@TestMetadata("breakInWhen.kt")
public void testBreakInWhen() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/breakInWhen.kt");
}
@TestMetadata("compareBoxedIntegerToZero.kt")
public void testCompareBoxedIntegerToZero() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/compareBoxedIntegerToZero.kt");
@@ -3843,6 +3848,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/controlStructures/continueInForCondition.kt");
}
@TestMetadata("continueInWhen.kt")
public void testContinueInWhen() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/continueInWhen.kt");
}
@TestMetadata("continueInWhile.kt")
public void testContinueInWhile() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/continueInWhile.kt");