blob: 3e5893277485eddf32fa40f2aa7835825e8a2d65 [file] [log] [blame]
40 columns |
>>> Separate statements in cases.
switch (foo) {case 0:a();b();c();}
<<<
switch (foo) {
case 0:
a();
b();
c();
}
>>> Allow a blank line between case statements.
switch (foo) {case 0:
a();
b();
c();
}
<<<
switch (foo) {
case 0:
a();
b();
c();
}
>>> Collapse other newlines in cases.
switch (foo) {case 0:
a();
b();
c();
}
<<<
switch (foo) {
case 0:
a();
b();
c();
}
>>> Remove newlines between empty cases.
switch (foo) {
case 1:
case 2:
case 3:
body;
case 4:
default:
body;
}
<<<
switch (foo) {
case 1:
case 2:
case 3:
body;
case 4:
default:
body;
}
>>> Separate statements in the default clause.
switch (foo) {default:a();b();c();}
<<<
switch (foo) {
default:
a();
b();
c();
}
>>> Allow a blank line between statements in the default clause.
switch (foo) {default:
a();
b();
c();
}
<<<
switch (foo) {
default:
a();
b();
c();
}
>>> Collapse other newlines in the default clause.
switch (foo) {default:
a();
b();
c();
}
<<<
switch (foo) {
default:
a();
b();
c();
}
>>> Put cases on their own lines.
switch (foo) {case 0:case 1:case 2:body();}
<<<
switch (foo) {
case 0:
case 1:
case 2:
body();
}
>>> Allow a blank line between non-empty cases.
switch (foo) {case 0: body();
case 1:
case 2:body();
}
<<<
switch (foo) {
case 0:
body();
case 1:
case 2:
body();
}
>>> Collapse other newlines between cases.
switch (foo) {
case 0:
case 1:
case 2:
body();
}
<<<
switch (foo) {
case 0:
case 1:
case 2:
body();
}
>>> Single-statement cases split even when they could fit on one line.
switch (obj) {
case 1: a();
case 2: b();
default: c();
}
<<<
switch (obj) {
case 1:
a();
case 2:
b();
default:
c();
}
>>> Multiple statement cases split even when they could fit on one line.
switch (obj) {
case 1: a(); b();
case 2: c(); d();
default: d(); e();
}
<<<
switch (obj) {
case 1:
a();
b();
case 2:
c();
d();
default:
d();
e();
}
>>> Indentation.
switch (fruit) {
case "apple":
print("delish");
break;
case "fig":
print("bleh");
break;
}
<<<
switch (fruit) {
case "apple":
print("delish");
break;
case "fig":
print("bleh");
break;
}
>>> Labeled cases.
switch (fruit) {
case "apple":
print("delish");
break;
label:case "fig":
print("bleh");
break;
other:default:
break;
}
<<<
switch (fruit) {
case "apple":
print("delish");
break;
label:
case "fig":
print("bleh");
break;
other:
default:
break;
}
>>> Don't split at parentheses.
switch ("a long string that must wrap") {
case 0:
return "ok";
}
<<<
switch ("a long string that must wrap") {
case 0:
return "ok";
}
>>> Split a delimited expression in the switch expression.
switch ([veryLongElement,veryLongElement]) {
case 0:
return "ok";
}
<<<
switch ([
veryLongElement,
veryLongElement,
]) {
case 0:
return "ok";
}
>>> Block split in pattern.
switch (obj) {
case [veryLongElement,veryLongElement,veryLongElement,]: body;
}
<<<
switch (obj) {
case [
veryLongElement,
veryLongElement,
veryLongElement,
]:
body;
}
>>> Infix `||` pattern as outermost.
### Switch expressions have some special formatting rules so here we just
### validate that those rules don't inadvertently affect switch statements too.
switch (obj) {
case oneConstant || twoConstant || threeConstant: body;
}
<<<
switch (obj) {
case oneConstant ||
twoConstant ||
threeConstant:
body;
}