From 36e242a9e67502d388c056e41b9e893ede3f30c8 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Fri, 30 Mar 2012 13:21:49 +0400 Subject: [PATCH] Add test for uncovered case. --- js/js.libraries/src/core/core.kt | 4 ++++ .../k2js/test/semantics/MiscTest.java | 4 ++++ .../misc/cases/whenReturnedWithoutBlock.kt | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 js/js.translator/testFiles/expression/misc/cases/whenReturnedWithoutBlock.kt diff --git a/js/js.libraries/src/core/core.kt b/js/js.libraries/src/core/core.kt index 26d09928bdd..a6b03627bba 100644 --- a/js/js.libraries/src/core/core.kt +++ b/js/js.libraries/src/core/core.kt @@ -19,6 +19,10 @@ fun print(s : Any?) {} library("parseInt") fun parseInt(s : String) : Int = js.noImpl library +fun safeParseInt(s : String) : Int? = js.noImpl +library +fun safeParseDouble(s : String) : Double? = js.noImpl +library open class Exception() : Throwable() {} library class NumberFormatException() : Exception() {} diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/MiscTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/MiscTest.java index 0f0c4698b66..d3be26a1a43 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/MiscTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/MiscTest.java @@ -113,4 +113,8 @@ public final class MiscTest extends AbstractExpressionTest { public void testTemporaryVariableCreatedInNamespaceInitializer() throws Exception { checkFooBoxIsTrue("temporaryVariableCreatedInNamespaceInitializer.kt"); } + + public void testWhenReturnedWithoutBlock() throws Exception { + checkFooBoxIsTrue("whenReturnedWithoutBlock.kt"); + } } diff --git a/js/js.translator/testFiles/expression/misc/cases/whenReturnedWithoutBlock.kt b/js/js.translator/testFiles/expression/misc/cases/whenReturnedWithoutBlock.kt new file mode 100644 index 00000000000..bbc80810dbb --- /dev/null +++ b/js/js.translator/testFiles/expression/misc/cases/whenReturnedWithoutBlock.kt @@ -0,0 +1,18 @@ +package foo + +fun box() : Boolean { + if (t(1) != 0) { + return false + } + if (t(0) != 1) { + return false + } + return (t(100) == 2) + +} + +fun t(i : Int) = when(i) { + 0 -> 1 + 1 -> 0 + else -> 2 +} \ No newline at end of file