From 18cb479ef38898e4a0464d7c9123b07bf3112142 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Sat, 19 Jul 2014 13:14:18 +0400 Subject: [PATCH] When2Switch: tests for non-literal expression in when by integral --- .../integralWhenWithNoInlinedConstants.kt | 23 +++++++++++++++++++ .../integralWhenWithNoInlinedConstants.kt | 16 +++++++++++++ .../codegen/BytecodeTextTestGenerated.java | 16 ++++++++++++- ...lackBoxWithStdlibCodegenTestGenerated.java | 5 ++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/boxWithStdlib/when/integralWhenWithNoInlinedConstants.kt create mode 100644 compiler/testData/codegen/bytecodeText/when/integralWhenWithNoInlinedConstants.kt diff --git a/compiler/testData/codegen/boxWithStdlib/when/integralWhenWithNoInlinedConstants.kt b/compiler/testData/codegen/boxWithStdlib/when/integralWhenWithNoInlinedConstants.kt new file mode 100644 index 00000000000..970266e7084 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/when/integralWhenWithNoInlinedConstants.kt @@ -0,0 +1,23 @@ +fun foo1(x: Int): Boolean { + when(x) { + 2 + 2 -> return true + else -> return false + } +} + +fun foo2(x: Int): Boolean { + when(x) { + Integer.MAX_VALUE -> return true + else -> return false + } +} + +fun box(): String { + assert(foo1(4)) + assert(!foo1(1)) + + assert(foo2(Integer.MAX_VALUE)) + assert(!foo2(1)) + + return "OK" +} diff --git a/compiler/testData/codegen/bytecodeText/when/integralWhenWithNoInlinedConstants.kt b/compiler/testData/codegen/bytecodeText/when/integralWhenWithNoInlinedConstants.kt new file mode 100644 index 00000000000..f01c101af8c --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/when/integralWhenWithNoInlinedConstants.kt @@ -0,0 +1,16 @@ +fun foo1(x: Int): Boolean { + when(x) { + 2 + 2 -> return true + else -> return false + } +} + +fun foo2(x: Int): Boolean { + when(x) { + Integer.MAX_VALUE -> return true + else -> return false + } +} + +// 0 TABLESWITCH +// 2 LOOKUPSWITCH diff --git a/compiler/tests/org/jetbrains/jet/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/BytecodeTextTestGenerated.java index 62f744e921d..9901afa8769 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/BytecodeTextTestGenerated.java @@ -31,7 +31,7 @@ import org.jetbrains.jet.codegen.AbstractBytecodeTextTest; /** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") @TestMetadata("compiler/testData/codegen/bytecodeText") -@InnerTestClasses({BytecodeTextTestGenerated.BoxingOptimization.class, BytecodeTextTestGenerated.Constants.class, BytecodeTextTestGenerated.DirectInvoke.class, BytecodeTextTestGenerated.Statements.class, BytecodeTextTestGenerated.WhenEnumOptimization.class, BytecodeTextTestGenerated.WhenStringOptimization.class}) +@InnerTestClasses({BytecodeTextTestGenerated.BoxingOptimization.class, BytecodeTextTestGenerated.Constants.class, BytecodeTextTestGenerated.DirectInvoke.class, BytecodeTextTestGenerated.Statements.class, BytecodeTextTestGenerated.When.class, BytecodeTextTestGenerated.WhenEnumOptimization.class, BytecodeTextTestGenerated.WhenStringOptimization.class}) public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { @TestMetadata("accessorForProtected.kt") public void testAccessorForProtected() throws Exception { @@ -304,6 +304,19 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { } + @TestMetadata("compiler/testData/codegen/bytecodeText/when") + public static class When extends AbstractBytecodeTextTest { + public void testAllFilesPresentInWhen() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/bytecodeText/when"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("integralWhenWithNoInlinedConstants.kt") + public void testIntegralWhenWithNoInlinedConstants() throws Exception { + doTest("compiler/testData/codegen/bytecodeText/when/integralWhenWithNoInlinedConstants.kt"); + } + + } + @TestMetadata("compiler/testData/codegen/bytecodeText/whenEnumOptimization") public static class WhenEnumOptimization extends AbstractBytecodeTextTest { public void testAllFilesPresentInWhenEnumOptimization() throws Exception { @@ -412,6 +425,7 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { suite.addTestSuite(Constants.class); suite.addTestSuite(DirectInvoke.class); suite.addTestSuite(Statements.class); + suite.addTestSuite(When.class); suite.addTestSuite(WhenEnumOptimization.class); suite.addTestSuite(WhenStringOptimization.class); return suite; diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java index 7631aa249a5..6f46c2888ab 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java @@ -1920,6 +1920,11 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib/when"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("integralWhenWithNoInlinedConstants.kt") + public void testIntegralWhenWithNoInlinedConstants() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/when/integralWhenWithNoInlinedConstants.kt"); + } + @TestMetadata("switchOptimizationDense.kt") public void testSwitchOptimizationDense() throws Exception { doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/when/switchOptimizationDense.kt");