mbien commented on code in PR #9484:
URL: https://github.com/apache/netbeans/pull/9484#discussion_r3522732421


##########
java/java.source.base/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java:
##########
@@ -3416,6 +3416,80 @@ public void testSwitchCaseAllPatternsWithReturnValue() 
throws Exception {
         reformat(doc, content, golden);
     }
 
+    public void testSwitchCaseExprWrapping() throws Exception {
+        try {
+            SourceVersion.valueOf("RELEASE_17"); //NOI18N
+        } catch (IllegalArgumentException ex) {
+            //OK, no RELEASE_17, skip test
+            return;
+        }
+        testFile = new File(getWorkDir(), "Test.java");
+        TestUtilities.copyStringToFile(testFile, "");
+        FileObject testSourceFO = FileUtil.toFileObject(testFile);
+        DataObject testSourceDO = DataObject.find(testSourceFO);
+        EditorCookie ec = (EditorCookie) 
testSourceDO.getCookie(EditorCookie.class);
+        final Document doc = ec.openDocument();
+        doc.putProperty(Language.class, JavaTokenId.language());
+        Preferences preferences = 
MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class);
+
+        String content
+                = """
+                package p;
+
+                public class Test {
+
+                    String choose(String str) {
+                        return switch (str) {
+                            Object str = "pattern matching switch";
+                            IntStream iso = IntStream.of(1, 2);
+                            case null -> "case with null formatting";

Review Comment:
   Not sure if intended but this code is not valid (several compiler errors, 
matching error and also syntax (e.g `(String s)` or `case default`)).
   
   We had issues before where tests using invalid code started failing for the 
wildest reasons (example: compiler suddenly thought it was a compact-java file 
and generated an additional wrapping class). Unless this is intended for the 
purpose of the test it might be better to use valid code.
   
   also would be good to add a case which uses curly braces+yield, e.g
   ```java
       String choose(String str) {
           IntStream iso = IntStream.of(1, 2);
           return switch (str) {
               case null -> "case with null formatting";
               case String string when (string.length() == iso.filter(i -> i / 
2 == 0).count() || string.length() == 0) ->
                   "case with pattern matching + condition + lambda expression 
formatting";
               case String s when s.length() == 1 -> "case with pattern 
matching + condition formatting";
               case String s when s.length() == 2 -> {
                   yield "case with pattern matching + condition formatting";
               }
               default -> "default formatting";
           };
       }
   ```



##########
java/java.source.base/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java:
##########


Review Comment:
   should we add the missing `t`? Because I once used to think the java 
format[t]er had no tests since i couldn't find it :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to