From 5dc08a5d25793de94634859a2d98c0f0b4328a70 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Tue, 14 May 2013 16:50:06 +0400 Subject: [PATCH] Add tests with multiple conditions types in 'when' --- .../whenWithMultipleConditionTypes.kt | 10 +++++++++ .../whenWithMultipleConditionTypes.kt.after | 12 ++++++++++ .../whenWithMultipleConditionTypes.kt | 12 ++++++++++ .../whenWithMultipleConditionTypes.kt.after | 10 +++++++++ .../whenWithMultipleConditionTypes.kt | 12 ++++++++++ .../whenWithMultipleConditionTypes.kt.after | 12 ++++++++++ .../whenWithMultipleConditionTypes.kt | 12 ++++++++++ .../whenWithMultipleConditionTypes.kt.after | 12 ++++++++++ .../CodeTransformationsTestGenerated.java | 22 ++++++++++++++++++- 9 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 idea/testData/codeInsight/codeTransformations/branched/ifWhen/ifToWhen/whenWithMultipleConditionTypes.kt create mode 100644 idea/testData/codeInsight/codeTransformations/branched/ifWhen/ifToWhen/whenWithMultipleConditionTypes.kt.after create mode 100644 idea/testData/codeInsight/codeTransformations/branched/ifWhen/whenToIf/whenWithMultipleConditionTypes.kt create mode 100644 idea/testData/codeInsight/codeTransformations/branched/ifWhen/whenToIf/whenWithMultipleConditionTypes.kt.after create mode 100644 idea/testData/codeInsight/codeTransformations/branched/when/eliminateSubject/whenWithMultipleConditionTypes.kt create mode 100644 idea/testData/codeInsight/codeTransformations/branched/when/eliminateSubject/whenWithMultipleConditionTypes.kt.after create mode 100644 idea/testData/codeInsight/codeTransformations/branched/when/introduceSubject/whenWithMultipleConditionTypes.kt create mode 100644 idea/testData/codeInsight/codeTransformations/branched/when/introduceSubject/whenWithMultipleConditionTypes.kt.after diff --git a/idea/testData/codeInsight/codeTransformations/branched/ifWhen/ifToWhen/whenWithMultipleConditionTypes.kt b/idea/testData/codeInsight/codeTransformations/branched/ifWhen/ifToWhen/whenWithMultipleConditionTypes.kt new file mode 100644 index 00000000000..59da552daeb --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/ifWhen/ifToWhen/whenWithMultipleConditionTypes.kt @@ -0,0 +1,10 @@ +fun test(n: Int): String { + return if (n !is Int) "???" + else if (n in 0..10) "small" + else if (n in 10..100) "average" + else if (n in 100..1000) "big" + else if (n == 1000000) "million" + else if (n !in -100..-10) "good" + else if (n is Int) "unknown" + else "unknown" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/ifWhen/ifToWhen/whenWithMultipleConditionTypes.kt.after b/idea/testData/codeInsight/codeTransformations/branched/ifWhen/ifToWhen/whenWithMultipleConditionTypes.kt.after new file mode 100644 index 00000000000..6babe750cc6 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/ifWhen/ifToWhen/whenWithMultipleConditionTypes.kt.after @@ -0,0 +1,12 @@ +fun test(n: Int): String { + return when { + n !is Int -> "???" + n in 0..10 -> "small" + n in 10..100 -> "average" + n in 100..1000 -> "big" + n == 1000000 -> "million" + n !in -100..-10 -> "good" + n is Int -> "unknown" + else -> "unknown" + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/ifWhen/whenToIf/whenWithMultipleConditionTypes.kt b/idea/testData/codeInsight/codeTransformations/branched/ifWhen/whenToIf/whenWithMultipleConditionTypes.kt new file mode 100644 index 00000000000..ea4d863fb5d --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/ifWhen/whenToIf/whenWithMultipleConditionTypes.kt @@ -0,0 +1,12 @@ +fun test(n: Int): String { + return when (n) { + !is Int -> "???" + in 0..10 -> "small" + in 10..100 -> "average" + in 100..1000 -> "big" + 1000000 -> "million" + !in -100..-10 -> "good" + is Int -> "unknown" + else -> "unknown" + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/ifWhen/whenToIf/whenWithMultipleConditionTypes.kt.after b/idea/testData/codeInsight/codeTransformations/branched/ifWhen/whenToIf/whenWithMultipleConditionTypes.kt.after new file mode 100644 index 00000000000..59da552daeb --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/ifWhen/whenToIf/whenWithMultipleConditionTypes.kt.after @@ -0,0 +1,10 @@ +fun test(n: Int): String { + return if (n !is Int) "???" + else if (n in 0..10) "small" + else if (n in 10..100) "average" + else if (n in 100..1000) "big" + else if (n == 1000000) "million" + else if (n !in -100..-10) "good" + else if (n is Int) "unknown" + else "unknown" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/when/eliminateSubject/whenWithMultipleConditionTypes.kt b/idea/testData/codeInsight/codeTransformations/branched/when/eliminateSubject/whenWithMultipleConditionTypes.kt new file mode 100644 index 00000000000..ea4d863fb5d --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/when/eliminateSubject/whenWithMultipleConditionTypes.kt @@ -0,0 +1,12 @@ +fun test(n: Int): String { + return when (n) { + !is Int -> "???" + in 0..10 -> "small" + in 10..100 -> "average" + in 100..1000 -> "big" + 1000000 -> "million" + !in -100..-10 -> "good" + is Int -> "unknown" + else -> "unknown" + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/when/eliminateSubject/whenWithMultipleConditionTypes.kt.after b/idea/testData/codeInsight/codeTransformations/branched/when/eliminateSubject/whenWithMultipleConditionTypes.kt.after new file mode 100644 index 00000000000..6babe750cc6 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/when/eliminateSubject/whenWithMultipleConditionTypes.kt.after @@ -0,0 +1,12 @@ +fun test(n: Int): String { + return when { + n !is Int -> "???" + n in 0..10 -> "small" + n in 10..100 -> "average" + n in 100..1000 -> "big" + n == 1000000 -> "million" + n !in -100..-10 -> "good" + n is Int -> "unknown" + else -> "unknown" + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/when/introduceSubject/whenWithMultipleConditionTypes.kt b/idea/testData/codeInsight/codeTransformations/branched/when/introduceSubject/whenWithMultipleConditionTypes.kt new file mode 100644 index 00000000000..6babe750cc6 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/when/introduceSubject/whenWithMultipleConditionTypes.kt @@ -0,0 +1,12 @@ +fun test(n: Int): String { + return when { + n !is Int -> "???" + n in 0..10 -> "small" + n in 10..100 -> "average" + n in 100..1000 -> "big" + n == 1000000 -> "million" + n !in -100..-10 -> "good" + n is Int -> "unknown" + else -> "unknown" + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/when/introduceSubject/whenWithMultipleConditionTypes.kt.after b/idea/testData/codeInsight/codeTransformations/branched/when/introduceSubject/whenWithMultipleConditionTypes.kt.after new file mode 100644 index 00000000000..ea4d863fb5d --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/when/introduceSubject/whenWithMultipleConditionTypes.kt.after @@ -0,0 +1,12 @@ +fun test(n: Int): String { + return when (n) { + !is Int -> "???" + in 0..10 -> "small" + in 10..100 -> "average" + in 100..1000 -> "big" + 1000000 -> "million" + !in -100..-10 -> "good" + is Int -> "unknown" + else -> "unknown" + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/CodeTransformationsTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/CodeTransformationsTestGenerated.java index 71da5f98dfc..3c2918daea9 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/CodeTransformationsTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/CodeTransformationsTestGenerated.java @@ -252,7 +252,7 @@ public class CodeTransformationsTestGenerated extends AbstractCodeTransformation } } - + @TestMetadata("idea/testData/codeInsight/codeTransformations/branched/unfolding/returnToIf") public static class ReturnToIf extends AbstractCodeTransformationTest { public void testAllFilesPresentInReturnToIf() throws Exception { @@ -345,6 +345,11 @@ public class CodeTransformationsTestGenerated extends AbstractCodeTransformation doTestIfToWhen("idea/testData/codeInsight/codeTransformations/branched/ifWhen/ifToWhen/ifWithRangeTestsAndUnparenthesizedMultiConditions.kt"); } + @TestMetadata("whenWithMultipleConditionTypes.kt") + public void testWhenWithMultipleConditionTypes() throws Exception { + doTestIfToWhen("idea/testData/codeInsight/codeTransformations/branched/ifWhen/ifToWhen/whenWithMultipleConditionTypes.kt"); + } + } @TestMetadata("idea/testData/codeInsight/codeTransformations/branched/ifWhen/whenToIf") @@ -363,6 +368,11 @@ public class CodeTransformationsTestGenerated extends AbstractCodeTransformation doTestWhenToIf("idea/testData/codeInsight/codeTransformations/branched/ifWhen/whenToIf/whenWithMultiConditions.kt"); } + @TestMetadata("whenWithMultipleConditionTypes.kt") + public void testWhenWithMultipleConditionTypes() throws Exception { + doTestWhenToIf("idea/testData/codeInsight/codeTransformations/branched/ifWhen/whenToIf/whenWithMultipleConditionTypes.kt"); + } + @TestMetadata("whenWithNegativePatterns.kt") public void testWhenWithNegativePatterns() throws Exception { doTestWhenToIf("idea/testData/codeInsight/codeTransformations/branched/ifWhen/whenToIf/whenWithNegativePatterns.kt"); @@ -429,6 +439,11 @@ public class CodeTransformationsTestGenerated extends AbstractCodeTransformation doTestIntroduceWhenSubject("idea/testData/codeInsight/codeTransformations/branched/when/introduceSubject/whenWithEqualityTests.kt"); } + @TestMetadata("whenWithMultipleConditionTypes.kt") + public void testWhenWithMultipleConditionTypes() throws Exception { + doTestIntroduceWhenSubject("idea/testData/codeInsight/codeTransformations/branched/when/introduceSubject/whenWithMultipleConditionTypes.kt"); + } + @TestMetadata("whenWithNegativePatterns.kt") public void testWhenWithNegativePatterns() throws Exception { doTestIntroduceWhenSubject("idea/testData/codeInsight/codeTransformations/branched/when/introduceSubject/whenWithNegativePatterns.kt"); @@ -482,6 +497,11 @@ public class CodeTransformationsTestGenerated extends AbstractCodeTransformation doTestEliminateWhenSubject("idea/testData/codeInsight/codeTransformations/branched/when/eliminateSubject/whenWithEqualityTests.kt"); } + @TestMetadata("whenWithMultipleConditionTypes.kt") + public void testWhenWithMultipleConditionTypes() throws Exception { + doTestEliminateWhenSubject("idea/testData/codeInsight/codeTransformations/branched/when/eliminateSubject/whenWithMultipleConditionTypes.kt"); + } + @TestMetadata("whenWithNegativePatterns.kt") public void testWhenWithNegativePatterns() throws Exception { doTestEliminateWhenSubject("idea/testData/codeInsight/codeTransformations/branched/when/eliminateSubject/whenWithNegativePatterns.kt");