From d6e0f67d4e81f221fbb4eb125025f65fa6d8d779 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Fri, 14 Jul 2017 12:58:01 +0700 Subject: [PATCH] tests: Add test for nested 'for' loops --- backend.native/tests/build.gradle | 11 ++++ .../codegen/controlflow/for_loops_nested.kt | 59 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 backend.native/tests/codegen/controlflow/for_loops_nested.kt diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 5df944e0337..635bff2eae8 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -337,6 +337,17 @@ task codegen_controlflow_for_loops_empty_range(type: RunKonanTest) { goldValue = "OK\n" } +task codegen_controlflow_for_loops_nested(type: RunKonanTest) { + source = "codegen/controlflow/for_loops_nested.kt" + goldValue = "00 01 02 10 11 12 20 21 22 \n" + + "00 01 10 11 20 21 \n" + + "00 01 10 11 20 21 \n" + + "00 01 \n" + + "00 02 10 12 20 22 \n" + + "00 02 10 12 20 22 \n" + + "00 10 20 \n" +} + task local_variable(type: RunKonanTest) { source = "codegen/basics/local_variable.kt" } diff --git a/backend.native/tests/codegen/controlflow/for_loops_nested.kt b/backend.native/tests/codegen/controlflow/for_loops_nested.kt new file mode 100644 index 00000000000..9548d87e761 --- /dev/null +++ b/backend.native/tests/codegen/controlflow/for_loops_nested.kt @@ -0,0 +1,59 @@ +fun main(args: Array) { + // Simple + for (i in 0..2) { + for (j in 0..2) { + print("$i$j ") + } + } + println() + + // Break + l1@for (i in 0..2) { + l2@for (j in 0..2) { + print("$i$j ") + if (j == 1) break + } + } + println() + + l1@for (i in 0..2) { + l2@for (j in 0..2) { + print("$i$j ") + if (j == 1) break@l2 + } + } + println() + + l1@for (i in 0..2) { + l2@for (j in 0..2) { + print("$i$j ") + if (j == 1) break@l1 + } + } + println() + + // Continue + l1@for (i in 0..2) { + l2@for (j in 0..2) { + if (j == 1) continue + print("$i$j ") + } + } + println() + + l1@for (i in 0..2) { + l2@for (j in 0..2) { + if (j == 1) continue@l2 + print("$i$j ") + } + } + println() + + l1@for (i in 0..2) { + l2@for (j in 0..2) { + if (j == 1) continue@l1 + print("$i$j ") + } + } + println() +} \ No newline at end of file