zig fmt: Allow one-line for loops

This commit is contained in:
hryx
2019-03-31 21:31:36 -07:00
committed by Andrew Kelley
parent d645500883
commit c76d51de97
2 changed files with 49 additions and 18 deletions

View File

@@ -1737,6 +1737,10 @@ test "zig fmt: switch" {
test "zig fmt: while" {
try testCanonical(
\\test "while" {
\\ while (10 < 1) unreachable;
\\
\\ while (10 < 1) unreachable else unreachable;
\\
\\ while (10 < 1) {
\\ unreachable;
\\ }
@@ -1803,10 +1807,27 @@ test "zig fmt: while" {
test "zig fmt: for" {
try testCanonical(
\\test "for" {
\\ for (a) continue;
\\
\\ for (a)
\\ continue;
\\
\\ for (a) {
\\ continue;
\\ }
\\
\\ for (a) |v| {
\\ continue;
\\ }
\\
\\ for (a) |v| continue;
\\
\\ for (a) |v| continue else return;
\\
\\ for (a) |v| {
\\ continue;
\\ } else return;
\\
\\ for (a) |v|
\\ continue;
\\
@@ -1820,6 +1841,17 @@ test "zig fmt: for" {
\\ for (a) |v, i|
\\ continue;
\\
\\ for (a) |b| switch (b) {
\\ c => {},
\\ d => {},
\\ };
\\
\\ for (a) |b|
\\ switch (b) {
\\ c => {},
\\ d => {},
\\ };
\\
\\ const res = for (a) |v, i| {
\\ break v;
\\ } else {