diff options
| author | Noopur Gupta | 2019-05-14 13:13:34 +0000 |
|---|---|---|
| committer | Noopur Gupta | 2019-05-14 13:13:34 +0000 |
| commit | 1c1f0a2d35513d79532a8d03f58f693a3b855608 (patch) | |
| tree | 81292b980cb69cf5a2c601306da5973de99607aa | |
| parent | ef6b732ee8f3f3920f99576ea4b9909d2098a45c (diff) | |
| download | eclipse.jdt.ui-1c1f0a2d35513d79532a8d03f58f693a3b855608.tar.gz eclipse.jdt.ui-1c1f0a2d35513d79532a8d03f58f693a3b855608.tar.xz eclipse.jdt.ui-1c1f0a2d35513d79532a8d03f58f693a3b855608.zip | |
Tests - Bug 545256: [12][quick fix][switch expression] 'Add defaultI20190515-1800I20190515-0205
case'
Change-Id: I331545fef5c605c5cc7b51e3eae919b419d178cd
| -rw-r--r-- | org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest12.java | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest12.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest12.java index 59fd0154ba..cef86c2224 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest12.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest12.java @@ -417,4 +417,123 @@ public class QuickFixTest12 extends QuickFixTest { assertEqualStringsIgnoreOrder(new String[] { preview }, new String[] { expected });
}
+ public void testAddDefaultCaseSwitchExpression1() throws Exception {
+ fJProject1= JavaProjectHelper.createJavaProject("TestProject1", "bin");
+ fJProject1.setRawClasspath(Java12ProjectTestSetup.getDefaultClasspath(), null);
+ JavaProjectHelper.set12CompilerOptions(fJProject1, true);
+ fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
+
+ StringBuffer buf= new StringBuffer();
+ buf.append("module test {\n");
+ buf.append("}\n");
+ IPackageFragment def= fSourceFolder.createPackageFragment("", false, null);
+ def.createCompilationUnit("module-info.java", buf.toString(), false, null);
+
+ IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null);
+ buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("public class Cls {\n");
+ buf.append(" public static void bar3(int input) {\n");
+ buf.append(" int num = switch (input) {\n");
+ buf.append(" case 60, 600 -> 6;\n");
+ buf.append(" case 70 -> 7;\n");
+ buf.append(" case 80 -> 8;\n");
+ buf.append(" case 90, 900 -> {\n");
+ buf.append(" break 9;\n");
+ buf.append(" }\n");
+ buf.append(" };\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack.createCompilationUnit("Cls.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= getASTRoot(cu);
+ ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, 1);
+ assertNumberOfProposals(proposals, 1);
+ assertCorrectLabels(proposals);
+
+ CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0);
+ String preview= getPreviewContent(proposal);
+
+ buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("public class Cls {\n");
+ buf.append(" public static void bar3(int input) {\n");
+ buf.append(" int num = switch (input) {\n");
+ buf.append(" case 60, 600 -> 6;\n");
+ buf.append(" case 70 -> 7;\n");
+ buf.append(" case 80 -> 8;\n");
+ buf.append(" case 90, 900 -> {\n");
+ buf.append(" break 9;\n");
+ buf.append(" }\n");
+ buf.append(" default -> throw new IllegalArgumentException(\"Unexpected value: \" + input);\n");
+ buf.append(" };\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ String expected= buf.toString();
+
+ assertEqualStringsIgnoreOrder(new String[] { preview }, new String[] { expected });
+ }
+
+ public void testAddDefaultCaseSwitchExpression2() throws Exception {
+ fJProject1= JavaProjectHelper.createJavaProject("TestProject1", "bin");
+ fJProject1.setRawClasspath(Java12ProjectTestSetup.getDefaultClasspath(), null);
+ JavaProjectHelper.set12CompilerOptions(fJProject1, true);
+ fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src");
+
+ StringBuffer buf= new StringBuffer();
+ buf.append("module test {\n");
+ buf.append("}\n");
+ IPackageFragment def= fSourceFolder.createPackageFragment("", false, null);
+ def.createCompilationUnit("module-info.java", buf.toString(), false, null);
+
+ IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null);
+ buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("public class Cls {\n");
+ buf.append(" public static void bar4(int input) {\n");
+ buf.append(" int num = switch (input) {\n");
+ buf.append(" case 60, 600:\n");
+ buf.append(" break 6;\n");
+ buf.append(" case 70:\n");
+ buf.append(" break 7;\n");
+ buf.append(" case 80:\n");
+ buf.append(" break 8;\n");
+ buf.append(" case 90, 900:\n");
+ buf.append(" break 9;\n");
+ buf.append(" };\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack.createCompilationUnit("Cls.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= getASTRoot(cu);
+ ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, 1);
+ assertNumberOfProposals(proposals, 1);
+ assertCorrectLabels(proposals);
+
+ CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0);
+ String preview= getPreviewContent(proposal);
+
+ buf= new StringBuffer();
+ buf.append("package test;\n");
+ buf.append("public class Cls {\n");
+ buf.append(" public static void bar4(int input) {\n");
+ buf.append(" int num = switch (input) {\n");
+ buf.append(" case 60, 600:\n");
+ buf.append(" break 6;\n");
+ buf.append(" case 70:\n");
+ buf.append(" break 7;\n");
+ buf.append(" case 80:\n");
+ buf.append(" break 8;\n");
+ buf.append(" case 90, 900:\n");
+ buf.append(" break 9;\n");
+ buf.append(" default :\n");
+ buf.append(" throw new IllegalArgumentException(\n");
+ buf.append(" \"Unexpected value: \" + input);\n");
+ buf.append(" };\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ String expected= buf.toString();
+
+ assertEqualStringsIgnoreOrder(new String[] { preview }, new String[] { expected });
+ }
}
|
