From d598eb48bb9b2c95e94fe76bb8df5a027c3e9f0b Mon Sep 17 00:00:00 2001 From: Alexey Stepanov Date: Mon, 8 Aug 2016 12:03:59 +0300 Subject: [PATCH] translator: add test for when --- .../src/main/resources/kotlib/kotlin/ByteArray.kt | 2 +- .../src/main/resources/kotlib/kotlin/IntArray.kt | 2 +- .../test/kotlin/tests/input/when_expression_1.txt | 3 +++ .../test/kotlin/tests/kotlin/when_expression_1.kt | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/translator/src/main/resources/kotlib/kotlin/ByteArray.kt b/translator/src/main/resources/kotlib/kotlin/ByteArray.kt index a62fc3b777c..6cf457c6f8e 100644 --- a/translator/src/main/resources/kotlib/kotlin/ByteArray.kt +++ b/translator/src/main/resources/kotlib/kotlin/ByteArray.kt @@ -7,7 +7,7 @@ class ByteArray(var size: Int) { val data: Int /** Returns the number of elements in the array. */ - //val size: Int + //size: Int init { this.data = malloc_array(this.size) diff --git a/translator/src/main/resources/kotlib/kotlin/IntArray.kt b/translator/src/main/resources/kotlib/kotlin/IntArray.kt index 5cc862b7089..27a808a888b 100644 --- a/translator/src/main/resources/kotlib/kotlin/IntArray.kt +++ b/translator/src/main/resources/kotlib/kotlin/IntArray.kt @@ -6,7 +6,7 @@ class IntArray(var size: Int) { val data: Int /** Returns the number of elements in the array. */ - //val size: Int + //size: Int init { this.data = malloc_array(4 * this.size) diff --git a/translator/src/test/kotlin/tests/input/when_expression_1.txt b/translator/src/test/kotlin/tests/input/when_expression_1.txt index 0e34c8ea655..9e1a1287947 100644 --- a/translator/src/test/kotlin/tests/input/when_expression_1.txt +++ b/translator/src/test/kotlin/tests/input/when_expression_1.txt @@ -2,3 +2,6 @@ when_expression_1_Int(21234) == 20 when_expression_1_Int(55555) == 50 when_expression_1_Int(345626) == 100 when_expression_1_Int(756754) == 100 +when_expression_2_Byte(0) == 100 +when_expression_2_Byte(5) == 105 +when_expression_2_Byte(155) == 199 diff --git a/translator/src/test/kotlin/tests/kotlin/when_expression_1.kt b/translator/src/test/kotlin/tests/kotlin/when_expression_1.kt index a5eb8226b8e..ebd1fe4f40b 100644 --- a/translator/src/test/kotlin/tests/kotlin/when_expression_1.kt +++ b/translator/src/test/kotlin/tests/kotlin/when_expression_1.kt @@ -5,4 +5,18 @@ fun when_expression_1(x: Int): Int { else -> 100 } return z +} + +fun when_expression_2 (value: Byte): Int { + val result = when (value) { + 0.toByte() -> 100 + 1.toByte() -> 101 + 2.toByte() -> 102 + 3.toByte() -> 103 + 4.toByte() -> 104 + 5.toByte() -> 105 + else -> 199 + } + + return result } \ No newline at end of file