authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-09 23:07:29-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-09 23:07:29-07:00
log58db3d27753709074fba7c88923754dd1c1a0ed9
treecda1b59e5d785e987b5a8fbb69e29c8973a8b838
parentfa5fcdd7343b8e759971ea14adead830b1f7c616

zig fmt: re-enable now-passing test cases


3 files changed, 925 insertions(+), 938 deletions(-)

lib/std/zig/ast.zig+7-7
......@@ -899,12 +899,12 @@ pub const Tree = struct {
899899 // require recursion due to the optional comma followed by rbrace.
900900 // TODO follow the pattern set by StructInitDotTwoComma which will allow
901901 // lastToken to work for all of these.
902 .ArrayInit => unreachable,
903 .ArrayInitOne => unreachable,
904 .ArrayInitDot => unreachable,
905 .StructInit => unreachable,
906 .StructInitOne => unreachable,
907 .StructInitDot => unreachable,
902 .ArrayInit => unreachable, // TODO
903 .ArrayInitOne => unreachable, // TODO
904 .ArrayInitDot => unreachable, // TODO
905 .StructInit => unreachable, // TODO
906 .StructInitOne => unreachable, // TODO
907 .StructInitDot => unreachable, // TODO
908908
909909 .TaggedUnionEnumTag => unreachable, // TODO
910910 .TaggedUnionEnumTagComma => unreachable, // TODO
......@@ -2065,7 +2065,7 @@ pub const Error = union(enum) {
20652065 pub const ExpectedVarDeclOrFn = SingleTokenError("Expected variable declaration or function, found '{s}'");
20662066 pub const ExpectedVarDecl = SingleTokenError("Expected variable declaration, found '{s}'");
20672067 pub const ExpectedFn = SingleTokenError("Expected function, found '{s}'");
2068 pub const ExpectedReturnType = SingleTokenError("Expected 'var' or return type expression, found '{s}'");
2068 pub const ExpectedReturnType = SingleTokenError("Expected return type expression, found '{s}'");
20692069 pub const ExpectedAggregateKw = SingleTokenError("Expected '" ++ Token.Tag.Keyword_struct.symbol() ++ "', '" ++ Token.Tag.Keyword_union.symbol() ++ "', '" ++ Token.Tag.Keyword_enum.symbol() ++ "', or '" ++ Token.Tag.Keyword_opaque.symbol() ++ "', found '{s}'");
20702070 pub const ExpectedEqOrSemi = SingleTokenError("Expected '=' or ';', found '{s}'");
20712071 pub const ExpectedSemiOrLBrace = SingleTokenError("Expected ';' or '{{', found '{s}'");
lib/std/zig/parser_test.zig+913-930
......@@ -757,14 +757,14 @@ test "zig fmt: tagged union with enum values" {
757757// \\
758758// );
759759//}
760//
761//test "zig fmt: enum literal" {
762// try testCanonical(
763// \\const x = .hi;
764// \\
765// );
766//}
767//
760
761test "zig fmt: enum literal" {
762 try testCanonical(
763 \\const x = .hi;
764 \\
765 );
766}
767
768768//test "zig fmt: enum literal inside array literal" {
769769// try testCanonical(
770770// \\test "enums in arrays" {
......@@ -779,14 +779,14 @@ test "zig fmt: tagged union with enum values" {
779779// \\
780780// );
781781//}
782//
783//test "zig fmt: character literal larger than u8" {
784// try testCanonical(
785// \\const x = '\u{01f4a9}';
786// \\
787// );
788//}
789//
782
783test "zig fmt: character literal larger than u8" {
784 try testCanonical(
785 \\const x = '\u{01f4a9}';
786 \\
787 );
788}
789
790790//test "zig fmt: infix operator and then multiline string literal" {
791791// try testCanonical(
792792// \\const x = "" ++
......@@ -813,22 +813,22 @@ test "zig fmt: tagged union with enum values" {
813813// \\
814814// );
815815//}
816//
817//test "zig fmt: threadlocal" {
818// try testCanonical(
819// \\threadlocal var x: i32 = 1234;
820// \\
821// );
822//}
823//
824//test "zig fmt: linksection" {
825// try testCanonical(
826// \\export var aoeu: u64 linksection(".text.derp") = 1234;
827// \\export fn _start() linksection(".text.boot") callconv(.Naked) noreturn {}
828// \\
829// );
830//}
831//
816
817test "zig fmt: threadlocal" {
818 try testCanonical(
819 \\threadlocal var x: i32 = 1234;
820 \\
821 );
822}
823
824test "zig fmt: linksection" {
825 try testCanonical(
826 \\export var aoeu: u64 linksection(".text.derp") = 1234;
827 \\export fn _start() linksection(".text.boot") callconv(.Naked) noreturn {}
828 \\
829 );
830}
831
832832//test "zig fmt: correctly move doc comments on struct fields" {
833833// try testTransform(
834834// \\pub const section_64 = extern struct {
......@@ -895,22 +895,22 @@ test "zig fmt: tagged union with enum values" {
895895// \\
896896// );
897897//}
898//
899//test "zig fmt: aligned struct field" {
900// try testCanonical(
901// \\pub const S = struct {
902// \\ f: i32 align(32),
903// \\};
904// \\
905// );
906// try testCanonical(
907// \\pub const S = struct {
908// \\ f: i32 align(32) = 1,
909// \\};
910// \\
911// );
912//}
913//
898
899test "zig fmt: aligned struct field" {
900 try testCanonical(
901 \\pub const S = struct {
902 \\ f: i32 align(32),
903 \\};
904 \\
905 );
906 try testCanonical(
907 \\pub const S = struct {
908 \\ f: i32 align(32) = 1,
909 \\};
910 \\
911 );
912}
913
914914//test "zig fmt: comment to disable/enable zig fmt first" {
915915// try testCanonical(
916916// \\// Test trailing comma syntax
......@@ -1040,32 +1040,32 @@ test "zig fmt: tagged union with enum values" {
10401040// \\
10411041// );
10421042//}
1043//
1044//test "zig fmt: spaces around slice operator" {
1045// try testCanonical(
1046// \\var a = b[c..d];
1047// \\var a = b[c..d :0];
1048// \\var a = b[c + 1 .. d];
1049// \\var a = b[c + 1 ..];
1050// \\var a = b[c .. d + 1];
1051// \\var a = b[c .. d + 1 :0];
1052// \\var a = b[c.a..d.e];
1053// \\var a = b[c.a..d.e :0];
1054// \\
1055// );
1056//}
1057//
1058//test "zig fmt: async call in if condition" {
1059// try testCanonical(
1060// \\comptime {
1061// \\ if (async b()) {
1062// \\ a();
1063// \\ }
1064// \\}
1065// \\
1066// );
1067//}
1068//
1043
1044test "zig fmt: spaces around slice operator" {
1045 try testCanonical(
1046 \\var a = b[c..d];
1047 \\var a = b[c..d :0];
1048 \\var a = b[c + 1 .. d];
1049 \\var a = b[c + 1 ..];
1050 \\var a = b[c .. d + 1];
1051 \\var a = b[c .. d + 1 :0];
1052 \\var a = b[c.a..d.e];
1053 \\var a = b[c.a..d.e :0];
1054 \\
1055 );
1056}
1057
1058test "zig fmt: async call in if condition" {
1059 try testCanonical(
1060 \\comptime {
1061 \\ if (async b()) {
1062 \\ a();
1063 \\ }
1064 \\}
1065 \\
1066 );
1067}
1068
10691069//test "zig fmt: 2nd arg multiline string" {
10701070// try testCanonical(
10711071// \\comptime {
......@@ -1300,64 +1300,64 @@ test "zig fmt: tagged union with enum values" {
13001300// \\
13011301// );
13021302//}
1303//
1304//test "zig fmt: respect line breaks in if-else" {
1305// try testCanonical(
1306// \\comptime {
1307// \\ return if (cond) a else b;
1308// \\ return if (cond)
1309// \\ a
1310// \\ else
1311// \\ b;
1312// \\ return if (cond)
1313// \\ a
1314// \\ else if (cond)
1315// \\ b
1316// \\ else
1317// \\ c;
1318// \\}
1319// \\
1320// );
1321//}
1322//
1323//test "zig fmt: respect line breaks after infix operators" {
1324// try testCanonical(
1325// \\comptime {
1326// \\ self.crc =
1327// \\ lookup_tables[0][p[7]] ^
1328// \\ lookup_tables[1][p[6]] ^
1329// \\ lookup_tables[2][p[5]] ^
1330// \\ lookup_tables[3][p[4]] ^
1331// \\ lookup_tables[4][@truncate(u8, self.crc >> 24)] ^
1332// \\ lookup_tables[5][@truncate(u8, self.crc >> 16)] ^
1333// \\ lookup_tables[6][@truncate(u8, self.crc >> 8)] ^
1334// \\ lookup_tables[7][@truncate(u8, self.crc >> 0)];
1335// \\}
1336// \\
1337// );
1338//}
1339//
1340//test "zig fmt: fn decl with trailing comma" {
1341// try testTransform(
1342// \\fn foo(a: i32, b: i32,) void {}
1343// ,
1344// \\fn foo(
1345// \\ a: i32,
1346// \\ b: i32,
1347// \\) void {}
1348// \\
1349// );
1350//}
1351//
1352//test "zig fmt: enum decl with no trailing comma" {
1353// try testTransform(
1354// \\const StrLitKind = enum {Normal, C};
1355// ,
1356// \\const StrLitKind = enum { Normal, C };
1357// \\
1358// );
1359//}
1360//
1303
1304test "zig fmt: respect line breaks in if-else" {
1305 try testCanonical(
1306 \\comptime {
1307 \\ return if (cond) a else b;
1308 \\ return if (cond)
1309 \\ a
1310 \\ else
1311 \\ b;
1312 \\ return if (cond)
1313 \\ a
1314 \\ else if (cond)
1315 \\ b
1316 \\ else
1317 \\ c;
1318 \\}
1319 \\
1320 );
1321}
1322
1323test "zig fmt: respect line breaks after infix operators" {
1324 try testCanonical(
1325 \\comptime {
1326 \\ self.crc =
1327 \\ lookup_tables[0][p[7]] ^
1328 \\ lookup_tables[1][p[6]] ^
1329 \\ lookup_tables[2][p[5]] ^
1330 \\ lookup_tables[3][p[4]] ^
1331 \\ lookup_tables[4][@truncate(u8, self.crc >> 24)] ^
1332 \\ lookup_tables[5][@truncate(u8, self.crc >> 16)] ^
1333 \\ lookup_tables[6][@truncate(u8, self.crc >> 8)] ^
1334 \\ lookup_tables[7][@truncate(u8, self.crc >> 0)];
1335 \\}
1336 \\
1337 );
1338}
1339
1340test "zig fmt: fn decl with trailing comma" {
1341 try testTransform(
1342 \\fn foo(a: i32, b: i32,) void {}
1343 ,
1344 \\fn foo(
1345 \\ a: i32,
1346 \\ b: i32,
1347 \\) void {}
1348 \\
1349 );
1350}
1351
1352test "zig fmt: enum decl with no trailing comma" {
1353 try testTransform(
1354 \\const StrLitKind = enum {Normal, C};
1355 ,
1356 \\const StrLitKind = enum { Normal, C };
1357 \\
1358 );
1359}
1360
13611361//test "zig fmt: switch comment before prong" {
13621362// try testCanonical(
13631363// \\comptime {
......@@ -1369,22 +1369,25 @@ test "zig fmt: tagged union with enum values" {
13691369// \\
13701370// );
13711371//}
1372//
1373//test "zig fmt: struct literal no trailing comma" {
1374// try testTransform(
1375// \\const a = foo{ .x = 1, .y = 2 };
1376// \\const a = foo{ .x = 1,
1377// \\ .y = 2 };
1378// ,
1379// \\const a = foo{ .x = 1, .y = 2 };
1380// \\const a = foo{
1381// \\ .x = 1,
1382// \\ .y = 2,
1383// \\};
1384// \\
1385// );
1386//}
1387//
1372
1373test "zig fmt: struct literal no trailing comma" {
1374 try testTransform(
1375 \\const a = foo{ .x = 1, .y = 2 };
1376 \\const a = foo{ .x = 1,
1377 \\ .y = 2 };
1378 \\const a = foo{ .x = 1,
1379 \\ .y = 2, };
1380 ,
1381 \\const a = foo{ .x = 1, .y = 2 };
1382 \\const a = foo{ .x = 1, .y = 2 };
1383 \\const a = foo{
1384 \\ .x = 1,
1385 \\ .y = 2,
1386 \\};
1387 \\
1388 );
1389}
1390
13881391//test "zig fmt: struct literal containing a multiline expression" {
13891392// try testTransform(
13901393// \\const a = A{ .x = if (f1()) 10 else 20 };
......@@ -1564,39 +1567,39 @@ test "zig fmt: tagged union with enum values" {
15641567// \\
15651568// );
15661569//}
1567//
1568//test "zig fmt: trailing comma on fn call" {
1569// try testCanonical(
1570// \\comptime {
1571// \\ var module = try Module.create(
1572// \\ allocator,
1573// \\ zig_lib_dir,
1574// \\ full_cache_dir,
1575// \\ );
1576// \\}
1577// \\
1578// );
1579//}
1580//
1581//test "zig fmt: multi line arguments without last comma" {
1582// try testTransform(
1583// \\pub fn foo(
1584// \\ a: usize,
1585// \\ b: usize,
1586// \\ c: usize,
1587// \\ d: usize
1588// \\) usize {
1589// \\ return a + b + c + d;
1590// \\}
1591// \\
1592// ,
1593// \\pub fn foo(a: usize, b: usize, c: usize, d: usize) usize {
1594// \\ return a + b + c + d;
1595// \\}
1596// \\
1597// );
1598//}
1599//
1570
1571test "zig fmt: trailing comma on fn call" {
1572 try testCanonical(
1573 \\comptime {
1574 \\ var module = try Module.create(
1575 \\ allocator,
1576 \\ zig_lib_dir,
1577 \\ full_cache_dir,
1578 \\ );
1579 \\}
1580 \\
1581 );
1582}
1583
1584test "zig fmt: multi line arguments without last comma" {
1585 try testTransform(
1586 \\pub fn foo(
1587 \\ a: usize,
1588 \\ b: usize,
1589 \\ c: usize,
1590 \\ d: usize
1591 \\) usize {
1592 \\ return a + b + c + d;
1593 \\}
1594 \\
1595 ,
1596 \\pub fn foo(a: usize, b: usize, c: usize, d: usize) usize {
1597 \\ return a + b + c + d;
1598 \\}
1599 \\
1600 );
1601}
1602
16001603//test "zig fmt: empty block with only comment" {
16011604// try testCanonical(
16021605// \\comptime {
......@@ -1616,19 +1619,19 @@ test "zig fmt: tagged union with enum values" {
16161619// \\
16171620// );
16181621//}
1619//
1620//test "zig fmt: extra newlines at the end" {
1621// try testTransform(
1622// \\const a = b;
1623// \\
1624// \\
1625// \\
1626// ,
1627// \\const a = b;
1628// \\
1629// );
1630//}
1631//
1622
1623test "zig fmt: extra newlines at the end" {
1624 try testTransform(
1625 \\const a = b;
1626 \\
1627 \\
1628 \\
1629 ,
1630 \\const a = b;
1631 \\
1632 );
1633}
1634
16321635//test "zig fmt: simple asm" {
16331636// try testTransform(
16341637// \\comptime {
......@@ -1704,15 +1707,15 @@ test "zig fmt: switch cases trailing comma" {
17041707 );
17051708}
17061709
1707//test "zig fmt: slice align" {
1708// try testCanonical(
1709// \\const A = struct {
1710// \\ items: []align(A) T,
1711// \\};
1712// \\
1713// );
1714//}
1715//
1710test "zig fmt: slice align" {
1711 try testCanonical(
1712 \\const A = struct {
1713 \\ items: []align(A) T,
1714 \\};
1715 \\
1716 );
1717}
1718
17161719//test "zig fmt: add trailing comma to array literal" {
17171720// try testTransform(
17181721// \\comptime {
......@@ -1756,29 +1759,29 @@ test "zig fmt: switch cases trailing comma" {
17561759// \\
17571760// );
17581761//}
1759//
1760//test "zig fmt: float literal with exponent" {
1761// try testCanonical(
1762// \\test "bit field alignment" {
1763// \\ assert(@TypeOf(&blah.b) == *align(1:3:6) const u3);
1764// \\}
1765// \\
1766// );
1767//}
1768//
1769//test "zig fmt: float literal with exponent" {
1770// try testCanonical(
1771// \\test "aoeu" {
1772// \\ switch (state) {
1773// \\ TermState.Start => switch (c) {
1774// \\ '\x1b' => state = TermState.Escape,
1775// \\ else => try out.writeByte(c),
1776// \\ },
1777// \\ }
1778// \\}
1779// \\
1780// );
1781//}
1762
1763test "zig fmt: bit field alignment" {
1764 try testCanonical(
1765 \\test {
1766 \\ assert(@TypeOf(&blah.b) == *align(1:3:6) const u3);
1767 \\}
1768 \\
1769 );
1770}
1771
1772test "zig fmt: nested switch" {
1773 try testCanonical(
1774 \\test {
1775 \\ switch (state) {
1776 \\ TermState.Start => switch (c) {
1777 \\ '\x1b' => state = TermState.Escape,
1778 \\ else => try out.writeByte(c),
1779 \\ },
1780 \\ }
1781 \\}
1782 \\
1783 );
1784}
17821785
17831786test "zig fmt: float literal with exponent" {
17841787 try testCanonical(
......@@ -1788,34 +1791,34 @@ test "zig fmt: float literal with exponent" {
17881791 );
17891792}
17901793
1791//test "zig fmt: if-else end of comptime" {
1792// try testCanonical(
1793// \\comptime {
1794// \\ if (a) {
1795// \\ b();
1796// \\ } else {
1797// \\ b();
1798// \\ }
1799// \\}
1800// \\
1801// );
1802//}
1803//
1804//test "zig fmt: nested blocks" {
1805// try testCanonical(
1806// \\comptime {
1807// \\ {
1808// \\ {
1809// \\ {
1810// \\ a();
1811// \\ }
1812// \\ }
1813// \\ }
1814// \\}
1815// \\
1816// );
1817//}
1818//
1794test "zig fmt: if-else end of comptime" {
1795 try testCanonical(
1796 \\comptime {
1797 \\ if (a) {
1798 \\ b();
1799 \\ } else {
1800 \\ b();
1801 \\ }
1802 \\}
1803 \\
1804 );
1805}
1806
1807test "zig fmt: nested blocks" {
1808 try testCanonical(
1809 \\comptime {
1810 \\ {
1811 \\ {
1812 \\ {
1813 \\ a();
1814 \\ }
1815 \\ }
1816 \\ }
1817 \\}
1818 \\
1819 );
1820}
1821
18191822//test "zig fmt: block with same line comment after end brace" {
18201823// try testCanonical(
18211824// \\comptime {
......@@ -1837,17 +1840,17 @@ test "zig fmt: float literal with exponent" {
18371840// \\
18381841// );
18391842//}
1840//
1841//test "zig fmt: statements with empty line between" {
1842// try testCanonical(
1843// \\comptime {
1844// \\ a = b;
1845// \\
1846// \\ a = b;
1847// \\}
1848// \\
1849// );
1850//}
1843
1844test "zig fmt: statements with empty line between" {
1845 try testCanonical(
1846 \\comptime {
1847 \\ a = b;
1848 \\
1849 \\ a = b;
1850 \\}
1851 \\
1852 );
1853}
18511854
18521855test "zig fmt: ptr deref operator and unwrap optional operator" {
18531856 try testCanonical(
......@@ -2119,18 +2122,18 @@ test "zig fmt: error set declaration" {
21192122// \\
21202123// );
21212124//}
2122//
2123//test "zig fmt: union(enum(u32)) with assigned enum values" {
2124// try testCanonical(
2125// \\const MultipleChoice = union(enum(u32)) {
2126// \\ A = 20,
2127// \\ B = 40,
2128// \\ C = 60,
2129// \\ D = 1000,
2130// \\};
2131// \\
2132// );
2133//}
2125
2126test "zig fmt: union(enum(u32)) with assigned enum values" {
2127 try testCanonical(
2128 \\const MultipleChoice = union(enum(u32)) {
2129 \\ A = 20,
2130 \\ B = 40,
2131 \\ C = 60,
2132 \\ D = 1000,
2133 \\};
2134 \\
2135 );
2136}
21342137
21352138test "zig fmt: resume from suspend block" {
21362139 try testCanonical(
......@@ -2270,15 +2273,15 @@ test "zig fmt: resume from suspend block" {
22702273// \\
22712274// );
22722275//}
2273//
2274//test "zig fmt: imports" {
2275// try testCanonical(
2276// \\const std = @import("std");
2277// \\const std = @import();
2278// \\
2279// );
2280//}
2281//
2276
2277test "zig fmt: imports" {
2278 try testCanonical(
2279 \\const std = @import("std");
2280 \\const std = @import();
2281 \\
2282 );
2283}
2284
22822285//test "zig fmt: global declarations" {
22832286// try testCanonical(
22842287// \\const a = b;
......@@ -2300,21 +2303,21 @@ test "zig fmt: resume from suspend block" {
23002303// \\
23012304// );
23022305//}
2303//
2304//test "zig fmt: extern declaration" {
2305// try testCanonical(
2306// \\extern var foo: c_int;
2307// \\
2308// );
2309//}
2310//
2311//test "zig fmt: alignment" {
2312// try testCanonical(
2313// \\var foo: c_int align(1);
2314// \\
2315// );
2316//}
2317//
2306
2307test "zig fmt: extern declaration" {
2308 try testCanonical(
2309 \\extern var foo: c_int;
2310 \\
2311 );
2312}
2313
2314test "zig fmt: alignment" {
2315 try testCanonical(
2316 \\var foo: c_int align(1);
2317 \\
2318 );
2319}
2320
23182321//test "zig fmt: C main" {
23192322// try testCanonical(
23202323// \\fn main(argc: c_int, argv: **u8) c_int {
......@@ -2358,128 +2361,128 @@ test "zig fmt: resume from suspend block" {
23582361// \\
23592362// );
23602363//}
2361//
2362//test "zig fmt: test declaration" {
2363// try testCanonical(
2364// \\test "test name" {
2365// \\ const a = 1;
2366// \\ var b = 1;
2367// \\}
2368// \\
2369// );
2370//}
2371//
2372//test "zig fmt: infix operators" {
2373// try testCanonical(
2374// \\test "infix operators" {
2375// \\ var i = undefined;
2376// \\ i = 2;
2377// \\ i *= 2;
2378// \\ i |= 2;
2379// \\ i ^= 2;
2380// \\ i <<= 2;
2381// \\ i >>= 2;
2382// \\ i &= 2;
2383// \\ i *= 2;
2384// \\ i *%= 2;
2385// \\ i -= 2;
2386// \\ i -%= 2;
2387// \\ i += 2;
2388// \\ i +%= 2;
2389// \\ i /= 2;
2390// \\ i %= 2;
2391// \\ _ = i == i;
2392// \\ _ = i != i;
2393// \\ _ = i != i;
2394// \\ _ = i.i;
2395// \\ _ = i || i;
2396// \\ _ = i!i;
2397// \\ _ = i ** i;
2398// \\ _ = i ++ i;
2399// \\ _ = i orelse i;
2400// \\ _ = i % i;
2401// \\ _ = i / i;
2402// \\ _ = i *% i;
2403// \\ _ = i * i;
2404// \\ _ = i -% i;
2405// \\ _ = i - i;
2406// \\ _ = i +% i;
2407// \\ _ = i + i;
2408// \\ _ = i << i;
2409// \\ _ = i >> i;
2410// \\ _ = i & i;
2411// \\ _ = i ^ i;
2412// \\ _ = i | i;
2413// \\ _ = i >= i;
2414// \\ _ = i <= i;
2415// \\ _ = i > i;
2416// \\ _ = i < i;
2417// \\ _ = i and i;
2418// \\ _ = i or i;
2419// \\}
2420// \\
2421// );
2422//}
2423//
2424//test "zig fmt: precedence" {
2425// try testCanonical(
2426// \\test "precedence" {
2427// \\ a!b();
2428// \\ (a!b)();
2429// \\ !a!b;
2430// \\ !(a!b);
2431// \\ !a{};
2432// \\ !(a{});
2433// \\ a + b{};
2434// \\ (a + b){};
2435// \\ a << b + c;
2436// \\ (a << b) + c;
2437// \\ a & b << c;
2438// \\ (a & b) << c;
2439// \\ a ^ b & c;
2440// \\ (a ^ b) & c;
2441// \\ a | b ^ c;
2442// \\ (a | b) ^ c;
2443// \\ a == b | c;
2444// \\ (a == b) | c;
2445// \\ a and b == c;
2446// \\ (a and b) == c;
2447// \\ a or b and c;
2448// \\ (a or b) and c;
2449// \\ (a or b) and c;
2450// \\}
2451// \\
2452// );
2453//}
2454//
2455//test "zig fmt: prefix operators" {
2456// try testCanonical(
2457// \\test "prefix operators" {
2458// \\ try return --%~!&0;
2459// \\}
2460// \\
2461// );
2462//}
2463//
2464//test "zig fmt: call expression" {
2465// try testCanonical(
2466// \\test "test calls" {
2467// \\ a();
2468// \\ a(1);
2469// \\ a(1, 2);
2470// \\ a(1, 2) + a(1, 2);
2471// \\}
2472// \\
2473// );
2474//}
2475//
2364
2365test "zig fmt: test declaration" {
2366 try testCanonical(
2367 \\test "test name" {
2368 \\ const a = 1;
2369 \\ var b = 1;
2370 \\}
2371 \\
2372 );
2373}
2374
2375test "zig fmt: infix operators" {
2376 try testCanonical(
2377 \\test {
2378 \\ var i = undefined;
2379 \\ i = 2;
2380 \\ i *= 2;
2381 \\ i |= 2;
2382 \\ i ^= 2;
2383 \\ i <<= 2;
2384 \\ i >>= 2;
2385 \\ i &= 2;
2386 \\ i *= 2;
2387 \\ i *%= 2;
2388 \\ i -= 2;
2389 \\ i -%= 2;
2390 \\ i += 2;
2391 \\ i +%= 2;
2392 \\ i /= 2;
2393 \\ i %= 2;
2394 \\ _ = i == i;
2395 \\ _ = i != i;
2396 \\ _ = i != i;
2397 \\ _ = i.i;
2398 \\ _ = i || i;
2399 \\ _ = i!i;
2400 \\ _ = i ** i;
2401 \\ _ = i ++ i;
2402 \\ _ = i orelse i;
2403 \\ _ = i % i;
2404 \\ _ = i / i;
2405 \\ _ = i *% i;
2406 \\ _ = i * i;
2407 \\ _ = i -% i;
2408 \\ _ = i - i;
2409 \\ _ = i +% i;
2410 \\ _ = i + i;
2411 \\ _ = i << i;
2412 \\ _ = i >> i;
2413 \\ _ = i & i;
2414 \\ _ = i ^ i;
2415 \\ _ = i | i;
2416 \\ _ = i >= i;
2417 \\ _ = i <= i;
2418 \\ _ = i > i;
2419 \\ _ = i < i;
2420 \\ _ = i and i;
2421 \\ _ = i or i;
2422 \\}
2423 \\
2424 );
2425}
2426
2427test "zig fmt: precedence" {
2428 try testCanonical(
2429 \\test "precedence" {
2430 \\ a!b();
2431 \\ (a!b)();
2432 \\ !a!b;
2433 \\ !(a!b);
2434 \\ !a{};
2435 \\ !(a{});
2436 \\ a + b{};
2437 \\ (a + b){};
2438 \\ a << b + c;
2439 \\ (a << b) + c;
2440 \\ a & b << c;
2441 \\ (a & b) << c;
2442 \\ a ^ b & c;
2443 \\ (a ^ b) & c;
2444 \\ a | b ^ c;
2445 \\ (a | b) ^ c;
2446 \\ a == b | c;
2447 \\ (a == b) | c;
2448 \\ a and b == c;
2449 \\ (a and b) == c;
2450 \\ a or b and c;
2451 \\ (a or b) and c;
2452 \\ (a or b) and c;
2453 \\}
2454 \\
2455 );
2456}
2457
2458test "zig fmt: prefix operators" {
2459 try testCanonical(
2460 \\test "prefix operators" {
2461 \\ try return --%~!&0;
2462 \\}
2463 \\
2464 );
2465}
2466
2467test "zig fmt: call expression" {
2468 try testCanonical(
2469 \\test "test calls" {
2470 \\ a();
2471 \\ a(1);
2472 \\ a(1, 2);
2473 \\ a(1, 2) + a(1, 2);
2474 \\}
2475 \\
2476 );
2477}
2478
24762479//test "zig fmt: anytype type" {
24772480// try testCanonical(
24782481// \\fn print(args: anytype) anytype {}
24792482// \\
24802483// );
24812484//}
2482//
2485
24832486//test "zig fmt: functions" {
24842487// try testCanonical(
24852488// \\extern fn puts(s: *const u8) c_int;
......@@ -2500,7 +2503,7 @@ test "zig fmt: resume from suspend block" {
25002503// \\
25012504// );
25022505//}
2503//
2506
25042507//test "zig fmt: multiline string" {
25052508// try testCanonical(
25062509// \\test "" {
......@@ -2518,145 +2521,145 @@ test "zig fmt: resume from suspend block" {
25182521// \\
25192522// );
25202523//}
2521//
2522//test "zig fmt: values" {
2523// try testCanonical(
2524// \\test "values" {
2525// \\ 1;
2526// \\ 1.0;
2527// \\ "string";
2528// \\ 'c';
2529// \\ true;
2530// \\ false;
2531// \\ null;
2532// \\ undefined;
2533// \\ anyerror;
2534// \\ this;
2535// \\ unreachable;
2536// \\}
2537// \\
2538// );
2539//}
2540//
2541//test "zig fmt: indexing" {
2542// try testCanonical(
2543// \\test "test index" {
2544// \\ a[0];
2545// \\ a[0 + 5];
2546// \\ a[0..];
2547// \\ a[0..5];
2548// \\ a[a[0]];
2549// \\ a[a[0..]];
2550// \\ a[a[0..5]];
2551// \\ a[a[0]..];
2552// \\ a[a[0..5]..];
2553// \\ a[a[0]..a[0]];
2554// \\ a[a[0..5]..a[0]];
2555// \\ a[a[0..5]..a[0..5]];
2556// \\}
2557// \\
2558// );
2559//}
2560//
2561//test "zig fmt: struct declaration" {
2562// try testCanonical(
2563// \\const S = struct {
2564// \\ const Self = @This();
2565// \\ f1: u8,
2566// \\ f3: u8,
2567// \\
2568// \\ f2: u8,
2569// \\
2570// \\ fn method(self: *Self) Self {
2571// \\ return self.*;
2572// \\ }
2573// \\};
2574// \\
2575// \\const Ps = packed struct {
2576// \\ a: u8,
2577// \\ b: u8,
2578// \\
2579// \\ c: u8,
2580// \\};
2581// \\
2582// \\const Es = extern struct {
2583// \\ a: u8,
2584// \\ b: u8,
2585// \\
2586// \\ c: u8,
2587// \\};
2588// \\
2589// );
2590//}
2591//
2592//test "zig fmt: enum declaration" {
2593// try testCanonical(
2594// \\const E = enum {
2595// \\ Ok,
2596// \\ SomethingElse = 0,
2597// \\};
2598// \\
2599// \\const E2 = enum(u8) {
2600// \\ Ok,
2601// \\ SomethingElse = 255,
2602// \\ SomethingThird,
2603// \\};
2604// \\
2605// \\const Ee = extern enum {
2606// \\ Ok,
2607// \\ SomethingElse,
2608// \\ SomethingThird,
2609// \\};
2610// \\
2611// \\const Ep = packed enum {
2612// \\ Ok,
2613// \\ SomethingElse,
2614// \\ SomethingThird,
2615// \\};
2616// \\
2617// );
2618//}
2619//
2620//test "zig fmt: union declaration" {
2621// try testCanonical(
2622// \\const U = union {
2623// \\ Int: u8,
2624// \\ Float: f32,
2625// \\ None,
2626// \\ Bool: bool,
2627// \\};
2628// \\
2629// \\const Ue = union(enum) {
2630// \\ Int: u8,
2631// \\ Float: f32,
2632// \\ None,
2633// \\ Bool: bool,
2634// \\};
2635// \\
2636// \\const E = enum {
2637// \\ Int,
2638// \\ Float,
2639// \\ None,
2640// \\ Bool,
2641// \\};
2642// \\
2643// \\const Ue2 = union(E) {
2644// \\ Int: u8,
2645// \\ Float: f32,
2646// \\ None,
2647// \\ Bool: bool,
2648// \\};
2649// \\
2650// \\const Eu = extern union {
2651// \\ Int: u8,
2652// \\ Float: f32,
2653// \\ None,
2654// \\ Bool: bool,
2655// \\};
2656// \\
2657// );
2658//}
2659//
2524
2525test "zig fmt: values" {
2526 try testCanonical(
2527 \\test "values" {
2528 \\ 1;
2529 \\ 1.0;
2530 \\ "string";
2531 \\ 'c';
2532 \\ true;
2533 \\ false;
2534 \\ null;
2535 \\ undefined;
2536 \\ anyerror;
2537 \\ this;
2538 \\ unreachable;
2539 \\}
2540 \\
2541 );
2542}
2543
2544test "zig fmt: indexing" {
2545 try testCanonical(
2546 \\test "test index" {
2547 \\ a[0];
2548 \\ a[0 + 5];
2549 \\ a[0..];
2550 \\ a[0..5];
2551 \\ a[a[0]];
2552 \\ a[a[0..]];
2553 \\ a[a[0..5]];
2554 \\ a[a[0]..];
2555 \\ a[a[0..5]..];
2556 \\ a[a[0]..a[0]];
2557 \\ a[a[0..5]..a[0]];
2558 \\ a[a[0..5]..a[0..5]];
2559 \\}
2560 \\
2561 );
2562}
2563
2564test "zig fmt: struct declaration" {
2565 try testCanonical(
2566 \\const S = struct {
2567 \\ const Self = @This();
2568 \\ f1: u8,
2569 \\ f3: u8,
2570 \\
2571 \\ f2: u8,
2572 \\
2573 \\ fn method(self: *Self) Self {
2574 \\ return self.*;
2575 \\ }
2576 \\};
2577 \\
2578 \\const Ps = packed struct {
2579 \\ a: u8,
2580 \\ b: u8,
2581 \\
2582 \\ c: u8,
2583 \\};
2584 \\
2585 \\const Es = extern struct {
2586 \\ a: u8,
2587 \\ b: u8,
2588 \\
2589 \\ c: u8,
2590 \\};
2591 \\
2592 );
2593}
2594
2595test "zig fmt: enum declaration" {
2596 try testCanonical(
2597 \\const E = enum {
2598 \\ Ok,
2599 \\ SomethingElse = 0,
2600 \\};
2601 \\
2602 \\const E2 = enum(u8) {
2603 \\ Ok,
2604 \\ SomethingElse = 255,
2605 \\ SomethingThird,
2606 \\};
2607 \\
2608 \\const Ee = extern enum {
2609 \\ Ok,
2610 \\ SomethingElse,
2611 \\ SomethingThird,
2612 \\};
2613 \\
2614 \\const Ep = packed enum {
2615 \\ Ok,
2616 \\ SomethingElse,
2617 \\ SomethingThird,
2618 \\};
2619 \\
2620 );
2621}
2622
2623test "zig fmt: union declaration" {
2624 try testCanonical(
2625 \\const U = union {
2626 \\ Int: u8,
2627 \\ Float: f32,
2628 \\ None,
2629 \\ Bool: bool,
2630 \\};
2631 \\
2632 \\const Ue = union(enum) {
2633 \\ Int: u8,
2634 \\ Float: f32,
2635 \\ None,
2636 \\ Bool: bool,
2637 \\};
2638 \\
2639 \\const E = enum {
2640 \\ Int,
2641 \\ Float,
2642 \\ None,
2643 \\ Bool,
2644 \\};
2645 \\
2646 \\const Ue2 = union(E) {
2647 \\ Int: u8,
2648 \\ Float: f32,
2649 \\ None,
2650 \\ Bool: bool,
2651 \\};
2652 \\
2653 \\const Eu = extern union {
2654 \\ Int: u8,
2655 \\ Float: f32,
2656 \\ None,
2657 \\ Bool: bool,
2658 \\};
2659 \\
2660 );
2661}
2662
26602663//test "zig fmt: arrays" {
26612664// try testCanonical(
26622665// \\test "test array" {
......@@ -2674,7 +2677,7 @@ test "zig fmt: resume from suspend block" {
26742677// \\
26752678// );
26762679//}
2677//
2680
26782681//test "zig fmt: container initializers" {
26792682// try testCanonical(
26802683// \\const a0 = []u8{};
......@@ -2912,140 +2915,140 @@ test "zig fmt: for" {
29122915 );
29132916}
29142917
2915//test "zig fmt: if" {
2916// try testCanonical(
2917// \\test "if" {
2918// \\ if (10 < 0) {
2919// \\ unreachable;
2920// \\ }
2921// \\
2922// \\ if (10 < 0) unreachable;
2923// \\
2924// \\ if (10 < 0) {
2925// \\ unreachable;
2926// \\ } else {
2927// \\ const a = 20;
2928// \\ }
2929// \\
2930// \\ if (10 < 0) {
2931// \\ unreachable;
2932// \\ } else if (5 < 0) {
2933// \\ unreachable;
2934// \\ } else {
2935// \\ const a = 20;
2936// \\ }
2937// \\
2938// \\ const is_world_broken = if (10 < 0) true else false;
2939// \\ const some_number = 1 + if (10 < 0) 2 else 3;
2940// \\
2941// \\ const a: ?u8 = 10;
2942// \\ const b: ?u8 = null;
2943// \\ if (a) |v| {
2944// \\ const some = v;
2945// \\ } else if (b) |*v| {
2946// \\ unreachable;
2947// \\ } else {
2948// \\ const some = 10;
2949// \\ }
2950// \\
2951// \\ const non_null_a = if (a) |v| v else 0;
2952// \\
2953// \\ const a_err: anyerror!u8 = 0;
2954// \\ if (a_err) |v| {
2955// \\ const p = v;
2956// \\ } else |err| {
2957// \\ unreachable;
2958// \\ }
2959// \\}
2960// \\
2961// );
2962//}
2963//
2964//test "zig fmt: defer" {
2965// try testCanonical(
2966// \\test "defer" {
2967// \\ var i: usize = 0;
2968// \\ defer i = 1;
2969// \\ defer {
2970// \\ i += 2;
2971// \\ i *= i;
2972// \\ }
2973// \\
2974// \\ errdefer i += 3;
2975// \\ errdefer {
2976// \\ i += 2;
2977// \\ i /= i;
2978// \\ }
2979// \\}
2980// \\
2981// );
2982//}
2983//
2984//test "zig fmt: comptime" {
2985// try testCanonical(
2986// \\fn a() u8 {
2987// \\ return 5;
2988// \\}
2989// \\
2990// \\fn b(comptime i: u8) u8 {
2991// \\ return i;
2992// \\}
2993// \\
2994// \\const av = comptime a();
2995// \\const av2 = comptime blk: {
2996// \\ var res = a();
2997// \\ res *= b(2);
2998// \\ break :blk res;
2999// \\};
3000// \\
3001// \\comptime {
3002// \\ _ = a();
3003// \\}
3004// \\
3005// \\test "comptime" {
3006// \\ const av3 = comptime a();
3007// \\ const av4 = comptime blk: {
3008// \\ var res = a();
3009// \\ res *= a();
3010// \\ break :blk res;
3011// \\ };
3012// \\
3013// \\ comptime var i = 0;
3014// \\ comptime {
3015// \\ i = a();
3016// \\ i += b(i);
3017// \\ }
3018// \\}
3019// \\
3020// );
3021//}
3022//
3023//test "zig fmt: fn type" {
3024// try testCanonical(
3025// \\fn a(i: u8) u8 {
3026// \\ return i + 1;
3027// \\}
3028// \\
3029// \\const a: fn (u8) u8 = undefined;
3030// \\const b: fn (u8) callconv(.Naked) u8 = undefined;
3031// \\const ap: fn (u8) u8 = a;
3032// \\
3033// );
3034//}
3035//
3036//test "zig fmt: inline asm" {
3037// try testCanonical(
3038// \\pub fn syscall1(number: usize, arg1: usize) usize {
3039// \\ return asm volatile ("syscall"
3040// \\ : [ret] "={rax}" (-> usize)
3041// \\ : [number] "{rax}" (number),
3042// \\ [arg1] "{rdi}" (arg1)
3043// \\ : "rcx", "r11"
3044// \\ );
3045// \\}
3046// \\
3047// );
3048//}
2918test "zig fmt: if" {
2919 try testCanonical(
2920 \\test "if" {
2921 \\ if (10 < 0) {
2922 \\ unreachable;
2923 \\ }
2924 \\
2925 \\ if (10 < 0) unreachable;
2926 \\
2927 \\ if (10 < 0) {
2928 \\ unreachable;
2929 \\ } else {
2930 \\ const a = 20;
2931 \\ }
2932 \\
2933 \\ if (10 < 0) {
2934 \\ unreachable;
2935 \\ } else if (5 < 0) {
2936 \\ unreachable;
2937 \\ } else {
2938 \\ const a = 20;
2939 \\ }
2940 \\
2941 \\ const is_world_broken = if (10 < 0) true else false;
2942 \\ const some_number = 1 + if (10 < 0) 2 else 3;
2943 \\
2944 \\ const a: ?u8 = 10;
2945 \\ const b: ?u8 = null;
2946 \\ if (a) |v| {
2947 \\ const some = v;
2948 \\ } else if (b) |*v| {
2949 \\ unreachable;
2950 \\ } else {
2951 \\ const some = 10;
2952 \\ }
2953 \\
2954 \\ const non_null_a = if (a) |v| v else 0;
2955 \\
2956 \\ const a_err: anyerror!u8 = 0;
2957 \\ if (a_err) |v| {
2958 \\ const p = v;
2959 \\ } else |err| {
2960 \\ unreachable;
2961 \\ }
2962 \\}
2963 \\
2964 );
2965}
2966
2967test "zig fmt: defer" {
2968 try testCanonical(
2969 \\test "defer" {
2970 \\ var i: usize = 0;
2971 \\ defer i = 1;
2972 \\ defer {
2973 \\ i += 2;
2974 \\ i *= i;
2975 \\ }
2976 \\
2977 \\ errdefer i += 3;
2978 \\ errdefer {
2979 \\ i += 2;
2980 \\ i /= i;
2981 \\ }
2982 \\}
2983 \\
2984 );
2985}
2986
2987test "zig fmt: comptime" {
2988 try testCanonical(
2989 \\fn a() u8 {
2990 \\ return 5;
2991 \\}
2992 \\
2993 \\fn b(comptime i: u8) u8 {
2994 \\ return i;
2995 \\}
2996 \\
2997 \\const av = comptime a();
2998 \\const av2 = comptime blk: {
2999 \\ var res = a();
3000 \\ res *= b(2);
3001 \\ break :blk res;
3002 \\};
3003 \\
3004 \\comptime {
3005 \\ _ = a();
3006 \\}
3007 \\
3008 \\test "comptime" {
3009 \\ const av3 = comptime a();
3010 \\ const av4 = comptime blk: {
3011 \\ var res = a();
3012 \\ res *= a();
3013 \\ break :blk res;
3014 \\ };
3015 \\
3016 \\ comptime var i = 0;
3017 \\ comptime {
3018 \\ i = a();
3019 \\ i += b(i);
3020 \\ }
3021 \\}
3022 \\
3023 );
3024}
3025
3026test "zig fmt: fn type" {
3027 try testCanonical(
3028 \\fn a(i: u8) u8 {
3029 \\ return i + 1;
3030 \\}
3031 \\
3032 \\const a: fn (u8) u8 = undefined;
3033 \\const b: fn (u8) callconv(.Naked) u8 = undefined;
3034 \\const ap: fn (u8) u8 = a;
3035 \\
3036 );
3037}
3038
3039test "zig fmt: inline asm" {
3040 try testCanonical(
3041 \\pub fn syscall1(number: usize, arg1: usize) usize {
3042 \\ return asm volatile ("syscall"
3043 \\ : [ret] "={rax}" (-> usize)
3044 \\ : [number] "{rax}" (number),
3045 \\ [arg1] "{rdi}" (arg1)
3046 \\ : "rcx", "r11"
3047 \\ );
3048 \\}
3049 \\
3050 );
3051}
30493052
30503053test "zig fmt: async functions" {
30513054 try testCanonical(
......@@ -3070,67 +3073,67 @@ test "zig fmt: async functions" {
30703073
30713074test "zig fmt: nosuspend" {
30723075 try testCanonical(
3073 \\const a = nosuspend foo();
3076 \\const a = nosuspend foo();
3077 \\
3078 );
3079}
3080
3081test "zig fmt: Block after if" {
3082 try testCanonical(
3083 \\test {
3084 \\ if (true) {
3085 \\ const a = 0;
3086 \\ }
3087 \\
3088 \\ {
3089 \\ const a = 0;
3090 \\ }
3091 \\}
3092 \\
3093 );
3094}
3095
3096test "zig fmt: usingnamespace" {
3097 try testCanonical(
3098 \\usingnamespace @import("std");
3099 \\pub usingnamespace @import("std");
3100 \\
3101 );
3102}
3103
3104test "zig fmt: string identifier" {
3105 try testCanonical(
3106 \\const @"a b" = @"c d".@"e f";
3107 \\fn @"g h"() void {}
3108 \\
3109 );
3110}
3111
3112test "zig fmt: error return" {
3113 try testCanonical(
3114 \\fn err() anyerror {
3115 \\ call();
3116 \\ return error.InvalidArgs;
3117 \\}
30743118 \\
30753119 );
30763120}
30773121
3078//test "zig fmt: Block after if" {
3079// try testCanonical(
3080// \\test "Block after if" {
3081// \\ if (true) {
3082// \\ const a = 0;
3083// \\ }
3084// \\
3085// \\ {
3086// \\ const a = 0;
3087// \\ }
3088// \\}
3089// \\
3090// );
3091//}
3092
3093test "zig fmt: usingnamespace" {
3122test "zig fmt: comptime block in container" {
30943123 try testCanonical(
3095 \\usingnamespace @import("std");
3096 \\pub usingnamespace @import("std");
3124 \\pub fn container() type {
3125 \\ return struct {
3126 \\ comptime {
3127 \\ if (false) {
3128 \\ unreachable;
3129 \\ }
3130 \\ }
3131 \\ };
3132 \\}
30973133 \\
30983134 );
30993135}
31003136
3101//test "zig fmt: string identifier" {
3102// try testCanonical(
3103// \\const @"a b" = @"c d".@"e f";
3104// \\fn @"g h"() void {}
3105// \\
3106// );
3107//}
3108//
3109//test "zig fmt: error return" {
3110// try testCanonical(
3111// \\fn err() anyerror {
3112// \\ call();
3113// \\ return error.InvalidArgs;
3114// \\}
3115// \\
3116// );
3117//}
3118//
3119//test "zig fmt: comptime block in container" {
3120// try testCanonical(
3121// \\pub fn container() type {
3122// \\ return struct {
3123// \\ comptime {
3124// \\ if (false) {
3125// \\ unreachable;
3126// \\ }
3127// \\ }
3128// \\ };
3129// \\}
3130// \\
3131// );
3132//}
3133//
31343137//test "zig fmt: inline asm parameter alignment" {
31353138// try testCanonical(
31363139// \\pub fn main() void {
......@@ -3171,7 +3174,7 @@ test "zig fmt: usingnamespace" {
31713174// \\
31723175// );
31733176//}
3174//
3177
31753178//test "zig fmt: multiline string in array" {
31763179// try testCanonical(
31773180// \\const Foo = [][]const u8{
......@@ -3196,25 +3199,25 @@ test "zig fmt: usingnamespace" {
31963199// \\
31973200// );
31983201//}
3199//
3200//test "zig fmt: if type expr" {
3201// try testCanonical(
3202// \\const mycond = true;
3203// \\pub fn foo() if (mycond) i32 else void {
3204// \\ if (mycond) {
3205// \\ return 42;
3206// \\ }
3207// \\}
3208// \\
3209// );
3210//}
3211//test "zig fmt: file ends with struct field" {
3212// try testCanonical(
3213// \\a: bool
3214// \\
3215// );
3216//}
3217//
3202
3203test "zig fmt: if type expr" {
3204 try testCanonical(
3205 \\const mycond = true;
3206 \\pub fn foo() if (mycond) i32 else void {
3207 \\ if (mycond) {
3208 \\ return 42;
3209 \\ }
3210 \\}
3211 \\
3212 );
3213}
3214test "zig fmt: file ends with struct field" {
3215 try testCanonical(
3216 \\a: bool
3217 \\
3218 );
3219}
3220
32183221//test "zig fmt: comment after empty comment" {
32193222// try testTransform(
32203223// \\const x = true; //
......@@ -3342,7 +3345,7 @@ test "zig fmt: usingnamespace" {
33423345// \\
33433346// );
33443347//}
3345//
3348
33463349//test "zig fmt: top level doc comments" {
33473350// try testCanonical(
33483351// \\//! tld 1
......@@ -3398,7 +3401,7 @@ test "zig fmt: usingnamespace" {
33983401// \\
33993402// );
34003403//}
3401//
3404
34023405//test "zig fmt: extern without container keyword returns error" {
34033406// try testError(
34043407// \\const container = extern {};
......@@ -3408,20 +3411,20 @@ test "zig fmt: usingnamespace" {
34083411// .ExpectedVarDeclOrFn,
34093412// });
34103413//}
3411//
3412//test "zig fmt: integer literals with underscore separators" {
3413// try testTransform(
3414// \\const
3415// \\ x =
3416// \\ 1_234_567
3417// \\ +(0b0_1-0o7_0+0xff_FF ) + 0_0;
3418// ,
3419// \\const x =
3420// \\ 1_234_567 + (0b0_1 - 0o7_0 + 0xff_FF) + 0_0;
3421// \\
3422// );
3423//}
3424//
3414
3415test "zig fmt: integer literals with underscore separators" {
3416 try testTransform(
3417 \\const
3418 \\ x =
3419 \\ 1_234_567
3420 \\ +(0b0_1-0o7_0+0xff_FF ) + 0_0;
3421 ,
3422 \\const x =
3423 \\ 1_234_567 + (0b0_1 - 0o7_0 + 0xff_FF) + 0_0;
3424 \\
3425 );
3426}
3427
34253428//test "zig fmt: hex literals with underscore separators" {
34263429// try testTransform(
34273430// \\pub fn orMask(a: [ 1_000 ]u64, b: [ 1_000] u64) [1_000]u64 {
......@@ -3444,7 +3447,7 @@ test "zig fmt: usingnamespace" {
34443447// \\
34453448// );
34463449//}
3447//
3450
34483451//test "zig fmt: decimal float literals with underscore separators" {
34493452// try testTransform(
34503453// \\pub fn main() void {
......@@ -3461,7 +3464,7 @@ test "zig fmt: usingnamespace" {
34613464// \\
34623465// );
34633466//}
3464//
3467
34653468//test "zig fmt: hexadeciaml float literals with underscore separators" {
34663469// try testTransform(
34673470// \\pub fn main() void {
......@@ -3478,34 +3481,14 @@ test "zig fmt: usingnamespace" {
34783481// \\
34793482// );
34803483//}
3481//
3482//test "zig fmt: convert async fn into callconv(.Async)" {
3483// try testTransform(
3484// \\async fn foo() void {}
3485// ,
3486// \\fn foo() callconv(.Async) void {}
3487// \\
3488// );
3489//}
3490//
3491//test "zig fmt: convert extern fn proto into callconv(.C)" {
3492// try testTransform(
3493// \\extern fn foo0() void {}
3494// \\const foo1 = extern fn () void;
3495// ,
3496// \\extern fn foo0() void {}
3497// \\const foo1 = fn () callconv(.C) void;
3498// \\
3499// );
3500//}
3501//
3484
35023485//test "zig fmt: C var args" {
35033486// try testCanonical(
35043487// \\pub extern "c" fn printf(format: [*:0]const u8, ...) c_int;
35053488// \\
35063489// );
35073490//}
3508//
3491
35093492//test "zig fmt: Only indent multiline string literals in function calls" {
35103493// try testCanonical(
35113494// \\test "zig fmt:" {
......@@ -3522,7 +3505,7 @@ test "zig fmt: usingnamespace" {
35223505// \\
35233506// );
35243507//}
3525//
3508
35263509//test "zig fmt: Don't add extra newline after if" {
35273510// try testCanonical(
35283511// \\pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path: []const u8) !void {
......@@ -3533,7 +3516,7 @@ test "zig fmt: usingnamespace" {
35333516// \\
35343517// );
35353518//}
3536//
3519
35373520//test "zig fmt: comments in ternary ifs" {
35383521// try testCanonical(
35393522// \\const x = if (true) {
......@@ -3611,7 +3594,7 @@ test "zig fmt: usingnamespace" {
36113594// \\
36123595// );
36133596//}
3614//
3597
36153598//test "zig fmt: Control flow statement as body of blockless if" {
36163599// try testCanonical(
36173600// \\pub fn main() void {
......@@ -3648,22 +3631,22 @@ test "zig fmt: usingnamespace" {
36483631// \\
36493632// );
36503633//}
3651//
3652//test "zig fmt: " {
3653// try testCanonical(
3654// \\pub fn sendViewTags(self: Self) void {
3655// \\ var it = ViewStack(View).iterator(self.output.views.first, std.math.maxInt(u32));
3656// \\ while (it.next()) |node|
3657// \\ view_tags.append(node.view.current_tags) catch {
3658// \\ c.wl_resource_post_no_memory(self.wl_resource);
3659// \\ log.crit(.river_status, "out of memory", .{});
3660// \\ return;
3661// \\ };
3662// \\}
3663// \\
3664// );
3665//}
3666//
3634
3635test "zig fmt: regression test for #5722" {
3636 try testCanonical(
3637 \\pub fn sendViewTags(self: Self) void {
3638 \\ var it = ViewStack(View).iterator(self.output.views.first, std.math.maxInt(u32));
3639 \\ while (it.next()) |node|
3640 \\ view_tags.append(node.view.current_tags) catch {
3641 \\ c.wl_resource_post_no_memory(self.wl_resource);
3642 \\ log.crit(.river_status, "out of memory", .{});
3643 \\ return;
3644 \\ };
3645 \\}
3646 \\
3647 );
3648}
3649
36673650//test "zig fmt: allow trailing line comments to do manual array formatting" {
36683651// try testCanonical(
36693652// \\fn foo() void {
......@@ -3804,40 +3787,40 @@ test "zig fmt: usingnamespace" {
38043787// \\
38053788// );
38063789//}
3807//
3808//test "zig fmt: single argument trailing commas in @builtins()" {
3809// try testCanonical(
3810// \\pub fn foo(qzz: []u8) i1 {
3811// \\ @panic(
3812// \\ foo,
3813// \\ );
3814// \\ panic(
3815// \\ foo,
3816// \\ );
3817// \\ @panic(
3818// \\ foo,
3819// \\ bar,
3820// \\ );
3821// \\}
3822// \\
3823// );
3824//}
3825//
3826//test "zig fmt: trailing comma should force multiline 1 column" {
3827// try testTransform(
3828// \\pub const UUID_NULL: uuid_t = [16]u8{0,0,0,0,};
3829// \\
3830// ,
3831// \\pub const UUID_NULL: uuid_t = [16]u8{
3832// \\ 0,
3833// \\ 0,
3834// \\ 0,
3835// \\ 0,
3836// \\};
3837// \\
3838// );
3839//}
3840//
3790
3791test "zig fmt: single argument trailing commas in @builtins()" {
3792 try testCanonical(
3793 \\pub fn foo(qzz: []u8) i1 {
3794 \\ @panic(
3795 \\ foo,
3796 \\ );
3797 \\ panic(
3798 \\ foo,
3799 \\ );
3800 \\ @panic(
3801 \\ foo,
3802 \\ bar,
3803 \\ );
3804 \\}
3805 \\
3806 );
3807}
3808
3809test "zig fmt: trailing comma should force multiline 1 column" {
3810 try testTransform(
3811 \\pub const UUID_NULL: uuid_t = [16]u8{0,0,0,0,};
3812 \\
3813 ,
3814 \\pub const UUID_NULL: uuid_t = [16]u8{
3815 \\ 0,
3816 \\ 0,
3817 \\ 0,
3818 \\ 0,
3819 \\};
3820 \\
3821 );
3822}
3823
38413824//test "zig fmt: function params should align nicely" {
38423825// try testCanonical(
38433826// \\pub fn foo() void {
......@@ -3853,29 +3836,29 @@ test "zig fmt: usingnamespace" {
38533836// \\
38543837// );
38553838//}
3856//
3857//test "recovery: top level" {
3858// try testError(
3859// \\test "" {inline}
3860// \\test "" {inline}
3861// , &[_]Error{
3862// .ExpectedInlinable,
3863// .ExpectedInlinable,
3864// });
3865//}
3866//
3867//test "recovery: block statements" {
3868// try testError(
3869// \\test "" {
3870// \\ foo + +;
3871// \\ inline;
3872// \\}
3873// , &[_]Error{
3874// .InvalidToken,
3875// .ExpectedInlinable,
3876// });
3877//}
3878//
3839
3840test "recovery: top level" {
3841 try testError(
3842 \\test "" {inline}
3843 \\test "" {inline}
3844 , &[_]Error{
3845 .ExpectedInlinable,
3846 .ExpectedInlinable,
3847 });
3848}
3849
3850test "recovery: block statements" {
3851 try testError(
3852 \\test "" {
3853 \\ foo + +;
3854 \\ inline;
3855 \\}
3856 , &[_]Error{
3857 .InvalidToken,
3858 .ExpectedInlinable,
3859 });
3860}
3861
38793862//test "recovery: missing comma" {
38803863// try testError(
38813864// \\test "" {
......@@ -3894,17 +3877,17 @@ test "zig fmt: usingnamespace" {
38943877// .InvalidToken,
38953878// });
38963879//}
3897//
3898//test "recovery: extra qualifier" {
3899// try testError(
3900// \\const a: *const const u8;
3901// \\test ""
3902// , &[_]Error{
3903// .ExtraConstQualifier,
3904// .ExpectedLBrace,
3905// });
3906//}
3907//
3880
3881test "recovery: extra qualifier" {
3882 try testError(
3883 \\const a: *const const u8;
3884 \\test ""
3885 , &[_]Error{
3886 .ExtraConstQualifier,
3887 .ExpectedLBrace,
3888 });
3889}
3890
39083891//test "recovery: missing return type" {
39093892// try testError(
39103893// \\fn foo() {
......@@ -3917,7 +3900,7 @@ test "zig fmt: usingnamespace" {
39173900// .ExpectedLBrace,
39183901// });
39193902//}
3920//
3903
39213904//test "recovery: continue after invalid decl" {
39223905// try testError(
39233906// \\fn foo {
......@@ -3942,7 +3925,7 @@ test "zig fmt: usingnamespace" {
39423925// .InvalidAnd,
39433926// });
39443927//}
3945//
3928
39463929//test "recovery: invalid extern/inline" {
39473930// try testError(
39483931// \\inline test "" { a && b; }
......@@ -3957,7 +3940,7 @@ test "zig fmt: usingnamespace" {
39573940// .InvalidAnd,
39583941// });
39593942//}
3960//
3943
39613944//test "recovery: missing semicolon" {
39623945// try testError(
39633946// \\test "" {
......@@ -3974,7 +3957,7 @@ test "zig fmt: usingnamespace" {
39743957// .ExpectedToken,
39753958// });
39763959//}
3977//
3960
39783961//test "recovery: invalid container members" {
39793962// try testError(
39803963// \\usingnamespace;
......@@ -3993,7 +3976,7 @@ test "zig fmt: usingnamespace" {
39933976// .ExpectedToken,
39943977// });
39953978//}
3996//
3979
39973980//test "recovery: invalid parameter" {
39983981// try testError(
39993982// \\fn main() void {
......@@ -4003,7 +3986,7 @@ test "zig fmt: usingnamespace" {
40033986// .ExpectedToken,
40043987// });
40053988//}
4006//
3989
40073990//test "recovery: extra '}' at top level" {
40083991// try testError(
40093992// \\}}}
......@@ -4018,16 +4001,16 @@ test "zig fmt: usingnamespace" {
40184001// });
40194002//}
40204003//
4021//test "recovery: mismatched bracket at top level" {
4022// try testError(
4023// \\const S = struct {
4024// \\ arr: 128]?G
4025// \\};
4026// , &[_]Error{
4027// .ExpectedToken,
4028// });
4029//}
4030//
4004test "recovery: mismatched bracket at top level" {
4005 try testError(
4006 \\const S = struct {
4007 \\ arr: 128]?G
4008 \\};
4009 , &[_]Error{
4010 .ExpectedToken,
4011 });
4012}
4013
40314014//test "recovery: invalid global error set access" {
40324015// try testError(
40334016// \\test "" {
......@@ -4039,7 +4022,7 @@ test "zig fmt: usingnamespace" {
40394022// .InvalidAnd,
40404023// });
40414024//}
4042//
4025
40434026//test "recovery: invalid asterisk after pointer dereference" {
40444027// try testError(
40454028// \\test "" {
......@@ -4057,7 +4040,7 @@ test "zig fmt: usingnamespace" {
40574040// .InvalidAnd,
40584041// });
40594042//}
4060//
4043
40614044//test "recovery: missing semicolon after if, for, while stmt" {
40624045// try testError(
40634046// \\test "" {
......@@ -4073,27 +4056,27 @@ test "zig fmt: usingnamespace" {
40734056// .InvalidAnd,
40744057// });
40754058//}
4076//
4077//test "recovery: invalid comptime" {
4078// try testError(
4079// \\comptime
4080// , &[_]Error{
4081// .ExpectedBlockOrField,
4082// });
4083//}
4084//
4085//test "recovery: missing block after for/while loops" {
4086// try testError(
4087// \\test "" { while (foo) }
4088// , &[_]Error{
4089// .ExpectedBlockOrAssignment,
4090// });
4091// try testError(
4092// \\test "" { for (foo) |bar| }
4093// , &[_]Error{
4094// .ExpectedBlockOrAssignment,
4095// });
4096//}
4059
4060test "recovery: invalid comptime" {
4061 try testError(
4062 \\comptime
4063 , &[_]Error{
4064 .ExpectedBlockOrField,
4065 });
4066}
4067
4068test "recovery: missing block after for/while loops" {
4069 try testError(
4070 \\test "" { while (foo) }
4071 , &[_]Error{
4072 .ExpectedBlockOrAssignment,
4073 });
4074 try testError(
4075 \\test "" { for (foo) |bar| }
4076 , &[_]Error{
4077 .ExpectedBlockOrAssignment,
4078 });
4079}
40974080
40984081const std = @import("std");
40994082const mem = std.mem;
lib/std/zig/render.zig+5-1
......@@ -198,7 +198,11 @@ fn renderExpression(ais: *Ais, tree: ast.Tree, node: ast.Node.Index, space: Spac
198198 .AnyFrameLiteral,
199199 => return renderToken(ais, tree, main_tokens[node], space),
200200
201 .ErrorValue => unreachable, // TODO
201 .ErrorValue => {
202 try renderToken(ais, tree, main_tokens[node], .None);
203 try renderToken(ais, tree, main_tokens[node] + 1, .None);
204 return renderToken(ais, tree, main_tokens[node] + 2, space);
205 },
202206
203207 .AnyType => return renderToken(ais, tree, main_tokens[node], space),
204208