From f3837e91e30e85eeb06b45bb9d7febb250c8598d Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Tue, 10 Sep 2019 15:56:23 +0300 Subject: [PATCH] Add BE tests for 'break' and 'continue' inside 'when' --- .../box/controlStructures/breakInWhen.kt | 43 ++++++++++++++++ .../box/controlStructures/continueInWhen.kt | 49 +++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 10 ++++ .../LightAnalysisModeTestGenerated.java | 10 ++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 10 ++++ .../IrJsCodegenBoxTestGenerated.java | 10 ++++ .../semantics/JsCodegenBoxTestGenerated.java | 10 ++++ 7 files changed, 142 insertions(+) create mode 100644 compiler/testData/codegen/box/controlStructures/breakInWhen.kt create mode 100644 compiler/testData/codegen/box/controlStructures/continueInWhen.kt diff --git a/compiler/testData/codegen/box/controlStructures/breakInWhen.kt b/compiler/testData/codegen/box/controlStructures/breakInWhen.kt new file mode 100644 index 00000000000..f04ce712562 --- /dev/null +++ b/compiler/testData/codegen/box/controlStructures/breakInWhen.kt @@ -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" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/controlStructures/continueInWhen.kt b/compiler/testData/codegen/box/controlStructures/continueInWhen.kt new file mode 100644 index 00000000000..deb0660766a --- /dev/null +++ b/compiler/testData/codegen/box/controlStructures/continueInWhen.kt @@ -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" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 35966f50c11..56d3ed6ec35 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -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"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index b3e0cd4bca5..c40117ddd93 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -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"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 4921928e01a..fd8cdf33ebd 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -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"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 693630e8b22..0203ce54133 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -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"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 84b2afb2923..58810600576 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -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");