1 //===- unittest/Format/FormatTestJava.cpp - Formatting tests for Java -----===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "FormatTestBase.h"
11 #define DEBUG_TYPE "format-test"
18 class FormatTestJava
: public test::FormatTestBase
{
20 FormatStyle
getDefaultStyle() const override
{
21 return getGoogleStyle(FormatStyle::LK_Java
);
24 static FormatStyle
getStyleWithColumns(unsigned ColumnLimit
) {
25 FormatStyle Style
= getGoogleStyle(FormatStyle::LK_Java
);
26 Style
.ColumnLimit
= ColumnLimit
;
31 TEST_F(FormatTestJava
, NoAlternativeOperatorNames
) {
32 verifyFormat("someObject.and();");
35 TEST_F(FormatTestJava
, UnderstandsCasts
) {
36 verifyFormat("a[b >> 1] = (byte) (c() << 4);");
39 TEST_F(FormatTestJava
, FormatsInstanceOfLikeOperators
) {
40 FormatStyle Style
= getStyleWithColumns(50);
41 verifyFormat("return aaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
42 " instanceof bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;",
44 Style
.BreakBeforeBinaryOperators
= FormatStyle::BOS_None
;
45 verifyFormat("return aaaaaaaaaaaaaaaaaaaaaaaaaaaaa instanceof\n"
46 " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;",
48 verifyFormat("return aaaaaaaaaaaaaaaaaaa instanceof bbbbbbbbbbbbbbbbbbbbbbb\n"
49 " && ccccccccccccccccccc instanceof dddddddddddddddddddddd;");
52 TEST_F(FormatTestJava
, Chromium
) {
53 verifyFormat("class SomeClass {\n"
59 " while (true) f();\n"
64 getChromiumStyle(FormatStyle::LK_Java
));
67 TEST_F(FormatTestJava
, QualifiedNames
) {
68 verifyFormat("public some.package.Type someFunction( // comment\n"
69 " int parameter) {}");
72 TEST_F(FormatTestJava
, ClassKeyword
) {
73 verifyFormat("SomeClass.class.getName();");
74 verifyFormat("Class c = SomeClass.class;");
77 TEST_F(FormatTestJava
, ClassDeclarations
) {
78 verifyFormat("public class SomeClass {\n"
82 verifyFormat("public class A {\n"
90 verifyFormat("public class A extends B.C {}");
92 verifyFormat("abstract class SomeClass\n"
93 " extends SomeOtherClass implements SomeInterface {}",
94 getStyleWithColumns(60));
95 verifyFormat("abstract class SomeClass extends SomeOtherClass\n"
96 " implements SomeInterfaceeeeeeeeeeeee {}",
97 getStyleWithColumns(60));
98 verifyFormat("abstract class SomeClass\n"
99 " extends SomeOtherClass\n"
100 " implements SomeInterface {}",
101 getStyleWithColumns(40));
102 verifyFormat("abstract class SomeClass\n"
103 " extends SomeOtherClass\n"
104 " implements SomeInterface,\n"
105 " AnotherInterface {}",
106 getStyleWithColumns(40));
107 verifyFormat("abstract class SomeClass\n"
108 " implements SomeInterface, AnotherInterface {}",
109 getStyleWithColumns(60));
110 verifyFormat("@SomeAnnotation()\n"
111 "abstract class aaaaaaaaaaaa\n"
112 " extends bbbbbbbbbbbbbbb implements cccccccccccc {}",
113 getStyleWithColumns(76));
114 verifyFormat("@SomeAnnotation()\n"
115 "abstract class aaaaaaaaa<a>\n"
116 " extends bbbbbbbbbbbb<b> implements cccccccccccc {}",
117 getStyleWithColumns(76));
118 verifyFormat("interface SomeInterface<A> extends Foo, Bar {\n"
119 " void doStuff(int theStuff);\n"
120 " void doMoreStuff(int moreStuff);\n"
122 verifyFormat("public interface SomeInterface {\n"
123 " void doStuff(int theStuff);\n"
124 " void doMoreStuff(int moreStuff);\n"
125 " default void doStuffWithDefault() {}\n"
127 verifyFormat("@interface SomeInterface {\n"
128 " void doStuff(int theStuff);\n"
129 " void doMoreStuff(int moreStuff);\n"
131 verifyFormat("public @interface SomeInterface {\n"
132 " void doStuff(int theStuff);\n"
133 " void doMoreStuff(int moreStuff);\n"
135 verifyFormat("class A {\n"
136 " public @interface SomeInterface {\n"
138 " void doMoreStuff(int moreStuff);\n"
141 verifyFormat("class A {\n"
142 " public @interface SomeInterface {}\n"
146 TEST_F(FormatTestJava
, AnonymousClasses
) {
147 verifyFormat("return new A() {\n"
148 " public String toString() {\n"
149 " return \"NotReallyA\";\n"
152 verifyFormat("A a = new A() {\n"
153 " public String toString() {\n"
154 " return \"NotReallyA\";\n"
159 TEST_F(FormatTestJava
, EnumDeclarations
) {
160 verifyFormat("enum SomeThing { ABC, CDE }");
161 verifyFormat("enum SomeThing {\n"
165 verifyFormat("public class SomeClass {\n"
166 " enum SomeThing { ABC, CDE }\n"
169 verifyFormat("public class SomeClass implements SomeInterface {\n"
170 " enum SomeThing { ABC, CDE }\n"
173 verifyFormat("enum SomeThing {\n"
178 verifyFormat("enum SomeThing {\n"
180 verifyFormat("enum SomeThing {\n"
181 " ABC(1, \"ABC\"),\n"
182 " CDE(2, \"CDE\");\n"
183 " Something(int i, String s) {}\n"
185 verifyFormat("enum SomeThing {\n"
186 " ABC(new int[] {1, 2}),\n"
187 " CDE(new int[] {2, 3});\n"
188 " Something(int[] i) {}\n"
190 verifyFormat("public enum SomeThing {\n"
192 " public String toString() {\n"
198 " public String toString() {\n"
202 " public void f() {}\n"
204 verifyFormat("private enum SomeEnum implements Foo<?, B> {\n"
207 " public String toString() {\n"
213 " public String toString() {\n"
218 verifyFormat("public enum VeryLongEnum {\n"
219 " ENUM_WITH_MANY_PARAMETERS(\n"
220 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", \"bbbbbbbbbbbbbbbb\", "
221 "\"cccccccccccccccccccccccc\"),\n"
222 " SECOND_ENUM(\"a\", \"b\", \"c\");\n"
223 " private VeryLongEnum(String a, String b, String c) {}\n"
227 TEST_F(FormatTestJava
, ArrayInitializers
) {
228 verifyFormat("new int[] {1, 2, 3, 4};");
229 verifyFormat("new int[] {\n"
236 FormatStyle Style
= getStyleWithColumns(65);
237 Style
.Cpp11BracedListStyle
= false;
239 "expected = new int[] { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,\n"
240 " 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 };",
244 TEST_F(FormatTestJava
, ThrowsDeclarations
) {
245 verifyFormat("public void doSooooooooooooooooooooooooooomething()\n"
246 " throws LooooooooooooooooooooooooooooongException {}");
247 verifyFormat("public void doSooooooooooooooooooooooooooomething()\n"
248 " throws LoooooooooongException, LooooooooooongException {}");
251 TEST_F(FormatTestJava
, Annotations
) {
252 verifyFormat("@Override\n"
253 "public String toString() {}");
254 verifyFormat("@Override\n"
256 "public String getNameIfPresent() {}");
257 verifyFormat("@Override // comment\n"
259 "public String getNameIfPresent() {}");
260 verifyFormat("@java.lang.Override // comment\n"
262 "public String getNameIfPresent() {}");
264 verifyFormat("@SuppressWarnings(value = \"unchecked\")\n"
265 "public void doSomething() {}");
266 verifyFormat("@SuppressWarnings(value = \"unchecked\")\n"
267 "@Author(name = \"abc\")\n"
268 "public void doSomething() {}");
270 verifyFormat("DoSomething(new A() {\n"
272 " public String toString() {}\n"
275 verifyFormat("void SomeFunction(@Nullable String something) {}");
276 verifyFormat("void SomeFunction(@org.llvm.Nullable String something) {}");
278 verifyFormat("@Partial @Mock DataLoader loader;");
279 verifyFormat("@Partial\n"
281 "DataLoader loader;",
282 getChromiumStyle(FormatStyle::LK_Java
));
283 verifyFormat("@SuppressWarnings(value = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\")\n"
284 "public static int iiiiiiiiiiiiiiiiiiiiiiii;");
286 verifyFormat("@SomeAnnotation(\"With some really looooooooooooooong text\")\n"
287 "private static final long something = 0L;");
288 verifyFormat("@org.llvm.Qualified(\"With some really looooooooooong text\")\n"
289 "private static final long something = 0L;");
290 verifyFormat("@Mock\n"
291 "DataLoader loooooooooooooooooooooooader =\n"
292 " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;",
293 getStyleWithColumns(60));
294 verifyFormat("@org.llvm.QualifiedMock\n"
295 "DataLoader loooooooooooooooooooooooader =\n"
296 " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;",
297 getStyleWithColumns(60));
298 verifyFormat("@Test(a)\n"
299 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
300 " aaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaa);");
301 verifyFormat("@SomeAnnotation(\n"
302 " aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa)\n"
304 getStyleWithColumns(50));
305 verifyFormat("@Test\n"
306 "ReturnType doSomething(\n"
307 " String aaaaaaaaaaaaa, String bbbbbbbbbbbbbbb) {}",
308 getStyleWithColumns(60));
310 " boolean someFunction(\n"
311 " @Param(aaaaaaaaaaaaaaaa) String aaaaa,\n"
312 " String bbbbbbbbbbbbbbb) {}\n"
314 getStyleWithColumns(60));
315 verifyFormat("@Annotation(\"Some\"\n"
317 "List<Integer> list;");
321 "@Feature({\"Android-TabSwitcher\"})\n"
322 "@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})\n"
323 "@Features.EnableFeatures({FEATURE})\n"
324 "public void test(@Foo.bar(\"baz\") @Quux.Qoob int theFirstParaaaaam,\n"
325 " @Foo.bar(\"baz\") @Quux.Qoob int theSecondParaaaaaaaaaaaaaaaam) {}");
328 TEST_F(FormatTestJava
, Generics
) {
329 verifyFormat("Iterable<?> a;");
330 verifyFormat("Iterable<?> a;");
331 verifyFormat("Iterable<? extends SomeObject> a;");
333 verifyFormat("A.<B>doSomething();");
334 verifyFormat("A.<B<C>>doSomething();");
335 verifyFormat("A.<B<C<D>>>doSomething();");
336 verifyFormat("A.<B<C<D<E>>>>doSomething();");
338 verifyFormat("OrderedPair<String, List<Box<Integer>>> p = null;");
340 verifyFormat("@Override\n"
341 "public Map<String, ?> getAll() {}");
343 verifyFormat("public <R> ArrayList<R> get() {}");
344 verifyFormat("protected <R> ArrayList<R> get() {}");
345 verifyFormat("private <R> ArrayList<R> get() {}");
346 verifyFormat("public static <R> ArrayList<R> get() {}");
347 verifyFormat("public static native <R> ArrayList<R> get();");
348 verifyFormat("public final <X> Foo foo() {}");
349 verifyFormat("public abstract <X> Foo foo();");
350 verifyFormat("<T extends B> T getInstance(Class<T> type);");
351 verifyFormat("Function<F, ? extends T> function;");
353 verifyFormat("private Foo<X, Y>[] foos;");
354 verifyFormat("Foo<X, Y>[] foos = this.foos;");
355 verifyFormat("return (a instanceof List<?>)\n"
356 " ? aaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaa)\n"
357 " : aaaaaaaaaaaaaaaaaaaaaaa;",
358 getStyleWithColumns(60));
361 "SomeLoooooooooooooooooooooongType name =\n"
362 " SomeType.foo(someArgument)\n"
364 " .aaaaaaaaaaaaaaaaaaa()\n"
365 " .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();");
368 TEST_F(FormatTestJava
, StringConcatenation
) {
369 verifyFormat("String someString = \"abc\"\n"
373 TEST_F(FormatTestJava
, TryCatchFinally
) {
374 verifyFormat("try {\n"
376 "} catch (SomeException e) {\n"
377 " HandleException(e);\n"
379 verifyFormat("try {\n"
384 verifyFormat("try {\n"
386 "} catch (SomeException e) {\n"
387 " HandleException(e);\n"
392 verifyFormat("try {\n"
394 "} catch (SomeException | OtherException e) {\n"
395 " HandleException(e);\n"
399 TEST_F(FormatTestJava
, TryWithResources
) {
400 verifyFormat("try (SomeResource rs = someFunction()) {\n"
403 verifyFormat("try (SomeResource rs = someFunction()) {\n"
405 "} catch (SomeException e) {\n"
406 " HandleException(e);\n"
410 TEST_F(FormatTestJava
, SynchronizedKeyword
) {
411 verifyFormat("synchronized (mData) {\n"
415 FormatStyle Style
= getLLVMStyle(FormatStyle::LK_Java
);
416 Style
.BreakBeforeBraces
= FormatStyle::BS_Custom
;
418 Style
.BraceWrapping
.AfterControlStatement
= FormatStyle::BWACS_Always
;
419 Style
.BraceWrapping
.AfterFunction
= false;
420 verifyFormat("synchronized (mData)\n"
426 Style
.BraceWrapping
.AfterControlStatement
= FormatStyle::BWACS_Never
;
427 Style
.BraceWrapping
.AfterFunction
= true;
428 verifyFormat("synchronized (mData) {\n"
434 TEST_F(FormatTestJava
, AssertKeyword
) {
435 verifyFormat("assert a && b;");
436 verifyFormat("assert (a && b);");
439 TEST_F(FormatTestJava
, PackageDeclarations
) {
440 verifyFormat("package some.really.loooooooooooooooooooooong.package;",
441 getStyleWithColumns(50));
444 TEST_F(FormatTestJava
, ImportDeclarations
) {
445 verifyFormat("import some.really.loooooooooooooooooooooong.imported.Class;",
446 getStyleWithColumns(50));
447 verifyFormat("import static some.really.looooooooooooooooong.imported.Class;",
448 getStyleWithColumns(50));
451 TEST_F(FormatTestJava
, MethodDeclarations
) {
452 verifyFormat("void methodName(Object arg1,\n"
453 " Object arg2, Object arg3) {}",
454 getStyleWithColumns(40));
455 verifyFormat("void methodName(\n"
456 " Object arg1, Object arg2) {}",
457 getStyleWithColumns(40));
460 TEST_F(FormatTestJava
, MethodReference
) {
461 EXPECT_EQ("private void foo() {\n"
462 " f(this::methodReference);\n"
463 " f(C.super::methodReference);\n"
464 " Consumer<String> c = System.out::println;\n"
465 " Iface<Integer> mRef = Ty::<Integer>meth;\n"
467 format("private void foo() {\n"
468 " f(this ::methodReference);\n"
469 " f(C.super ::methodReference);\n"
470 " Consumer<String> c = System.out ::println;\n"
471 " Iface<Integer> mRef = Ty :: <Integer> meth;\n"
475 TEST_F(FormatTestJava
, CppKeywords
) {
476 verifyFormat("public void union(Type a, Type b);");
477 verifyFormat("public void struct(Object o);");
478 verifyFormat("public void delete(Object o);");
479 verifyFormat("return operator && (aa);");
482 TEST_F(FormatTestJava
, NeverAlignAfterReturn
) {
483 verifyFormat("return aaaaaaaaaaaaaaaaaaa\n"
484 " && bbbbbbbbbbbbbbbbbbb\n"
485 " && ccccccccccccccccccc;",
486 getStyleWithColumns(40));
487 verifyFormat("return (result == null)\n"
488 " ? aaaaaaaaaaaaaaaaa\n"
489 " : bbbbbbbbbbbbbbbbb;",
490 getStyleWithColumns(40));
491 verifyFormat("return aaaaaaaaaaaaaaaaaaa()\n"
492 " .bbbbbbbbbbbbbbbbbbb()\n"
493 " .ccccccccccccccccccc();",
494 getStyleWithColumns(40));
495 verifyFormat("return aaaaaaaaaaaaaaaaaaa()\n"
496 " .bbbbbbbbbbbbbbbbbbb(\n"
497 " ccccccccccccccc)\n"
498 " .ccccccccccccccccccc();",
499 getStyleWithColumns(40));
502 TEST_F(FormatTestJava
, FormatsInnerBlocks
) {
503 verifyFormat("someObject.someFunction(new Runnable() {\n"
505 " public void run() {\n"
506 " System.out.println(42);\n"
508 "}, someOtherParameter);");
509 verifyFormat("someFunction(new Runnable() {\n"
510 " public void run() {\n"
511 " System.out.println(42);\n"
514 verifyFormat("someObject.someFunction(\n"
515 " new Runnable() {\n"
517 " public void run() {\n"
518 " System.out.println(42);\n"
521 " new Runnable() {\n"
523 " public void run() {\n"
524 " System.out.println(43);\n"
527 " someOtherParameter);");
530 TEST_F(FormatTestJava
, FormatsLambdas
) {
531 verifyFormat("(aaaaaaaaaa, bbbbbbbbbb) -> aaaaaaaaaa + bbbbbbbbbb;");
532 verifyFormat("(aaaaaaaaaa, bbbbbbbbbb)\n"
533 " -> aaaaaaaaaa + bbbbbbbbbb;",
534 getStyleWithColumns(40));
535 verifyFormat("Runnable someLambda = () -> DoSomething();");
536 verifyFormat("Runnable someLambda = () -> {\n"
540 verifyFormat("Runnable someLambda =\n"
541 " (int aaaaa) -> DoSomething(aaaaa);",
542 getStyleWithColumns(40));
545 TEST_F(FormatTestJava
, BreaksStringLiterals
) {
546 verifyFormat("x = \"some text \"\n"
548 "x = \"some text other\";", getStyleWithColumns(18));
551 TEST_F(FormatTestJava
, AlignsBlockComments
) {
553 " * Really multi-line\n"
558 " * Really multi-line\n"
564 TEST_F(FormatTestJava
, AlignDeclarations
) {
565 FormatStyle Style
= getLLVMStyle(FormatStyle::LK_Java
);
566 Style
.AlignConsecutiveDeclarations
.Enabled
= true;
567 verifyFormat("private final String[] args;\n"
568 "private final A_ParserHelper parserHelper;\n"
569 "private final int numOfCmdArgs;\n"
570 "private int numOfCmdArgs;\n"
571 "private String[] args;",
575 TEST_F(FormatTestJava
, KeepsDelimitersOnOwnLineInJavaDocComments
) {
577 " * javadoc line 1\n"
578 " * javadoc line 2\n"
580 format("/** javadoc line 1\n"
581 " * javadoc line 2 */"));
584 TEST_F(FormatTestJava
, RetainsLogicalShifts
) {
585 verifyFormat("void f() {\n"
589 verifyFormat("void f() {\n"
595 TEST_F(FormatTestJava
, ShortFunctions
) {
596 FormatStyle Style
= getLLVMStyle(FormatStyle::LK_Java
);
597 Style
.AllowShortFunctionsOnASingleLine
= FormatStyle::SFS_Inline
;
598 verifyFormat("enum Enum {\n"
601 " void f() { return; }\n"
606 TEST_F(FormatTestJava
, ConfigurableSpacesInSquareBrackets
) {
607 FormatStyle Spaces
= getLLVMStyle(FormatStyle::LK_Java
);
609 verifyFormat("Object[] arguments", Spaces
);
610 verifyFormat("final Class<?>[] types = new Class<?>[numElements];", Spaces
);
611 verifyFormat("types[i] = arguments[i].getClass();", Spaces
);
613 Spaces
.SpacesInSquareBrackets
= true;
615 verifyFormat("Object[ ] arguments", Spaces
);
616 verifyFormat("final Class<?>[ ] types = new Class<?>[ numElements ];",
618 verifyFormat("types[ i ] = arguments[ i ].getClass();", Spaces
);
621 TEST_F(FormatTestJava
, SwitchExpression
) {
622 auto Style
= getLLVMStyle(FormatStyle::LK_Java
);
623 EXPECT_TRUE(Style
.AllowShortCaseExpressionOnASingleLine
);
625 verifyFormat("foo(switch (day) {\n"
626 " case THURSDAY, SATURDAY -> 8;\n"
627 " case WEDNESDAY -> 9;\n"
632 constexpr StringRef Code1
{"i = switch (day) {\n"
633 " case THURSDAY, SATURDAY -> 8;\n"
634 " case WEDNESDAY -> 9;\n"
637 verifyFormat(Code1
, Style
);
639 Style
.IndentCaseLabels
= true;
640 verifyFormat(Code1
, Style
);
642 constexpr StringRef Code2
{"i = switch (day) {\n"
643 " case THURSDAY, SATURDAY -> {\n"
647 " case WEDNESDAY -> {\n"
655 verifyFormat(Code2
, Style
);
657 Style
.IndentCaseLabels
= false;
658 verifyFormat(Code2
, Style
);
660 constexpr StringRef Code3
{"switch (day) {\n"
661 "case THURSDAY, SATURDAY -> i = 8;\n"
662 "case WEDNESDAY -> i = 9;\n"
663 "default -> i = 0;\n"
665 verifyFormat(Code3
, Style
);
667 Style
.IndentCaseLabels
= true;
668 verifyFormat("switch (day) {\n"
669 " case THURSDAY, SATURDAY -> i = 8;\n"
670 " case WEDNESDAY -> i = 9;\n"
671 " default -> i = 0;\n"
676 TEST_F(FormatTestJava
, ShortCaseExpression
) {
677 auto Style
= getLLVMStyle(FormatStyle::LK_Java
);
679 verifyFormat("i = switch (a) {\n"
681 " case 2 -> // comment\n"
686 " case 4 -> 4; // comment\n"
691 verifyNoChange("i = switch (a) {\n"
697 " case 3 -> 3; /* comment */\n"
698 " case 4 -> /* comment */ 4;\n"
699 " case 5 -> x + /* comment */ 1;\n"
701 " 0; // comment line 1\n"
702 " // comment line 2\n"
706 Style
.ColumnLimit
= 18;
707 verifyFormat("i = switch (a) {\n"
710 " default -> 9999;\n"
714 Style
.ColumnLimit
= 80;
715 Style
.AllowShortCaseExpressionOnASingleLine
= false;
716 Style
.IndentCaseLabels
= true;
717 verifyFormat("i = switch (n) {\n"
718 " default /*comments*/ ->\n"
725 Style
.AllowShortCaseExpressionOnASingleLine
= true;
726 Style
.BreakBeforeBraces
= FormatStyle::BS_Custom
;
727 Style
.BraceWrapping
.AfterCaseLabel
= true;
728 Style
.BraceWrapping
.AfterControlStatement
= FormatStyle::BWACS_Always
;
729 verifyFormat("i = switch (n)\n"
743 TEST_F(FormatTestJava
, AlignCaseArrows
) {
744 auto Style
= getLLVMStyle(FormatStyle::LK_Java
);
745 Style
.AlignConsecutiveShortCaseStatements
.Enabled
= true;
747 verifyFormat("foo(switch (day) {\n"
748 " case THURSDAY, SATURDAY -> 8;\n"
749 " case WEDNESDAY -> 9;\n"
754 verifyFormat("i = switch (day) {\n"
755 " case THURSDAY, SATURDAY -> 8;\n"
756 " case WEDNESDAY -> 9;\n"
761 verifyFormat("switch (day) {\n"
762 "case THURSDAY, SATURDAY -> i = 8;\n"
763 "case WEDNESDAY -> i = 9;\n"
764 "default -> i = 0;\n"
768 Style
.AlignConsecutiveShortCaseStatements
.AlignCaseArrows
= true;
770 verifyFormat("foo(switch (day) {\n"
771 " case THURSDAY, SATURDAY -> 8;\n"
772 " case WEDNESDAY -> 9;\n"
777 verifyFormat("i = switch (day) {\n"
778 " case THURSDAY, SATURDAY -> 8;\n"
779 " case WEDNESDAY -> 9;\n"
784 verifyFormat("switch (day) {\n"
785 "case THURSDAY, SATURDAY -> i = 8;\n"
786 "case WEDNESDAY -> i = 9;\n"
787 "default -> i = 0;\n"
794 } // namespace format