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 {...@@ -899,12 +899,12 @@ pub const Tree = struct {
899 // require recursion due to the optional comma followed by rbrace.899 // require recursion due to the optional comma followed by rbrace.
900 // TODO follow the pattern set by StructInitDotTwoComma which will allow900 // TODO follow the pattern set by StructInitDotTwoComma which will allow
901 // lastToken to work for all of these.901 // lastToken to work for all of these.
902 .ArrayInit => unreachable,902 .ArrayInit => unreachable, // TODO
903 .ArrayInitOne => unreachable,903 .ArrayInitOne => unreachable, // TODO
904 .ArrayInitDot => unreachable,904 .ArrayInitDot => unreachable, // TODO
905 .StructInit => unreachable,905 .StructInit => unreachable, // TODO
906 .StructInitOne => unreachable,906 .StructInitOne => unreachable, // TODO
907 .StructInitDot => unreachable,907 .StructInitDot => unreachable, // TODO
908908
909 .TaggedUnionEnumTag => unreachable, // TODO909 .TaggedUnionEnumTag => unreachable, // TODO
910 .TaggedUnionEnumTagComma => unreachable, // TODO910 .TaggedUnionEnumTagComma => unreachable, // TODO
...@@ -2065,7 +2065,7 @@ pub const Error = union(enum) {...@@ -2065,7 +2065,7 @@ pub const Error = union(enum) {
2065 pub const ExpectedVarDeclOrFn = SingleTokenError("Expected variable declaration or function, found '{s}'");2065 pub const ExpectedVarDeclOrFn = SingleTokenError("Expected variable declaration or function, found '{s}'");
2066 pub const ExpectedVarDecl = SingleTokenError("Expected variable declaration, found '{s}'");2066 pub const ExpectedVarDecl = SingleTokenError("Expected variable declaration, found '{s}'");
2067 pub const ExpectedFn = SingleTokenError("Expected function, found '{s}'");2067 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}'");
2069 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}'");2069 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}'");
2070 pub const ExpectedEqOrSemi = SingleTokenError("Expected '=' or ';', found '{s}'");2070 pub const ExpectedEqOrSemi = SingleTokenError("Expected '=' or ';', found '{s}'");
2071 pub const ExpectedSemiOrLBrace = SingleTokenError("Expected ';' or '{{', found '{s}'");2071 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" {...@@ -757,14 +757,14 @@ test "zig fmt: tagged union with enum values" {
757// \\757// \\
758// );758// );
759//}759//}
760//760
761//test "zig fmt: enum literal" {761test "zig fmt: enum literal" {
762// try testCanonical(762 try testCanonical(
763// \\const x = .hi;763 \\const x = .hi;
764// \\764 \\
765// );765 );
766//}766}
767//767
768//test "zig fmt: enum literal inside array literal" {768//test "zig fmt: enum literal inside array literal" {
769// try testCanonical(769// try testCanonical(
770// \\test "enums in arrays" {770// \\test "enums in arrays" {
...@@ -779,14 +779,14 @@ test "zig fmt: tagged union with enum values" {...@@ -779,14 +779,14 @@ test "zig fmt: tagged union with enum values" {
779// \\779// \\
780// );780// );
781//}781//}
782//782
783//test "zig fmt: character literal larger than u8" {783test "zig fmt: character literal larger than u8" {
784// try testCanonical(784 try testCanonical(
785// \\const x = '\u{01f4a9}';785 \\const x = '\u{01f4a9}';
786// \\786 \\
787// );787 );
788//}788}
789//789
790//test "zig fmt: infix operator and then multiline string literal" {790//test "zig fmt: infix operator and then multiline string literal" {
791// try testCanonical(791// try testCanonical(
792// \\const x = "" ++792// \\const x = "" ++
...@@ -813,22 +813,22 @@ test "zig fmt: tagged union with enum values" {...@@ -813,22 +813,22 @@ test "zig fmt: tagged union with enum values" {
813// \\813// \\
814// );814// );
815//}815//}
816//816
817//test "zig fmt: threadlocal" {817test "zig fmt: threadlocal" {
818// try testCanonical(818 try testCanonical(
819// \\threadlocal var x: i32 = 1234;819 \\threadlocal var x: i32 = 1234;
820// \\820 \\
821// );821 );
822//}822}
823//823
824//test "zig fmt: linksection" {824test "zig fmt: linksection" {
825// try testCanonical(825 try testCanonical(
826// \\export var aoeu: u64 linksection(".text.derp") = 1234;826 \\export var aoeu: u64 linksection(".text.derp") = 1234;
827// \\export fn _start() linksection(".text.boot") callconv(.Naked) noreturn {}827 \\export fn _start() linksection(".text.boot") callconv(.Naked) noreturn {}
828// \\828 \\
829// );829 );
830//}830}
831//831
832//test "zig fmt: correctly move doc comments on struct fields" {832//test "zig fmt: correctly move doc comments on struct fields" {
833// try testTransform(833// try testTransform(
834// \\pub const section_64 = extern struct {834// \\pub const section_64 = extern struct {
...@@ -895,22 +895,22 @@ test "zig fmt: tagged union with enum values" {...@@ -895,22 +895,22 @@ test "zig fmt: tagged union with enum values" {
895// \\895// \\
896// );896// );
897//}897//}
898//898
899//test "zig fmt: aligned struct field" {899test "zig fmt: aligned struct field" {
900// try testCanonical(900 try testCanonical(
901// \\pub const S = struct {901 \\pub const S = struct {
902// \\ f: i32 align(32),902 \\ f: i32 align(32),
903// \\};903 \\};
904// \\904 \\
905// );905 );
906// try testCanonical(906 try testCanonical(
907// \\pub const S = struct {907 \\pub const S = struct {
908// \\ f: i32 align(32) = 1,908 \\ f: i32 align(32) = 1,
909// \\};909 \\};
910// \\910 \\
911// );911 );
912//}912}
913//913
914//test "zig fmt: comment to disable/enable zig fmt first" {914//test "zig fmt: comment to disable/enable zig fmt first" {
915// try testCanonical(915// try testCanonical(
916// \\// Test trailing comma syntax916// \\// Test trailing comma syntax
...@@ -1040,32 +1040,32 @@ test "zig fmt: tagged union with enum values" {...@@ -1040,32 +1040,32 @@ test "zig fmt: tagged union with enum values" {
1040// \\1040// \\
1041// );1041// );
1042//}1042//}
1043//1043
1044//test "zig fmt: spaces around slice operator" {1044test "zig fmt: spaces around slice operator" {
1045// try testCanonical(1045 try testCanonical(
1046// \\var a = b[c..d];1046 \\var a = b[c..d];
1047// \\var a = b[c..d :0];1047 \\var a = b[c..d :0];
1048// \\var a = b[c + 1 .. d];1048 \\var a = b[c + 1 .. d];
1049// \\var a = b[c + 1 ..];1049 \\var a = b[c + 1 ..];
1050// \\var a = b[c .. d + 1];1050 \\var a = b[c .. d + 1];
1051// \\var a = b[c .. d + 1 :0];1051 \\var a = b[c .. d + 1 :0];
1052// \\var a = b[c.a..d.e];1052 \\var a = b[c.a..d.e];
1053// \\var a = b[c.a..d.e :0];1053 \\var a = b[c.a..d.e :0];
1054// \\1054 \\
1055// );1055 );
1056//}1056}
1057//1057
1058//test "zig fmt: async call in if condition" {1058test "zig fmt: async call in if condition" {
1059// try testCanonical(1059 try testCanonical(
1060// \\comptime {1060 \\comptime {
1061// \\ if (async b()) {1061 \\ if (async b()) {
1062// \\ a();1062 \\ a();
1063// \\ }1063 \\ }
1064// \\}1064 \\}
1065// \\1065 \\
1066// );1066 );
1067//}1067}
1068//1068
1069//test "zig fmt: 2nd arg multiline string" {1069//test "zig fmt: 2nd arg multiline string" {
1070// try testCanonical(1070// try testCanonical(
1071// \\comptime {1071// \\comptime {
...@@ -1300,64 +1300,64 @@ test "zig fmt: tagged union with enum values" {...@@ -1300,64 +1300,64 @@ test "zig fmt: tagged union with enum values" {
1300// \\1300// \\
1301// );1301// );
1302//}1302//}
1303//1303
1304//test "zig fmt: respect line breaks in if-else" {1304test "zig fmt: respect line breaks in if-else" {
1305// try testCanonical(1305 try testCanonical(
1306// \\comptime {1306 \\comptime {
1307// \\ return if (cond) a else b;1307 \\ return if (cond) a else b;
1308// \\ return if (cond)1308 \\ return if (cond)
1309// \\ a1309 \\ a
1310// \\ else1310 \\ else
1311// \\ b;1311 \\ b;
1312// \\ return if (cond)1312 \\ return if (cond)
1313// \\ a1313 \\ a
1314// \\ else if (cond)1314 \\ else if (cond)
1315// \\ b1315 \\ b
1316// \\ else1316 \\ else
1317// \\ c;1317 \\ c;
1318// \\}1318 \\}
1319// \\1319 \\
1320// );1320 );
1321//}1321}
1322//1322
1323//test "zig fmt: respect line breaks after infix operators" {1323test "zig fmt: respect line breaks after infix operators" {
1324// try testCanonical(1324 try testCanonical(
1325// \\comptime {1325 \\comptime {
1326// \\ self.crc =1326 \\ self.crc =
1327// \\ lookup_tables[0][p[7]] ^1327 \\ lookup_tables[0][p[7]] ^
1328// \\ lookup_tables[1][p[6]] ^1328 \\ lookup_tables[1][p[6]] ^
1329// \\ lookup_tables[2][p[5]] ^1329 \\ lookup_tables[2][p[5]] ^
1330// \\ lookup_tables[3][p[4]] ^1330 \\ lookup_tables[3][p[4]] ^
1331// \\ lookup_tables[4][@truncate(u8, self.crc >> 24)] ^1331 \\ lookup_tables[4][@truncate(u8, self.crc >> 24)] ^
1332// \\ lookup_tables[5][@truncate(u8, self.crc >> 16)] ^1332 \\ lookup_tables[5][@truncate(u8, self.crc >> 16)] ^
1333// \\ lookup_tables[6][@truncate(u8, self.crc >> 8)] ^1333 \\ lookup_tables[6][@truncate(u8, self.crc >> 8)] ^
1334// \\ lookup_tables[7][@truncate(u8, self.crc >> 0)];1334 \\ lookup_tables[7][@truncate(u8, self.crc >> 0)];
1335// \\}1335 \\}
1336// \\1336 \\
1337// );1337 );
1338//}1338}
1339//1339
1340//test "zig fmt: fn decl with trailing comma" {1340test "zig fmt: fn decl with trailing comma" {
1341// try testTransform(1341 try testTransform(
1342// \\fn foo(a: i32, b: i32,) void {}1342 \\fn foo(a: i32, b: i32,) void {}
1343// ,1343 ,
1344// \\fn foo(1344 \\fn foo(
1345// \\ a: i32,1345 \\ a: i32,
1346// \\ b: i32,1346 \\ b: i32,
1347// \\) void {}1347 \\) void {}
1348// \\1348 \\
1349// );1349 );
1350//}1350}
1351//1351
1352//test "zig fmt: enum decl with no trailing comma" {1352test "zig fmt: enum decl with no trailing comma" {
1353// try testTransform(1353 try testTransform(
1354// \\const StrLitKind = enum {Normal, C};1354 \\const StrLitKind = enum {Normal, C};
1355// ,1355 ,
1356// \\const StrLitKind = enum { Normal, C };1356 \\const StrLitKind = enum { Normal, C };
1357// \\1357 \\
1358// );1358 );
1359//}1359}
1360//1360
1361//test "zig fmt: switch comment before prong" {1361//test "zig fmt: switch comment before prong" {
1362// try testCanonical(1362// try testCanonical(
1363// \\comptime {1363// \\comptime {
...@@ -1369,22 +1369,25 @@ test "zig fmt: tagged union with enum values" {...@@ -1369,22 +1369,25 @@ test "zig fmt: tagged union with enum values" {
1369// \\1369// \\
1370// );1370// );
1371//}1371//}
1372//1372
1373//test "zig fmt: struct literal no trailing comma" {1373test "zig fmt: struct literal no trailing comma" {
1374// try testTransform(1374 try testTransform(
1375// \\const a = foo{ .x = 1, .y = 2 };1375 \\const a = foo{ .x = 1, .y = 2 };
1376// \\const a = foo{ .x = 1,1376 \\const a = foo{ .x = 1,
1377// \\ .y = 2 };1377 \\ .y = 2 };
1378// ,1378 \\const a = foo{ .x = 1,
1379// \\const a = foo{ .x = 1, .y = 2 };1379 \\ .y = 2, };
1380// \\const a = foo{1380 ,
1381// \\ .x = 1,1381 \\const a = foo{ .x = 1, .y = 2 };
1382// \\ .y = 2,1382 \\const a = foo{ .x = 1, .y = 2 };
1383// \\};1383 \\const a = foo{
1384// \\1384 \\ .x = 1,
1385// );1385 \\ .y = 2,
1386//}1386 \\};
1387//1387 \\
1388 );
1389}
1390
1388//test "zig fmt: struct literal containing a multiline expression" {1391//test "zig fmt: struct literal containing a multiline expression" {
1389// try testTransform(1392// try testTransform(
1390// \\const a = A{ .x = if (f1()) 10 else 20 };1393// \\const a = A{ .x = if (f1()) 10 else 20 };
...@@ -1564,39 +1567,39 @@ test "zig fmt: tagged union with enum values" {...@@ -1564,39 +1567,39 @@ test "zig fmt: tagged union with enum values" {
1564// \\1567// \\
1565// );1568// );
1566//}1569//}
1567//1570
1568//test "zig fmt: trailing comma on fn call" {1571test "zig fmt: trailing comma on fn call" {
1569// try testCanonical(1572 try testCanonical(
1570// \\comptime {1573 \\comptime {
1571// \\ var module = try Module.create(1574 \\ var module = try Module.create(
1572// \\ allocator,1575 \\ allocator,
1573// \\ zig_lib_dir,1576 \\ zig_lib_dir,
1574// \\ full_cache_dir,1577 \\ full_cache_dir,
1575// \\ );1578 \\ );
1576// \\}1579 \\}
1577// \\1580 \\
1578// );1581 );
1579//}1582}
1580//1583
1581//test "zig fmt: multi line arguments without last comma" {1584test "zig fmt: multi line arguments without last comma" {
1582// try testTransform(1585 try testTransform(
1583// \\pub fn foo(1586 \\pub fn foo(
1584// \\ a: usize,1587 \\ a: usize,
1585// \\ b: usize,1588 \\ b: usize,
1586// \\ c: usize,1589 \\ c: usize,
1587// \\ d: usize1590 \\ d: usize
1588// \\) usize {1591 \\) usize {
1589// \\ return a + b + c + d;1592 \\ return a + b + c + d;
1590// \\}1593 \\}
1591// \\1594 \\
1592// ,1595 ,
1593// \\pub fn foo(a: usize, b: usize, c: usize, d: usize) usize {1596 \\pub fn foo(a: usize, b: usize, c: usize, d: usize) usize {
1594// \\ return a + b + c + d;1597 \\ return a + b + c + d;
1595// \\}1598 \\}
1596// \\1599 \\
1597// );1600 );
1598//}1601}
1599//1602
1600//test "zig fmt: empty block with only comment" {1603//test "zig fmt: empty block with only comment" {
1601// try testCanonical(1604// try testCanonical(
1602// \\comptime {1605// \\comptime {
...@@ -1616,19 +1619,19 @@ test "zig fmt: tagged union with enum values" {...@@ -1616,19 +1619,19 @@ test "zig fmt: tagged union with enum values" {
1616// \\1619// \\
1617// );1620// );
1618//}1621//}
1619//1622
1620//test "zig fmt: extra newlines at the end" {1623test "zig fmt: extra newlines at the end" {
1621// try testTransform(1624 try testTransform(
1622// \\const a = b;1625 \\const a = b;
1623// \\1626 \\
1624// \\1627 \\
1625// \\1628 \\
1626// ,1629 ,
1627// \\const a = b;1630 \\const a = b;
1628// \\1631 \\
1629// );1632 );
1630//}1633}
1631//1634
1632//test "zig fmt: simple asm" {1635//test "zig fmt: simple asm" {
1633// try testTransform(1636// try testTransform(
1634// \\comptime {1637// \\comptime {
...@@ -1704,15 +1707,15 @@ test "zig fmt: switch cases trailing comma" {...@@ -1704,15 +1707,15 @@ test "zig fmt: switch cases trailing comma" {
1704 );1707 );
1705}1708}
17061709
1707//test "zig fmt: slice align" {1710test "zig fmt: slice align" {
1708// try testCanonical(1711 try testCanonical(
1709// \\const A = struct {1712 \\const A = struct {
1710// \\ items: []align(A) T,1713 \\ items: []align(A) T,
1711// \\};1714 \\};
1712// \\1715 \\
1713// );1716 );
1714//}1717}
1715//1718
1716//test "zig fmt: add trailing comma to array literal" {1719//test "zig fmt: add trailing comma to array literal" {
1717// try testTransform(1720// try testTransform(
1718// \\comptime {1721// \\comptime {
...@@ -1756,29 +1759,29 @@ test "zig fmt: switch cases trailing comma" {...@@ -1756,29 +1759,29 @@ test "zig fmt: switch cases trailing comma" {
1756// \\1759// \\
1757// );1760// );
1758//}1761//}
1759//1762
1760//test "zig fmt: float literal with exponent" {1763test "zig fmt: bit field alignment" {
1761// try testCanonical(1764 try testCanonical(
1762// \\test "bit field alignment" {1765 \\test {
1763// \\ assert(@TypeOf(&blah.b) == *align(1:3:6) const u3);1766 \\ assert(@TypeOf(&blah.b) == *align(1:3:6) const u3);
1764// \\}1767 \\}
1765// \\1768 \\
1766// );1769 );
1767//}1770}
1768//1771
1769//test "zig fmt: float literal with exponent" {1772test "zig fmt: nested switch" {
1770// try testCanonical(1773 try testCanonical(
1771// \\test "aoeu" {1774 \\test {
1772// \\ switch (state) {1775 \\ switch (state) {
1773// \\ TermState.Start => switch (c) {1776 \\ TermState.Start => switch (c) {
1774// \\ '\x1b' => state = TermState.Escape,1777 \\ '\x1b' => state = TermState.Escape,
1775// \\ else => try out.writeByte(c),1778 \\ else => try out.writeByte(c),
1776// \\ },1779 \\ },
1777// \\ }1780 \\ }
1778// \\}1781 \\}
1779// \\1782 \\
1780// );1783 );
1781//}1784}
17821785
1783test "zig fmt: float literal with exponent" {1786test "zig fmt: float literal with exponent" {
1784 try testCanonical(1787 try testCanonical(
...@@ -1788,34 +1791,34 @@ test "zig fmt: float literal with exponent" {...@@ -1788,34 +1791,34 @@ test "zig fmt: float literal with exponent" {
1788 );1791 );
1789}1792}
17901793
1791//test "zig fmt: if-else end of comptime" {1794test "zig fmt: if-else end of comptime" {
1792// try testCanonical(1795 try testCanonical(
1793// \\comptime {1796 \\comptime {
1794// \\ if (a) {1797 \\ if (a) {
1795// \\ b();1798 \\ b();
1796// \\ } else {1799 \\ } else {
1797// \\ b();1800 \\ b();
1798// \\ }1801 \\ }
1799// \\}1802 \\}
1800// \\1803 \\
1801// );1804 );
1802//}1805}
1803//1806
1804//test "zig fmt: nested blocks" {1807test "zig fmt: nested blocks" {
1805// try testCanonical(1808 try testCanonical(
1806// \\comptime {1809 \\comptime {
1807// \\ {1810 \\ {
1808// \\ {1811 \\ {
1809// \\ {1812 \\ {
1810// \\ a();1813 \\ a();
1811// \\ }1814 \\ }
1812// \\ }1815 \\ }
1813// \\ }1816 \\ }
1814// \\}1817 \\}
1815// \\1818 \\
1816// );1819 );
1817//}1820}
1818//1821
1819//test "zig fmt: block with same line comment after end brace" {1822//test "zig fmt: block with same line comment after end brace" {
1820// try testCanonical(1823// try testCanonical(
1821// \\comptime {1824// \\comptime {
...@@ -1837,17 +1840,17 @@ test "zig fmt: float literal with exponent" {...@@ -1837,17 +1840,17 @@ test "zig fmt: float literal with exponent" {
1837// \\1840// \\
1838// );1841// );
1839//}1842//}
1840//1843
1841//test "zig fmt: statements with empty line between" {1844test "zig fmt: statements with empty line between" {
1842// try testCanonical(1845 try testCanonical(
1843// \\comptime {1846 \\comptime {
1844// \\ a = b;1847 \\ a = b;
1845// \\1848 \\
1846// \\ a = b;1849 \\ a = b;
1847// \\}1850 \\}
1848// \\1851 \\
1849// );1852 );
1850//}1853}
18511854
1852test "zig fmt: ptr deref operator and unwrap optional operator" {1855test "zig fmt: ptr deref operator and unwrap optional operator" {
1853 try testCanonical(1856 try testCanonical(
...@@ -2119,18 +2122,18 @@ test "zig fmt: error set declaration" {...@@ -2119,18 +2122,18 @@ test "zig fmt: error set declaration" {
2119// \\2122// \\
2120// );2123// );
2121//}2124//}
2122//2125
2123//test "zig fmt: union(enum(u32)) with assigned enum values" {2126test "zig fmt: union(enum(u32)) with assigned enum values" {
2124// try testCanonical(2127 try testCanonical(
2125// \\const MultipleChoice = union(enum(u32)) {2128 \\const MultipleChoice = union(enum(u32)) {
2126// \\ A = 20,2129 \\ A = 20,
2127// \\ B = 40,2130 \\ B = 40,
2128// \\ C = 60,2131 \\ C = 60,
2129// \\ D = 1000,2132 \\ D = 1000,
2130// \\};2133 \\};
2131// \\2134 \\
2132// );2135 );
2133//}2136}
21342137
2135test "zig fmt: resume from suspend block" {2138test "zig fmt: resume from suspend block" {
2136 try testCanonical(2139 try testCanonical(
...@@ -2270,15 +2273,15 @@ test "zig fmt: resume from suspend block" {...@@ -2270,15 +2273,15 @@ test "zig fmt: resume from suspend block" {
2270// \\2273// \\
2271// );2274// );
2272//}2275//}
2273//2276
2274//test "zig fmt: imports" {2277test "zig fmt: imports" {
2275// try testCanonical(2278 try testCanonical(
2276// \\const std = @import("std");2279 \\const std = @import("std");
2277// \\const std = @import();2280 \\const std = @import();
2278// \\2281 \\
2279// );2282 );
2280//}2283}
2281//2284
2282//test "zig fmt: global declarations" {2285//test "zig fmt: global declarations" {
2283// try testCanonical(2286// try testCanonical(
2284// \\const a = b;2287// \\const a = b;
...@@ -2300,21 +2303,21 @@ test "zig fmt: resume from suspend block" {...@@ -2300,21 +2303,21 @@ test "zig fmt: resume from suspend block" {
2300// \\2303// \\
2301// );2304// );
2302//}2305//}
2303//2306
2304//test "zig fmt: extern declaration" {2307test "zig fmt: extern declaration" {
2305// try testCanonical(2308 try testCanonical(
2306// \\extern var foo: c_int;2309 \\extern var foo: c_int;
2307// \\2310 \\
2308// );2311 );
2309//}2312}
2310//2313
2311//test "zig fmt: alignment" {2314test "zig fmt: alignment" {
2312// try testCanonical(2315 try testCanonical(
2313// \\var foo: c_int align(1);2316 \\var foo: c_int align(1);
2314// \\2317 \\
2315// );2318 );
2316//}2319}
2317//2320
2318//test "zig fmt: C main" {2321//test "zig fmt: C main" {
2319// try testCanonical(2322// try testCanonical(
2320// \\fn main(argc: c_int, argv: **u8) c_int {2323// \\fn main(argc: c_int, argv: **u8) c_int {
...@@ -2358,128 +2361,128 @@ test "zig fmt: resume from suspend block" {...@@ -2358,128 +2361,128 @@ test "zig fmt: resume from suspend block" {
2358// \\2361// \\
2359// );2362// );
2360//}2363//}
2361//2364
2362//test "zig fmt: test declaration" {2365test "zig fmt: test declaration" {
2363// try testCanonical(2366 try testCanonical(
2364// \\test "test name" {2367 \\test "test name" {
2365// \\ const a = 1;2368 \\ const a = 1;
2366// \\ var b = 1;2369 \\ var b = 1;
2367// \\}2370 \\}
2368// \\2371 \\
2369// );2372 );
2370//}2373}
2371//2374
2372//test "zig fmt: infix operators" {2375test "zig fmt: infix operators" {
2373// try testCanonical(2376 try testCanonical(
2374// \\test "infix operators" {2377 \\test {
2375// \\ var i = undefined;2378 \\ var i = undefined;
2376// \\ i = 2;2379 \\ i = 2;
2377// \\ i *= 2;2380 \\ i *= 2;
2378// \\ i |= 2;2381 \\ i |= 2;
2379// \\ i ^= 2;2382 \\ i ^= 2;
2380// \\ i <<= 2;2383 \\ i <<= 2;
2381// \\ i >>= 2;2384 \\ i >>= 2;
2382// \\ i &= 2;2385 \\ i &= 2;
2383// \\ i *= 2;2386 \\ i *= 2;
2384// \\ i *%= 2;2387 \\ i *%= 2;
2385// \\ i -= 2;2388 \\ i -= 2;
2386// \\ i -%= 2;2389 \\ i -%= 2;
2387// \\ i += 2;2390 \\ i += 2;
2388// \\ i +%= 2;2391 \\ i +%= 2;
2389// \\ i /= 2;2392 \\ i /= 2;
2390// \\ i %= 2;2393 \\ i %= 2;
2391// \\ _ = i == i;2394 \\ _ = i == i;
2392// \\ _ = i != i;2395 \\ _ = i != i;
2393// \\ _ = i != i;2396 \\ _ = i != i;
2394// \\ _ = i.i;2397 \\ _ = i.i;
2395// \\ _ = i || i;2398 \\ _ = i || i;
2396// \\ _ = i!i;2399 \\ _ = i!i;
2397// \\ _ = i ** i;2400 \\ _ = i ** i;
2398// \\ _ = i ++ i;2401 \\ _ = i ++ i;
2399// \\ _ = i orelse i;2402 \\ _ = i orelse i;
2400// \\ _ = i % i;2403 \\ _ = i % i;
2401// \\ _ = i / i;2404 \\ _ = i / i;
2402// \\ _ = i *% i;2405 \\ _ = i *% i;
2403// \\ _ = i * i;2406 \\ _ = i * i;
2404// \\ _ = i -% i;2407 \\ _ = i -% i;
2405// \\ _ = i - i;2408 \\ _ = i - i;
2406// \\ _ = i +% i;2409 \\ _ = i +% i;
2407// \\ _ = i + i;2410 \\ _ = i + i;
2408// \\ _ = i << i;2411 \\ _ = i << i;
2409// \\ _ = i >> i;2412 \\ _ = i >> i;
2410// \\ _ = i & i;2413 \\ _ = i & i;
2411// \\ _ = i ^ i;2414 \\ _ = i ^ i;
2412// \\ _ = i | i;2415 \\ _ = i | i;
2413// \\ _ = i >= i;2416 \\ _ = i >= i;
2414// \\ _ = i <= i;2417 \\ _ = i <= i;
2415// \\ _ = i > i;2418 \\ _ = i > i;
2416// \\ _ = i < i;2419 \\ _ = i < i;
2417// \\ _ = i and i;2420 \\ _ = i and i;
2418// \\ _ = i or i;2421 \\ _ = i or i;
2419// \\}2422 \\}
2420// \\2423 \\
2421// );2424 );
2422//}2425}
2423//2426
2424//test "zig fmt: precedence" {2427test "zig fmt: precedence" {
2425// try testCanonical(2428 try testCanonical(
2426// \\test "precedence" {2429 \\test "precedence" {
2427// \\ a!b();2430 \\ a!b();
2428// \\ (a!b)();2431 \\ (a!b)();
2429// \\ !a!b;2432 \\ !a!b;
2430// \\ !(a!b);2433 \\ !(a!b);
2431// \\ !a{};2434 \\ !a{};
2432// \\ !(a{});2435 \\ !(a{});
2433// \\ a + b{};2436 \\ a + b{};
2434// \\ (a + b){};2437 \\ (a + b){};
2435// \\ a << b + c;2438 \\ a << b + c;
2436// \\ (a << b) + c;2439 \\ (a << b) + c;
2437// \\ a & b << c;2440 \\ a & b << c;
2438// \\ (a & b) << c;2441 \\ (a & b) << c;
2439// \\ a ^ b & c;2442 \\ a ^ b & c;
2440// \\ (a ^ b) & c;2443 \\ (a ^ b) & c;
2441// \\ a | b ^ c;2444 \\ a | b ^ c;
2442// \\ (a | b) ^ c;2445 \\ (a | b) ^ c;
2443// \\ a == b | c;2446 \\ a == b | c;
2444// \\ (a == b) | c;2447 \\ (a == b) | c;
2445// \\ a and b == c;2448 \\ a and b == c;
2446// \\ (a and b) == c;2449 \\ (a and b) == c;
2447// \\ a or b and c;2450 \\ a or b and c;
2448// \\ (a or b) and c;2451 \\ (a or b) and c;
2449// \\ (a or b) and c;2452 \\ (a or b) and c;
2450// \\}2453 \\}
2451// \\2454 \\
2452// );2455 );
2453//}2456}
2454//2457
2455//test "zig fmt: prefix operators" {2458test "zig fmt: prefix operators" {
2456// try testCanonical(2459 try testCanonical(
2457// \\test "prefix operators" {2460 \\test "prefix operators" {
2458// \\ try return --%~!&0;2461 \\ try return --%~!&0;
2459// \\}2462 \\}
2460// \\2463 \\
2461// );2464 );
2462//}2465}
2463//2466
2464//test "zig fmt: call expression" {2467test "zig fmt: call expression" {
2465// try testCanonical(2468 try testCanonical(
2466// \\test "test calls" {2469 \\test "test calls" {
2467// \\ a();2470 \\ a();
2468// \\ a(1);2471 \\ a(1);
2469// \\ a(1, 2);2472 \\ a(1, 2);
2470// \\ a(1, 2) + a(1, 2);2473 \\ a(1, 2) + a(1, 2);
2471// \\}2474 \\}
2472// \\2475 \\
2473// );2476 );
2474//}2477}
2475//2478
2476//test "zig fmt: anytype type" {2479//test "zig fmt: anytype type" {
2477// try testCanonical(2480// try testCanonical(
2478// \\fn print(args: anytype) anytype {}2481// \\fn print(args: anytype) anytype {}
2479// \\2482// \\
2480// );2483// );
2481//}2484//}
2482//2485
2483//test "zig fmt: functions" {2486//test "zig fmt: functions" {
2484// try testCanonical(2487// try testCanonical(
2485// \\extern fn puts(s: *const u8) c_int;2488// \\extern fn puts(s: *const u8) c_int;
...@@ -2500,7 +2503,7 @@ test "zig fmt: resume from suspend block" {...@@ -2500,7 +2503,7 @@ test "zig fmt: resume from suspend block" {
2500// \\2503// \\
2501// );2504// );
2502//}2505//}
2503//2506
2504//test "zig fmt: multiline string" {2507//test "zig fmt: multiline string" {
2505// try testCanonical(2508// try testCanonical(
2506// \\test "" {2509// \\test "" {
...@@ -2518,145 +2521,145 @@ test "zig fmt: resume from suspend block" {...@@ -2518,145 +2521,145 @@ test "zig fmt: resume from suspend block" {
2518// \\2521// \\
2519// );2522// );
2520//}2523//}
2521//2524
2522//test "zig fmt: values" {2525test "zig fmt: values" {
2523// try testCanonical(2526 try testCanonical(
2524// \\test "values" {2527 \\test "values" {
2525// \\ 1;2528 \\ 1;
2526// \\ 1.0;2529 \\ 1.0;
2527// \\ "string";2530 \\ "string";
2528// \\ 'c';2531 \\ 'c';
2529// \\ true;2532 \\ true;
2530// \\ false;2533 \\ false;
2531// \\ null;2534 \\ null;
2532// \\ undefined;2535 \\ undefined;
2533// \\ anyerror;2536 \\ anyerror;
2534// \\ this;2537 \\ this;
2535// \\ unreachable;2538 \\ unreachable;
2536// \\}2539 \\}
2537// \\2540 \\
2538// );2541 );
2539//}2542}
2540//2543
2541//test "zig fmt: indexing" {2544test "zig fmt: indexing" {
2542// try testCanonical(2545 try testCanonical(
2543// \\test "test index" {2546 \\test "test index" {
2544// \\ a[0];2547 \\ a[0];
2545// \\ a[0 + 5];2548 \\ a[0 + 5];
2546// \\ a[0..];2549 \\ a[0..];
2547// \\ a[0..5];2550 \\ a[0..5];
2548// \\ a[a[0]];2551 \\ a[a[0]];
2549// \\ a[a[0..]];2552 \\ a[a[0..]];
2550// \\ a[a[0..5]];2553 \\ a[a[0..5]];
2551// \\ a[a[0]..];2554 \\ a[a[0]..];
2552// \\ a[a[0..5]..];2555 \\ a[a[0..5]..];
2553// \\ a[a[0]..a[0]];2556 \\ a[a[0]..a[0]];
2554// \\ a[a[0..5]..a[0]];2557 \\ a[a[0..5]..a[0]];
2555// \\ a[a[0..5]..a[0..5]];2558 \\ a[a[0..5]..a[0..5]];
2556// \\}2559 \\}
2557// \\2560 \\
2558// );2561 );
2559//}2562}
2560//2563
2561//test "zig fmt: struct declaration" {2564test "zig fmt: struct declaration" {
2562// try testCanonical(2565 try testCanonical(
2563// \\const S = struct {2566 \\const S = struct {
2564// \\ const Self = @This();2567 \\ const Self = @This();
2565// \\ f1: u8,2568 \\ f1: u8,
2566// \\ f3: u8,2569 \\ f3: u8,
2567// \\2570 \\
2568// \\ f2: u8,2571 \\ f2: u8,
2569// \\2572 \\
2570// \\ fn method(self: *Self) Self {2573 \\ fn method(self: *Self) Self {
2571// \\ return self.*;2574 \\ return self.*;
2572// \\ }2575 \\ }
2573// \\};2576 \\};
2574// \\2577 \\
2575// \\const Ps = packed struct {2578 \\const Ps = packed struct {
2576// \\ a: u8,2579 \\ a: u8,
2577// \\ b: u8,2580 \\ b: u8,
2578// \\2581 \\
2579// \\ c: u8,2582 \\ c: u8,
2580// \\};2583 \\};
2581// \\2584 \\
2582// \\const Es = extern struct {2585 \\const Es = extern struct {
2583// \\ a: u8,2586 \\ a: u8,
2584// \\ b: u8,2587 \\ b: u8,
2585// \\2588 \\
2586// \\ c: u8,2589 \\ c: u8,
2587// \\};2590 \\};
2588// \\2591 \\
2589// );2592 );
2590//}2593}
2591//2594
2592//test "zig fmt: enum declaration" {2595test "zig fmt: enum declaration" {
2593// try testCanonical(2596 try testCanonical(
2594// \\const E = enum {2597 \\const E = enum {
2595// \\ Ok,2598 \\ Ok,
2596// \\ SomethingElse = 0,2599 \\ SomethingElse = 0,
2597// \\};2600 \\};
2598// \\2601 \\
2599// \\const E2 = enum(u8) {2602 \\const E2 = enum(u8) {
2600// \\ Ok,2603 \\ Ok,
2601// \\ SomethingElse = 255,2604 \\ SomethingElse = 255,
2602// \\ SomethingThird,2605 \\ SomethingThird,
2603// \\};2606 \\};
2604// \\2607 \\
2605// \\const Ee = extern enum {2608 \\const Ee = extern enum {
2606// \\ Ok,2609 \\ Ok,
2607// \\ SomethingElse,2610 \\ SomethingElse,
2608// \\ SomethingThird,2611 \\ SomethingThird,
2609// \\};2612 \\};
2610// \\2613 \\
2611// \\const Ep = packed enum {2614 \\const Ep = packed enum {
2612// \\ Ok,2615 \\ Ok,
2613// \\ SomethingElse,2616 \\ SomethingElse,
2614// \\ SomethingThird,2617 \\ SomethingThird,
2615// \\};2618 \\};
2616// \\2619 \\
2617// );2620 );
2618//}2621}
2619//2622
2620//test "zig fmt: union declaration" {2623test "zig fmt: union declaration" {
2621// try testCanonical(2624 try testCanonical(
2622// \\const U = union {2625 \\const U = union {
2623// \\ Int: u8,2626 \\ Int: u8,
2624// \\ Float: f32,2627 \\ Float: f32,
2625// \\ None,2628 \\ None,
2626// \\ Bool: bool,2629 \\ Bool: bool,
2627// \\};2630 \\};
2628// \\2631 \\
2629// \\const Ue = union(enum) {2632 \\const Ue = union(enum) {
2630// \\ Int: u8,2633 \\ Int: u8,
2631// \\ Float: f32,2634 \\ Float: f32,
2632// \\ None,2635 \\ None,
2633// \\ Bool: bool,2636 \\ Bool: bool,
2634// \\};2637 \\};
2635// \\2638 \\
2636// \\const E = enum {2639 \\const E = enum {
2637// \\ Int,2640 \\ Int,
2638// \\ Float,2641 \\ Float,
2639// \\ None,2642 \\ None,
2640// \\ Bool,2643 \\ Bool,
2641// \\};2644 \\};
2642// \\2645 \\
2643// \\const Ue2 = union(E) {2646 \\const Ue2 = union(E) {
2644// \\ Int: u8,2647 \\ Int: u8,
2645// \\ Float: f32,2648 \\ Float: f32,
2646// \\ None,2649 \\ None,
2647// \\ Bool: bool,2650 \\ Bool: bool,
2648// \\};2651 \\};
2649// \\2652 \\
2650// \\const Eu = extern union {2653 \\const Eu = extern union {
2651// \\ Int: u8,2654 \\ Int: u8,
2652// \\ Float: f32,2655 \\ Float: f32,
2653// \\ None,2656 \\ None,
2654// \\ Bool: bool,2657 \\ Bool: bool,
2655// \\};2658 \\};
2656// \\2659 \\
2657// );2660 );
2658//}2661}
2659//2662
2660//test "zig fmt: arrays" {2663//test "zig fmt: arrays" {
2661// try testCanonical(2664// try testCanonical(
2662// \\test "test array" {2665// \\test "test array" {
...@@ -2674,7 +2677,7 @@ test "zig fmt: resume from suspend block" {...@@ -2674,7 +2677,7 @@ test "zig fmt: resume from suspend block" {
2674// \\2677// \\
2675// );2678// );
2676//}2679//}
2677//2680
2678//test "zig fmt: container initializers" {2681//test "zig fmt: container initializers" {
2679// try testCanonical(2682// try testCanonical(
2680// \\const a0 = []u8{};2683// \\const a0 = []u8{};
...@@ -2912,140 +2915,140 @@ test "zig fmt: for" {...@@ -2912,140 +2915,140 @@ test "zig fmt: for" {
2912 );2915 );
2913}2916}
29142917
2915//test "zig fmt: if" {2918test "zig fmt: if" {
2916// try testCanonical(2919 try testCanonical(
2917// \\test "if" {2920 \\test "if" {
2918// \\ if (10 < 0) {2921 \\ if (10 < 0) {
2919// \\ unreachable;2922 \\ unreachable;
2920// \\ }2923 \\ }
2921// \\2924 \\
2922// \\ if (10 < 0) unreachable;2925 \\ if (10 < 0) unreachable;
2923// \\2926 \\
2924// \\ if (10 < 0) {2927 \\ if (10 < 0) {
2925// \\ unreachable;2928 \\ unreachable;
2926// \\ } else {2929 \\ } else {
2927// \\ const a = 20;2930 \\ const a = 20;
2928// \\ }2931 \\ }
2929// \\2932 \\
2930// \\ if (10 < 0) {2933 \\ if (10 < 0) {
2931// \\ unreachable;2934 \\ unreachable;
2932// \\ } else if (5 < 0) {2935 \\ } else if (5 < 0) {
2933// \\ unreachable;2936 \\ unreachable;
2934// \\ } else {2937 \\ } else {
2935// \\ const a = 20;2938 \\ const a = 20;
2936// \\ }2939 \\ }
2937// \\2940 \\
2938// \\ const is_world_broken = if (10 < 0) true else false;2941 \\ const is_world_broken = if (10 < 0) true else false;
2939// \\ const some_number = 1 + if (10 < 0) 2 else 3;2942 \\ const some_number = 1 + if (10 < 0) 2 else 3;
2940// \\2943 \\
2941// \\ const a: ?u8 = 10;2944 \\ const a: ?u8 = 10;
2942// \\ const b: ?u8 = null;2945 \\ const b: ?u8 = null;
2943// \\ if (a) |v| {2946 \\ if (a) |v| {
2944// \\ const some = v;2947 \\ const some = v;
2945// \\ } else if (b) |*v| {2948 \\ } else if (b) |*v| {
2946// \\ unreachable;2949 \\ unreachable;
2947// \\ } else {2950 \\ } else {
2948// \\ const some = 10;2951 \\ const some = 10;
2949// \\ }2952 \\ }
2950// \\2953 \\
2951// \\ const non_null_a = if (a) |v| v else 0;2954 \\ const non_null_a = if (a) |v| v else 0;
2952// \\2955 \\
2953// \\ const a_err: anyerror!u8 = 0;2956 \\ const a_err: anyerror!u8 = 0;
2954// \\ if (a_err) |v| {2957 \\ if (a_err) |v| {
2955// \\ const p = v;2958 \\ const p = v;
2956// \\ } else |err| {2959 \\ } else |err| {
2957// \\ unreachable;2960 \\ unreachable;
2958// \\ }2961 \\ }
2959// \\}2962 \\}
2960// \\2963 \\
2961// );2964 );
2962//}2965}
2963//2966
2964//test "zig fmt: defer" {2967test "zig fmt: defer" {
2965// try testCanonical(2968 try testCanonical(
2966// \\test "defer" {2969 \\test "defer" {
2967// \\ var i: usize = 0;2970 \\ var i: usize = 0;
2968// \\ defer i = 1;2971 \\ defer i = 1;
2969// \\ defer {2972 \\ defer {
2970// \\ i += 2;2973 \\ i += 2;
2971// \\ i *= i;2974 \\ i *= i;
2972// \\ }2975 \\ }
2973// \\2976 \\
2974// \\ errdefer i += 3;2977 \\ errdefer i += 3;
2975// \\ errdefer {2978 \\ errdefer {
2976// \\ i += 2;2979 \\ i += 2;
2977// \\ i /= i;2980 \\ i /= i;
2978// \\ }2981 \\ }
2979// \\}2982 \\}
2980// \\2983 \\
2981// );2984 );
2982//}2985}
2983//2986
2984//test "zig fmt: comptime" {2987test "zig fmt: comptime" {
2985// try testCanonical(2988 try testCanonical(
2986// \\fn a() u8 {2989 \\fn a() u8 {
2987// \\ return 5;2990 \\ return 5;
2988// \\}2991 \\}
2989// \\2992 \\
2990// \\fn b(comptime i: u8) u8 {2993 \\fn b(comptime i: u8) u8 {
2991// \\ return i;2994 \\ return i;
2992// \\}2995 \\}
2993// \\2996 \\
2994// \\const av = comptime a();2997 \\const av = comptime a();
2995// \\const av2 = comptime blk: {2998 \\const av2 = comptime blk: {
2996// \\ var res = a();2999 \\ var res = a();
2997// \\ res *= b(2);3000 \\ res *= b(2);
2998// \\ break :blk res;3001 \\ break :blk res;
2999// \\};3002 \\};
3000// \\3003 \\
3001// \\comptime {3004 \\comptime {
3002// \\ _ = a();3005 \\ _ = a();
3003// \\}3006 \\}
3004// \\3007 \\
3005// \\test "comptime" {3008 \\test "comptime" {
3006// \\ const av3 = comptime a();3009 \\ const av3 = comptime a();
3007// \\ const av4 = comptime blk: {3010 \\ const av4 = comptime blk: {
3008// \\ var res = a();3011 \\ var res = a();
3009// \\ res *= a();3012 \\ res *= a();
3010// \\ break :blk res;3013 \\ break :blk res;
3011// \\ };3014 \\ };
3012// \\3015 \\
3013// \\ comptime var i = 0;3016 \\ comptime var i = 0;
3014// \\ comptime {3017 \\ comptime {
3015// \\ i = a();3018 \\ i = a();
3016// \\ i += b(i);3019 \\ i += b(i);
3017// \\ }3020 \\ }
3018// \\}3021 \\}
3019// \\3022 \\
3020// );3023 );
3021//}3024}
3022//3025
3023//test "zig fmt: fn type" {3026test "zig fmt: fn type" {
3024// try testCanonical(3027 try testCanonical(
3025// \\fn a(i: u8) u8 {3028 \\fn a(i: u8) u8 {
3026// \\ return i + 1;3029 \\ return i + 1;
3027// \\}3030 \\}
3028// \\3031 \\
3029// \\const a: fn (u8) u8 = undefined;3032 \\const a: fn (u8) u8 = undefined;
3030// \\const b: fn (u8) callconv(.Naked) u8 = undefined;3033 \\const b: fn (u8) callconv(.Naked) u8 = undefined;
3031// \\const ap: fn (u8) u8 = a;3034 \\const ap: fn (u8) u8 = a;
3032// \\3035 \\
3033// );3036 );
3034//}3037}
3035//3038
3036//test "zig fmt: inline asm" {3039test "zig fmt: inline asm" {
3037// try testCanonical(3040 try testCanonical(
3038// \\pub fn syscall1(number: usize, arg1: usize) usize {3041 \\pub fn syscall1(number: usize, arg1: usize) usize {
3039// \\ return asm volatile ("syscall"3042 \\ return asm volatile ("syscall"
3040// \\ : [ret] "={rax}" (-> usize)3043 \\ : [ret] "={rax}" (-> usize)
3041// \\ : [number] "{rax}" (number),3044 \\ : [number] "{rax}" (number),
3042// \\ [arg1] "{rdi}" (arg1)3045 \\ [arg1] "{rdi}" (arg1)
3043// \\ : "rcx", "r11"3046 \\ : "rcx", "r11"
3044// \\ );3047 \\ );
3045// \\}3048 \\}
3046// \\3049 \\
3047// );3050 );
3048//}3051}
30493052
3050test "zig fmt: async functions" {3053test "zig fmt: async functions" {
3051 try testCanonical(3054 try testCanonical(
...@@ -3070,67 +3073,67 @@ test "zig fmt: async functions" {...@@ -3070,67 +3073,67 @@ test "zig fmt: async functions" {
30703073
3071test "zig fmt: nosuspend" {3074test "zig fmt: nosuspend" {
3072 try testCanonical(3075 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 \\}
3074 \\3118 \\
3075 );3119 );
3076}3120}
30773121
3078//test "zig fmt: Block after if" {3122test "zig fmt: comptime block in container" {
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" {
3094 try testCanonical(3123 try testCanonical(
3095 \\usingnamespace @import("std");3124 \\pub fn container() type {
3096 \\pub usingnamespace @import("std");3125 \\ return struct {
3126 \\ comptime {
3127 \\ if (false) {
3128 \\ unreachable;
3129 \\ }
3130 \\ }
3131 \\ };
3132 \\}
3097 \\3133 \\
3098 );3134 );
3099}3135}
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//
3134//test "zig fmt: inline asm parameter alignment" {3137//test "zig fmt: inline asm parameter alignment" {
3135// try testCanonical(3138// try testCanonical(
3136// \\pub fn main() void {3139// \\pub fn main() void {
...@@ -3171,7 +3174,7 @@ test "zig fmt: usingnamespace" {...@@ -3171,7 +3174,7 @@ test "zig fmt: usingnamespace" {
3171// \\3174// \\
3172// );3175// );
3173//}3176//}
3174//3177
3175//test "zig fmt: multiline string in array" {3178//test "zig fmt: multiline string in array" {
3176// try testCanonical(3179// try testCanonical(
3177// \\const Foo = [][]const u8{3180// \\const Foo = [][]const u8{
...@@ -3196,25 +3199,25 @@ test "zig fmt: usingnamespace" {...@@ -3196,25 +3199,25 @@ test "zig fmt: usingnamespace" {
3196// \\3199// \\
3197// );3200// );
3198//}3201//}
3199//3202
3200//test "zig fmt: if type expr" {3203test "zig fmt: if type expr" {
3201// try testCanonical(3204 try testCanonical(
3202// \\const mycond = true;3205 \\const mycond = true;
3203// \\pub fn foo() if (mycond) i32 else void {3206 \\pub fn foo() if (mycond) i32 else void {
3204// \\ if (mycond) {3207 \\ if (mycond) {
3205// \\ return 42;3208 \\ return 42;
3206// \\ }3209 \\ }
3207// \\}3210 \\}
3208// \\3211 \\
3209// );3212 );
3210//}3213}
3211//test "zig fmt: file ends with struct field" {3214test "zig fmt: file ends with struct field" {
3212// try testCanonical(3215 try testCanonical(
3213// \\a: bool3216 \\a: bool
3214// \\3217 \\
3215// );3218 );
3216//}3219}
3217//3220
3218//test "zig fmt: comment after empty comment" {3221//test "zig fmt: comment after empty comment" {
3219// try testTransform(3222// try testTransform(
3220// \\const x = true; //3223// \\const x = true; //
...@@ -3342,7 +3345,7 @@ test "zig fmt: usingnamespace" {...@@ -3342,7 +3345,7 @@ test "zig fmt: usingnamespace" {
3342// \\3345// \\
3343// );3346// );
3344//}3347//}
3345//3348
3346//test "zig fmt: top level doc comments" {3349//test "zig fmt: top level doc comments" {
3347// try testCanonical(3350// try testCanonical(
3348// \\//! tld 13351// \\//! tld 1
...@@ -3398,7 +3401,7 @@ test "zig fmt: usingnamespace" {...@@ -3398,7 +3401,7 @@ test "zig fmt: usingnamespace" {
3398// \\3401// \\
3399// );3402// );
3400//}3403//}
3401//3404
3402//test "zig fmt: extern without container keyword returns error" {3405//test "zig fmt: extern without container keyword returns error" {
3403// try testError(3406// try testError(
3404// \\const container = extern {};3407// \\const container = extern {};
...@@ -3408,20 +3411,20 @@ test "zig fmt: usingnamespace" {...@@ -3408,20 +3411,20 @@ test "zig fmt: usingnamespace" {
3408// .ExpectedVarDeclOrFn,3411// .ExpectedVarDeclOrFn,
3409// });3412// });
3410//}3413//}
3411//3414
3412//test "zig fmt: integer literals with underscore separators" {3415test "zig fmt: integer literals with underscore separators" {
3413// try testTransform(3416 try testTransform(
3414// \\const3417 \\const
3415// \\ x =3418 \\ x =
3416// \\ 1_234_5673419 \\ 1_234_567
3417// \\ +(0b0_1-0o7_0+0xff_FF ) + 0_0;3420 \\ +(0b0_1-0o7_0+0xff_FF ) + 0_0;
3418// ,3421 ,
3419// \\const x =3422 \\const x =
3420// \\ 1_234_567 + (0b0_1 - 0o7_0 + 0xff_FF) + 0_0;3423 \\ 1_234_567 + (0b0_1 - 0o7_0 + 0xff_FF) + 0_0;
3421// \\3424 \\
3422// );3425 );
3423//}3426}
3424//3427
3425//test "zig fmt: hex literals with underscore separators" {3428//test "zig fmt: hex literals with underscore separators" {
3426// try testTransform(3429// try testTransform(
3427// \\pub fn orMask(a: [ 1_000 ]u64, b: [ 1_000] u64) [1_000]u64 {3430// \\pub fn orMask(a: [ 1_000 ]u64, b: [ 1_000] u64) [1_000]u64 {
...@@ -3444,7 +3447,7 @@ test "zig fmt: usingnamespace" {...@@ -3444,7 +3447,7 @@ test "zig fmt: usingnamespace" {
3444// \\3447// \\
3445// );3448// );
3446//}3449//}
3447//3450
3448//test "zig fmt: decimal float literals with underscore separators" {3451//test "zig fmt: decimal float literals with underscore separators" {
3449// try testTransform(3452// try testTransform(
3450// \\pub fn main() void {3453// \\pub fn main() void {
...@@ -3461,7 +3464,7 @@ test "zig fmt: usingnamespace" {...@@ -3461,7 +3464,7 @@ test "zig fmt: usingnamespace" {
3461// \\3464// \\
3462// );3465// );
3463//}3466//}
3464//3467
3465//test "zig fmt: hexadeciaml float literals with underscore separators" {3468//test "zig fmt: hexadeciaml float literals with underscore separators" {
3466// try testTransform(3469// try testTransform(
3467// \\pub fn main() void {3470// \\pub fn main() void {
...@@ -3478,34 +3481,14 @@ test "zig fmt: usingnamespace" {...@@ -3478,34 +3481,14 @@ test "zig fmt: usingnamespace" {
3478// \\3481// \\
3479// );3482// );
3480//}3483//}
3481//3484
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//
3502//test "zig fmt: C var args" {3485//test "zig fmt: C var args" {
3503// try testCanonical(3486// try testCanonical(
3504// \\pub extern "c" fn printf(format: [*:0]const u8, ...) c_int;3487// \\pub extern "c" fn printf(format: [*:0]const u8, ...) c_int;
3505// \\3488// \\
3506// );3489// );
3507//}3490//}
3508//3491
3509//test "zig fmt: Only indent multiline string literals in function calls" {3492//test "zig fmt: Only indent multiline string literals in function calls" {
3510// try testCanonical(3493// try testCanonical(
3511// \\test "zig fmt:" {3494// \\test "zig fmt:" {
...@@ -3522,7 +3505,7 @@ test "zig fmt: usingnamespace" {...@@ -3522,7 +3505,7 @@ test "zig fmt: usingnamespace" {
3522// \\3505// \\
3523// );3506// );
3524//}3507//}
3525//3508
3526//test "zig fmt: Don't add extra newline after if" {3509//test "zig fmt: Don't add extra newline after if" {
3527// try testCanonical(3510// try testCanonical(
3528// \\pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path: []const u8) !void {3511// \\pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path: []const u8) !void {
...@@ -3533,7 +3516,7 @@ test "zig fmt: usingnamespace" {...@@ -3533,7 +3516,7 @@ test "zig fmt: usingnamespace" {
3533// \\3516// \\
3534// );3517// );
3535//}3518//}
3536//3519
3537//test "zig fmt: comments in ternary ifs" {3520//test "zig fmt: comments in ternary ifs" {
3538// try testCanonical(3521// try testCanonical(
3539// \\const x = if (true) {3522// \\const x = if (true) {
...@@ -3611,7 +3594,7 @@ test "zig fmt: usingnamespace" {...@@ -3611,7 +3594,7 @@ test "zig fmt: usingnamespace" {
3611// \\3594// \\
3612// );3595// );
3613//}3596//}
3614//3597
3615//test "zig fmt: Control flow statement as body of blockless if" {3598//test "zig fmt: Control flow statement as body of blockless if" {
3616// try testCanonical(3599// try testCanonical(
3617// \\pub fn main() void {3600// \\pub fn main() void {
...@@ -3648,22 +3631,22 @@ test "zig fmt: usingnamespace" {...@@ -3648,22 +3631,22 @@ test "zig fmt: usingnamespace" {
3648// \\3631// \\
3649// );3632// );
3650//}3633//}
3651//3634
3652//test "zig fmt: " {3635test "zig fmt: regression test for #5722" {
3653// try testCanonical(3636 try testCanonical(
3654// \\pub fn sendViewTags(self: Self) void {3637 \\pub fn sendViewTags(self: Self) void {
3655// \\ var it = ViewStack(View).iterator(self.output.views.first, std.math.maxInt(u32));3638 \\ var it = ViewStack(View).iterator(self.output.views.first, std.math.maxInt(u32));
3656// \\ while (it.next()) |node|3639 \\ while (it.next()) |node|
3657// \\ view_tags.append(node.view.current_tags) catch {3640 \\ view_tags.append(node.view.current_tags) catch {
3658// \\ c.wl_resource_post_no_memory(self.wl_resource);3641 \\ c.wl_resource_post_no_memory(self.wl_resource);
3659// \\ log.crit(.river_status, "out of memory", .{});3642 \\ log.crit(.river_status, "out of memory", .{});
3660// \\ return;3643 \\ return;
3661// \\ };3644 \\ };
3662// \\}3645 \\}
3663// \\3646 \\
3664// );3647 );
3665//}3648}
3666//3649
3667//test "zig fmt: allow trailing line comments to do manual array formatting" {3650//test "zig fmt: allow trailing line comments to do manual array formatting" {
3668// try testCanonical(3651// try testCanonical(
3669// \\fn foo() void {3652// \\fn foo() void {
...@@ -3804,40 +3787,40 @@ test "zig fmt: usingnamespace" {...@@ -3804,40 +3787,40 @@ test "zig fmt: usingnamespace" {
3804// \\3787// \\
3805// );3788// );
3806//}3789//}
3807//3790
3808//test "zig fmt: single argument trailing commas in @builtins()" {3791test "zig fmt: single argument trailing commas in @builtins()" {
3809// try testCanonical(3792 try testCanonical(
3810// \\pub fn foo(qzz: []u8) i1 {3793 \\pub fn foo(qzz: []u8) i1 {
3811// \\ @panic(3794 \\ @panic(
3812// \\ foo,3795 \\ foo,
3813// \\ );3796 \\ );
3814// \\ panic(3797 \\ panic(
3815// \\ foo,3798 \\ foo,
3816// \\ );3799 \\ );
3817// \\ @panic(3800 \\ @panic(
3818// \\ foo,3801 \\ foo,
3819// \\ bar,3802 \\ bar,
3820// \\ );3803 \\ );
3821// \\}3804 \\}
3822// \\3805 \\
3823// );3806 );
3824//}3807}
3825//3808
3826//test "zig fmt: trailing comma should force multiline 1 column" {3809test "zig fmt: trailing comma should force multiline 1 column" {
3827// try testTransform(3810 try testTransform(
3828// \\pub const UUID_NULL: uuid_t = [16]u8{0,0,0,0,};3811 \\pub const UUID_NULL: uuid_t = [16]u8{0,0,0,0,};
3829// \\3812 \\
3830// ,3813 ,
3831// \\pub const UUID_NULL: uuid_t = [16]u8{3814 \\pub const UUID_NULL: uuid_t = [16]u8{
3832// \\ 0,3815 \\ 0,
3833// \\ 0,3816 \\ 0,
3834// \\ 0,3817 \\ 0,
3835// \\ 0,3818 \\ 0,
3836// \\};3819 \\};
3837// \\3820 \\
3838// );3821 );
3839//}3822}
3840//3823
3841//test "zig fmt: function params should align nicely" {3824//test "zig fmt: function params should align nicely" {
3842// try testCanonical(3825// try testCanonical(
3843// \\pub fn foo() void {3826// \\pub fn foo() void {
...@@ -3853,29 +3836,29 @@ test "zig fmt: usingnamespace" {...@@ -3853,29 +3836,29 @@ test "zig fmt: usingnamespace" {
3853// \\3836// \\
3854// );3837// );
3855//}3838//}
3856//3839
3857//test "recovery: top level" {3840test "recovery: top level" {
3858// try testError(3841 try testError(
3859// \\test "" {inline}3842 \\test "" {inline}
3860// \\test "" {inline}3843 \\test "" {inline}
3861// , &[_]Error{3844 , &[_]Error{
3862// .ExpectedInlinable,3845 .ExpectedInlinable,
3863// .ExpectedInlinable,3846 .ExpectedInlinable,
3864// });3847 });
3865//}3848}
3866//3849
3867//test "recovery: block statements" {3850test "recovery: block statements" {
3868// try testError(3851 try testError(
3869// \\test "" {3852 \\test "" {
3870// \\ foo + +;3853 \\ foo + +;
3871// \\ inline;3854 \\ inline;
3872// \\}3855 \\}
3873// , &[_]Error{3856 , &[_]Error{
3874// .InvalidToken,3857 .InvalidToken,
3875// .ExpectedInlinable,3858 .ExpectedInlinable,
3876// });3859 });
3877//}3860}
3878//3861
3879//test "recovery: missing comma" {3862//test "recovery: missing comma" {
3880// try testError(3863// try testError(
3881// \\test "" {3864// \\test "" {
...@@ -3894,17 +3877,17 @@ test "zig fmt: usingnamespace" {...@@ -3894,17 +3877,17 @@ test "zig fmt: usingnamespace" {
3894// .InvalidToken,3877// .InvalidToken,
3895// });3878// });
3896//}3879//}
3897//3880
3898//test "recovery: extra qualifier" {3881test "recovery: extra qualifier" {
3899// try testError(3882 try testError(
3900// \\const a: *const const u8;3883 \\const a: *const const u8;
3901// \\test ""3884 \\test ""
3902// , &[_]Error{3885 , &[_]Error{
3903// .ExtraConstQualifier,3886 .ExtraConstQualifier,
3904// .ExpectedLBrace,3887 .ExpectedLBrace,
3905// });3888 });
3906//}3889}
3907//3890
3908//test "recovery: missing return type" {3891//test "recovery: missing return type" {
3909// try testError(3892// try testError(
3910// \\fn foo() {3893// \\fn foo() {
...@@ -3917,7 +3900,7 @@ test "zig fmt: usingnamespace" {...@@ -3917,7 +3900,7 @@ test "zig fmt: usingnamespace" {
3917// .ExpectedLBrace,3900// .ExpectedLBrace,
3918// });3901// });
3919//}3902//}
3920//3903
3921//test "recovery: continue after invalid decl" {3904//test "recovery: continue after invalid decl" {
3922// try testError(3905// try testError(
3923// \\fn foo {3906// \\fn foo {
...@@ -3942,7 +3925,7 @@ test "zig fmt: usingnamespace" {...@@ -3942,7 +3925,7 @@ test "zig fmt: usingnamespace" {
3942// .InvalidAnd,3925// .InvalidAnd,
3943// });3926// });
3944//}3927//}
3945//3928
3946//test "recovery: invalid extern/inline" {3929//test "recovery: invalid extern/inline" {
3947// try testError(3930// try testError(
3948// \\inline test "" { a && b; }3931// \\inline test "" { a && b; }
...@@ -3957,7 +3940,7 @@ test "zig fmt: usingnamespace" {...@@ -3957,7 +3940,7 @@ test "zig fmt: usingnamespace" {
3957// .InvalidAnd,3940// .InvalidAnd,
3958// });3941// });
3959//}3942//}
3960//3943
3961//test "recovery: missing semicolon" {3944//test "recovery: missing semicolon" {
3962// try testError(3945// try testError(
3963// \\test "" {3946// \\test "" {
...@@ -3974,7 +3957,7 @@ test "zig fmt: usingnamespace" {...@@ -3974,7 +3957,7 @@ test "zig fmt: usingnamespace" {
3974// .ExpectedToken,3957// .ExpectedToken,
3975// });3958// });
3976//}3959//}
3977//3960
3978//test "recovery: invalid container members" {3961//test "recovery: invalid container members" {
3979// try testError(3962// try testError(
3980// \\usingnamespace;3963// \\usingnamespace;
...@@ -3993,7 +3976,7 @@ test "zig fmt: usingnamespace" {...@@ -3993,7 +3976,7 @@ test "zig fmt: usingnamespace" {
3993// .ExpectedToken,3976// .ExpectedToken,
3994// });3977// });
3995//}3978//}
3996//3979
3997//test "recovery: invalid parameter" {3980//test "recovery: invalid parameter" {
3998// try testError(3981// try testError(
3999// \\fn main() void {3982// \\fn main() void {
...@@ -4003,7 +3986,7 @@ test "zig fmt: usingnamespace" {...@@ -4003,7 +3986,7 @@ test "zig fmt: usingnamespace" {
4003// .ExpectedToken,3986// .ExpectedToken,
4004// });3987// });
4005//}3988//}
4006//3989
4007//test "recovery: extra '}' at top level" {3990//test "recovery: extra '}' at top level" {
4008// try testError(3991// try testError(
4009// \\}}}3992// \\}}}
...@@ -4018,16 +4001,16 @@ test "zig fmt: usingnamespace" {...@@ -4018,16 +4001,16 @@ test "zig fmt: usingnamespace" {
4018// });4001// });
4019//}4002//}
4020//4003//
4021//test "recovery: mismatched bracket at top level" {4004test "recovery: mismatched bracket at top level" {
4022// try testError(4005 try testError(
4023// \\const S = struct {4006 \\const S = struct {
4024// \\ arr: 128]?G4007 \\ arr: 128]?G
4025// \\};4008 \\};
4026// , &[_]Error{4009 , &[_]Error{
4027// .ExpectedToken,4010 .ExpectedToken,
4028// });4011 });
4029//}4012}
4030//4013
4031//test "recovery: invalid global error set access" {4014//test "recovery: invalid global error set access" {
4032// try testError(4015// try testError(
4033// \\test "" {4016// \\test "" {
...@@ -4039,7 +4022,7 @@ test "zig fmt: usingnamespace" {...@@ -4039,7 +4022,7 @@ test "zig fmt: usingnamespace" {
4039// .InvalidAnd,4022// .InvalidAnd,
4040// });4023// });
4041//}4024//}
4042//4025
4043//test "recovery: invalid asterisk after pointer dereference" {4026//test "recovery: invalid asterisk after pointer dereference" {
4044// try testError(4027// try testError(
4045// \\test "" {4028// \\test "" {
...@@ -4057,7 +4040,7 @@ test "zig fmt: usingnamespace" {...@@ -4057,7 +4040,7 @@ test "zig fmt: usingnamespace" {
4057// .InvalidAnd,4040// .InvalidAnd,
4058// });4041// });
4059//}4042//}
4060//4043
4061//test "recovery: missing semicolon after if, for, while stmt" {4044//test "recovery: missing semicolon after if, for, while stmt" {
4062// try testError(4045// try testError(
4063// \\test "" {4046// \\test "" {
...@@ -4073,27 +4056,27 @@ test "zig fmt: usingnamespace" {...@@ -4073,27 +4056,27 @@ test "zig fmt: usingnamespace" {
4073// .InvalidAnd,4056// .InvalidAnd,
4074// });4057// });
4075//}4058//}
4076//4059
4077//test "recovery: invalid comptime" {4060test "recovery: invalid comptime" {
4078// try testError(4061 try testError(
4079// \\comptime4062 \\comptime
4080// , &[_]Error{4063 , &[_]Error{
4081// .ExpectedBlockOrField,4064 .ExpectedBlockOrField,
4082// });4065 });
4083//}4066}
4084//4067
4085//test "recovery: missing block after for/while loops" {4068test "recovery: missing block after for/while loops" {
4086// try testError(4069 try testError(
4087// \\test "" { while (foo) }4070 \\test "" { while (foo) }
4088// , &[_]Error{4071 , &[_]Error{
4089// .ExpectedBlockOrAssignment,4072 .ExpectedBlockOrAssignment,
4090// });4073 });
4091// try testError(4074 try testError(
4092// \\test "" { for (foo) |bar| }4075 \\test "" { for (foo) |bar| }
4093// , &[_]Error{4076 , &[_]Error{
4094// .ExpectedBlockOrAssignment,4077 .ExpectedBlockOrAssignment,
4095// });4078 });
4096//}4079}
40974080
4098const std = @import("std");4081const std = @import("std");
4099const mem = std.mem;4082const 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...@@ -198,7 +198,11 @@ fn renderExpression(ais: *Ais, tree: ast.Tree, node: ast.Node.Index, space: Spac
198 .AnyFrameLiteral,198 .AnyFrameLiteral,
199 => return renderToken(ais, tree, main_tokens[node], space),199 => return renderToken(ais, tree, main_tokens[node], space),
200200
201 .ErrorValue => unreachable, // TODO201 .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
203 .AnyType => return renderToken(ais, tree, main_tokens[node], space),207 .AnyType => return renderToken(ais, tree, main_tokens[node], space),
204208