| ... | ... | @@ -757,14 +757,14 @@ test "zig fmt: tagged union with enum values" { |
| 757 | 757 | // \\ |
| 758 | 758 | // ); |
| 759 | 759 | //} |
| 760 | | // |
| 761 | | //test "zig fmt: enum literal" { |
| 762 | | // try testCanonical( |
| 763 | | // \\const x = .hi; |
| 764 | | // \\ |
| 765 | | // ); |
| 766 | | //} |
| 767 | | // |
| 760 | |
| 761 | test "zig fmt: enum literal" { |
| 762 | try testCanonical( |
| 763 | \\const x = .hi; |
| 764 | \\ |
| 765 | ); |
| 766 | } |
| 767 | |
| 768 | 768 | //test "zig fmt: enum literal inside array literal" { |
| 769 | 769 | // try testCanonical( |
| 770 | 770 | // \\test "enums in arrays" { |
| ... | ... | @@ -779,14 +779,14 @@ test "zig fmt: tagged union with enum values" { |
| 779 | 779 | // \\ |
| 780 | 780 | // ); |
| 781 | 781 | //} |
| 782 | | // |
| 783 | | //test "zig fmt: character literal larger than u8" { |
| 784 | | // try testCanonical( |
| 785 | | // \\const x = '\u{01f4a9}'; |
| 786 | | // \\ |
| 787 | | // ); |
| 788 | | //} |
| 789 | | // |
| 782 | |
| 783 | test "zig fmt: character literal larger than u8" { |
| 784 | try testCanonical( |
| 785 | \\const x = '\u{01f4a9}'; |
| 786 | \\ |
| 787 | ); |
| 788 | } |
| 789 | |
| 790 | 790 | //test "zig fmt: infix operator and then multiline string literal" { |
| 791 | 791 | // try testCanonical( |
| 792 | 792 | // \\const x = "" ++ |
| ... | ... | @@ -813,22 +813,22 @@ test "zig fmt: tagged union with enum values" { |
| 813 | 813 | // \\ |
| 814 | 814 | // ); |
| 815 | 815 | //} |
| 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 | |
| 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 | |
| 832 | 832 | //test "zig fmt: correctly move doc comments on struct fields" { |
| 833 | 833 | // try testTransform( |
| 834 | 834 | // \\pub const section_64 = extern struct { |
| ... | ... | @@ -895,22 +895,22 @@ test "zig fmt: tagged union with enum values" { |
| 895 | 895 | // \\ |
| 896 | 896 | // ); |
| 897 | 897 | //} |
| 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 | |
| 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 | |
| 914 | 914 | //test "zig fmt: comment to disable/enable zig fmt first" { |
| 915 | 915 | // try testCanonical( |
| 916 | 916 | // \\// Test trailing comma syntax |
| ... | ... | @@ -1040,32 +1040,32 @@ test "zig fmt: tagged union with enum values" { |
| 1040 | 1040 | // \\ |
| 1041 | 1041 | // ); |
| 1042 | 1042 | //} |
| 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 | |
| 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 | |
| 1069 | 1069 | //test "zig fmt: 2nd arg multiline string" { |
| 1070 | 1070 | // try testCanonical( |
| 1071 | 1071 | // \\comptime { |
| ... | ... | @@ -1300,64 +1300,64 @@ test "zig fmt: tagged union with enum values" { |
| 1300 | 1300 | // \\ |
| 1301 | 1301 | // ); |
| 1302 | 1302 | //} |
| 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 | |
| 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 | |
| 1361 | 1361 | //test "zig fmt: switch comment before prong" { |
| 1362 | 1362 | // try testCanonical( |
| 1363 | 1363 | // \\comptime { |
| ... | ... | @@ -1369,22 +1369,25 @@ test "zig fmt: tagged union with enum values" { |
| 1369 | 1369 | // \\ |
| 1370 | 1370 | // ); |
| 1371 | 1371 | //} |
| 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 | |
| 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 | \\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 | |
| 1388 | 1391 | //test "zig fmt: struct literal containing a multiline expression" { |
| 1389 | 1392 | // try testTransform( |
| 1390 | 1393 | // \\const a = A{ .x = if (f1()) 10 else 20 }; |
| ... | ... | @@ -1564,39 +1567,39 @@ test "zig fmt: tagged union with enum values" { |
| 1564 | 1567 | // \\ |
| 1565 | 1568 | // ); |
| 1566 | 1569 | //} |
| 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 | |
| 1571 | test "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 | |
| 1584 | test "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 | |
| 1600 | 1603 | //test "zig fmt: empty block with only comment" { |
| 1601 | 1604 | // try testCanonical( |
| 1602 | 1605 | // \\comptime { |
| ... | ... | @@ -1616,19 +1619,19 @@ test "zig fmt: tagged union with enum values" { |
| 1616 | 1619 | // \\ |
| 1617 | 1620 | // ); |
| 1618 | 1621 | //} |
| 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 | |
| 1623 | test "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 | |
| 1632 | 1635 | //test "zig fmt: simple asm" { |
| 1633 | 1636 | // try testTransform( |
| 1634 | 1637 | // \\comptime { |
| ... | ... | @@ -1704,15 +1707,15 @@ test "zig fmt: switch cases trailing comma" { |
| 1704 | 1707 | ); |
| 1705 | 1708 | } |
| 1706 | 1709 | |
| 1707 | | //test "zig fmt: slice align" { |
| 1708 | | // try testCanonical( |
| 1709 | | // \\const A = struct { |
| 1710 | | // \\ items: []align(A) T, |
| 1711 | | // \\}; |
| 1712 | | // \\ |
| 1713 | | // ); |
| 1714 | | //} |
| 1715 | | // |
| 1710 | test "zig fmt: slice align" { |
| 1711 | try testCanonical( |
| 1712 | \\const A = struct { |
| 1713 | \\ items: []align(A) T, |
| 1714 | \\}; |
| 1715 | \\ |
| 1716 | ); |
| 1717 | } |
| 1718 | |
| 1716 | 1719 | //test "zig fmt: add trailing comma to array literal" { |
| 1717 | 1720 | // try testTransform( |
| 1718 | 1721 | // \\comptime { |
| ... | ... | @@ -1756,29 +1759,29 @@ test "zig fmt: switch cases trailing comma" { |
| 1756 | 1759 | // \\ |
| 1757 | 1760 | // ); |
| 1758 | 1761 | //} |
| 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 | |
| 1763 | test "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 | |
| 1772 | test "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 | } |
| 1782 | 1785 | |
| 1783 | 1786 | test "zig fmt: float literal with exponent" { |
| 1784 | 1787 | try testCanonical( |
| ... | ... | @@ -1788,34 +1791,34 @@ test "zig fmt: float literal with exponent" { |
| 1788 | 1791 | ); |
| 1789 | 1792 | } |
| 1790 | 1793 | |
| 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 | | // |
| 1794 | test "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 | |
| 1807 | test "zig fmt: nested blocks" { |
| 1808 | try testCanonical( |
| 1809 | \\comptime { |
| 1810 | \\ { |
| 1811 | \\ { |
| 1812 | \\ { |
| 1813 | \\ a(); |
| 1814 | \\ } |
| 1815 | \\ } |
| 1816 | \\ } |
| 1817 | \\} |
| 1818 | \\ |
| 1819 | ); |
| 1820 | } |
| 1821 | |
| 1819 | 1822 | //test "zig fmt: block with same line comment after end brace" { |
| 1820 | 1823 | // try testCanonical( |
| 1821 | 1824 | // \\comptime { |
| ... | ... | @@ -1837,17 +1840,17 @@ test "zig fmt: float literal with exponent" { |
| 1837 | 1840 | // \\ |
| 1838 | 1841 | // ); |
| 1839 | 1842 | //} |
| 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 | |
| 1844 | test "zig fmt: statements with empty line between" { |
| 1845 | try testCanonical( |
| 1846 | \\comptime { |
| 1847 | \\ a = b; |
| 1848 | \\ |
| 1849 | \\ a = b; |
| 1850 | \\} |
| 1851 | \\ |
| 1852 | ); |
| 1853 | } |
| 1851 | 1854 | |
| 1852 | 1855 | test "zig fmt: ptr deref operator and unwrap optional operator" { |
| 1853 | 1856 | try testCanonical( |
| ... | ... | @@ -2119,18 +2122,18 @@ test "zig fmt: error set declaration" { |
| 2119 | 2122 | // \\ |
| 2120 | 2123 | // ); |
| 2121 | 2124 | //} |
| 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 | |
| 2126 | test "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 | } |
| 2134 | 2137 | |
| 2135 | 2138 | test "zig fmt: resume from suspend block" { |
| 2136 | 2139 | try testCanonical( |
| ... | ... | @@ -2270,15 +2273,15 @@ test "zig fmt: resume from suspend block" { |
| 2270 | 2273 | // \\ |
| 2271 | 2274 | // ); |
| 2272 | 2275 | //} |
| 2273 | | // |
| 2274 | | //test "zig fmt: imports" { |
| 2275 | | // try testCanonical( |
| 2276 | | // \\const std = @import("std"); |
| 2277 | | // \\const std = @import(); |
| 2278 | | // \\ |
| 2279 | | // ); |
| 2280 | | //} |
| 2281 | | // |
| 2276 | |
| 2277 | test "zig fmt: imports" { |
| 2278 | try testCanonical( |
| 2279 | \\const std = @import("std"); |
| 2280 | \\const std = @import(); |
| 2281 | \\ |
| 2282 | ); |
| 2283 | } |
| 2284 | |
| 2282 | 2285 | //test "zig fmt: global declarations" { |
| 2283 | 2286 | // try testCanonical( |
| 2284 | 2287 | // \\const a = b; |
| ... | ... | @@ -2300,21 +2303,21 @@ test "zig fmt: resume from suspend block" { |
| 2300 | 2303 | // \\ |
| 2301 | 2304 | // ); |
| 2302 | 2305 | //} |
| 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 | |
| 2307 | test "zig fmt: extern declaration" { |
| 2308 | try testCanonical( |
| 2309 | \\extern var foo: c_int; |
| 2310 | \\ |
| 2311 | ); |
| 2312 | } |
| 2313 | |
| 2314 | test "zig fmt: alignment" { |
| 2315 | try testCanonical( |
| 2316 | \\var foo: c_int align(1); |
| 2317 | \\ |
| 2318 | ); |
| 2319 | } |
| 2320 | |
| 2318 | 2321 | //test "zig fmt: C main" { |
| 2319 | 2322 | // try testCanonical( |
| 2320 | 2323 | // \\fn main(argc: c_int, argv: **u8) c_int { |
| ... | ... | @@ -2358,128 +2361,128 @@ test "zig fmt: resume from suspend block" { |
| 2358 | 2361 | // \\ |
| 2359 | 2362 | // ); |
| 2360 | 2363 | //} |
| 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 | |
| 2365 | test "zig fmt: test declaration" { |
| 2366 | try testCanonical( |
| 2367 | \\test "test name" { |
| 2368 | \\ const a = 1; |
| 2369 | \\ var b = 1; |
| 2370 | \\} |
| 2371 | \\ |
| 2372 | ); |
| 2373 | } |
| 2374 | |
| 2375 | test "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 | |
| 2427 | test "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 | |
| 2458 | test "zig fmt: prefix operators" { |
| 2459 | try testCanonical( |
| 2460 | \\test "prefix operators" { |
| 2461 | \\ try return --%~!&0; |
| 2462 | \\} |
| 2463 | \\ |
| 2464 | ); |
| 2465 | } |
| 2466 | |
| 2467 | test "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 | |
| 2476 | 2479 | //test "zig fmt: anytype type" { |
| 2477 | 2480 | // try testCanonical( |
| 2478 | 2481 | // \\fn print(args: anytype) anytype {} |
| 2479 | 2482 | // \\ |
| 2480 | 2483 | // ); |
| 2481 | 2484 | //} |
| 2482 | | // |
| 2485 | |
| 2483 | 2486 | //test "zig fmt: functions" { |
| 2484 | 2487 | // try testCanonical( |
| 2485 | 2488 | // \\extern fn puts(s: *const u8) c_int; |
| ... | ... | @@ -2500,7 +2503,7 @@ test "zig fmt: resume from suspend block" { |
| 2500 | 2503 | // \\ |
| 2501 | 2504 | // ); |
| 2502 | 2505 | //} |
| 2503 | | // |
| 2506 | |
| 2504 | 2507 | //test "zig fmt: multiline string" { |
| 2505 | 2508 | // try testCanonical( |
| 2506 | 2509 | // \\test "" { |
| ... | ... | @@ -2518,145 +2521,145 @@ test "zig fmt: resume from suspend block" { |
| 2518 | 2521 | // \\ |
| 2519 | 2522 | // ); |
| 2520 | 2523 | //} |
| 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 | |
| 2525 | test "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 | |
| 2544 | test "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 | |
| 2564 | test "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 | |
| 2595 | test "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 | |
| 2623 | test "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 | |
| 2660 | 2663 | //test "zig fmt: arrays" { |
| 2661 | 2664 | // try testCanonical( |
| 2662 | 2665 | // \\test "test array" { |
| ... | ... | @@ -2674,7 +2677,7 @@ test "zig fmt: resume from suspend block" { |
| 2674 | 2677 | // \\ |
| 2675 | 2678 | // ); |
| 2676 | 2679 | //} |
| 2677 | | // |
| 2680 | |
| 2678 | 2681 | //test "zig fmt: container initializers" { |
| 2679 | 2682 | // try testCanonical( |
| 2680 | 2683 | // \\const a0 = []u8{}; |
| ... | ... | @@ -2912,140 +2915,140 @@ test "zig fmt: for" { |
| 2912 | 2915 | ); |
| 2913 | 2916 | } |
| 2914 | 2917 | |
| 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 | | //} |
| 2918 | test "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 | |
| 2967 | test "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 | |
| 2987 | test "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 | |
| 3026 | test "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 | |
| 3039 | test "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 | } |
| 3049 | 3052 | |
| 3050 | 3053 | test "zig fmt: async functions" { |
| 3051 | 3054 | try testCanonical( |
| ... | ... | @@ -3070,67 +3073,67 @@ test "zig fmt: async functions" { |
| 3070 | 3073 | |
| 3071 | 3074 | test "zig fmt: nosuspend" { |
| 3072 | 3075 | try testCanonical( |
| 3073 | | \\const a = nosuspend foo(); |
| 3076 | \\const a = nosuspend foo(); |
| 3077 | \\ |
| 3078 | ); |
| 3079 | } |
| 3080 | |
| 3081 | test "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 | |
| 3096 | test "zig fmt: usingnamespace" { |
| 3097 | try testCanonical( |
| 3098 | \\usingnamespace @import("std"); |
| 3099 | \\pub usingnamespace @import("std"); |
| 3100 | \\ |
| 3101 | ); |
| 3102 | } |
| 3103 | |
| 3104 | test "zig fmt: string identifier" { |
| 3105 | try testCanonical( |
| 3106 | \\const @"a b" = @"c d".@"e f"; |
| 3107 | \\fn @"g h"() void {} |
| 3108 | \\ |
| 3109 | ); |
| 3110 | } |
| 3111 | |
| 3112 | test "zig fmt: error return" { |
| 3113 | try testCanonical( |
| 3114 | \\fn err() anyerror { |
| 3115 | \\ call(); |
| 3116 | \\ return error.InvalidArgs; |
| 3117 | \\} |
| 3074 | 3118 | \\ |
| 3075 | 3119 | ); |
| 3076 | 3120 | } |
| 3077 | 3121 | |
| 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 | | |
| 3093 | | test "zig fmt: usingnamespace" { |
| 3122 | test "zig fmt: comptime block in container" { |
| 3094 | 3123 | 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 | \\} |
| 3097 | 3133 | \\ |
| 3098 | 3134 | ); |
| 3099 | 3135 | } |
| 3100 | 3136 | |
| 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 | 3137 | //test "zig fmt: inline asm parameter alignment" { |
| 3135 | 3138 | // try testCanonical( |
| 3136 | 3139 | // \\pub fn main() void { |
| ... | ... | @@ -3171,7 +3174,7 @@ test "zig fmt: usingnamespace" { |
| 3171 | 3174 | // \\ |
| 3172 | 3175 | // ); |
| 3173 | 3176 | //} |
| 3174 | | // |
| 3177 | |
| 3175 | 3178 | //test "zig fmt: multiline string in array" { |
| 3176 | 3179 | // try testCanonical( |
| 3177 | 3180 | // \\const Foo = [][]const u8{ |
| ... | ... | @@ -3196,25 +3199,25 @@ test "zig fmt: usingnamespace" { |
| 3196 | 3199 | // \\ |
| 3197 | 3200 | // ); |
| 3198 | 3201 | //} |
| 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 | |
| 3203 | test "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 | } |
| 3214 | test "zig fmt: file ends with struct field" { |
| 3215 | try testCanonical( |
| 3216 | \\a: bool |
| 3217 | \\ |
| 3218 | ); |
| 3219 | } |
| 3220 | |
| 3218 | 3221 | //test "zig fmt: comment after empty comment" { |
| 3219 | 3222 | // try testTransform( |
| 3220 | 3223 | // \\const x = true; // |
| ... | ... | @@ -3342,7 +3345,7 @@ test "zig fmt: usingnamespace" { |
| 3342 | 3345 | // \\ |
| 3343 | 3346 | // ); |
| 3344 | 3347 | //} |
| 3345 | | // |
| 3348 | |
| 3346 | 3349 | //test "zig fmt: top level doc comments" { |
| 3347 | 3350 | // try testCanonical( |
| 3348 | 3351 | // \\//! tld 1 |
| ... | ... | @@ -3398,7 +3401,7 @@ test "zig fmt: usingnamespace" { |
| 3398 | 3401 | // \\ |
| 3399 | 3402 | // ); |
| 3400 | 3403 | //} |
| 3401 | | // |
| 3404 | |
| 3402 | 3405 | //test "zig fmt: extern without container keyword returns error" { |
| 3403 | 3406 | // try testError( |
| 3404 | 3407 | // \\const container = extern {}; |
| ... | ... | @@ -3408,20 +3411,20 @@ test "zig fmt: usingnamespace" { |
| 3408 | 3411 | // .ExpectedVarDeclOrFn, |
| 3409 | 3412 | // }); |
| 3410 | 3413 | //} |
| 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 | |
| 3415 | test "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 | |
| 3425 | 3428 | //test "zig fmt: hex literals with underscore separators" { |
| 3426 | 3429 | // try testTransform( |
| 3427 | 3430 | // \\pub fn orMask(a: [ 1_000 ]u64, b: [ 1_000] u64) [1_000]u64 { |
| ... | ... | @@ -3444,7 +3447,7 @@ test "zig fmt: usingnamespace" { |
| 3444 | 3447 | // \\ |
| 3445 | 3448 | // ); |
| 3446 | 3449 | //} |
| 3447 | | // |
| 3450 | |
| 3448 | 3451 | //test "zig fmt: decimal float literals with underscore separators" { |
| 3449 | 3452 | // try testTransform( |
| 3450 | 3453 | // \\pub fn main() void { |
| ... | ... | @@ -3461,7 +3464,7 @@ test "zig fmt: usingnamespace" { |
| 3461 | 3464 | // \\ |
| 3462 | 3465 | // ); |
| 3463 | 3466 | //} |
| 3464 | | // |
| 3467 | |
| 3465 | 3468 | //test "zig fmt: hexadeciaml float literals with underscore separators" { |
| 3466 | 3469 | // try testTransform( |
| 3467 | 3470 | // \\pub fn main() void { |
| ... | ... | @@ -3478,34 +3481,14 @@ test "zig fmt: usingnamespace" { |
| 3478 | 3481 | // \\ |
| 3479 | 3482 | // ); |
| 3480 | 3483 | //} |
| 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 | |
| 3502 | 3485 | //test "zig fmt: C var args" { |
| 3503 | 3486 | // try testCanonical( |
| 3504 | 3487 | // \\pub extern "c" fn printf(format: [*:0]const u8, ...) c_int; |
| 3505 | 3488 | // \\ |
| 3506 | 3489 | // ); |
| 3507 | 3490 | //} |
| 3508 | | // |
| 3491 | |
| 3509 | 3492 | //test "zig fmt: Only indent multiline string literals in function calls" { |
| 3510 | 3493 | // try testCanonical( |
| 3511 | 3494 | // \\test "zig fmt:" { |
| ... | ... | @@ -3522,7 +3505,7 @@ test "zig fmt: usingnamespace" { |
| 3522 | 3505 | // \\ |
| 3523 | 3506 | // ); |
| 3524 | 3507 | //} |
| 3525 | | // |
| 3508 | |
| 3526 | 3509 | //test "zig fmt: Don't add extra newline after if" { |
| 3527 | 3510 | // try testCanonical( |
| 3528 | 3511 | // \\pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path: []const u8) !void { |
| ... | ... | @@ -3533,7 +3516,7 @@ test "zig fmt: usingnamespace" { |
| 3533 | 3516 | // \\ |
| 3534 | 3517 | // ); |
| 3535 | 3518 | //} |
| 3536 | | // |
| 3519 | |
| 3537 | 3520 | //test "zig fmt: comments in ternary ifs" { |
| 3538 | 3521 | // try testCanonical( |
| 3539 | 3522 | // \\const x = if (true) { |
| ... | ... | @@ -3611,7 +3594,7 @@ test "zig fmt: usingnamespace" { |
| 3611 | 3594 | // \\ |
| 3612 | 3595 | // ); |
| 3613 | 3596 | //} |
| 3614 | | // |
| 3597 | |
| 3615 | 3598 | //test "zig fmt: Control flow statement as body of blockless if" { |
| 3616 | 3599 | // try testCanonical( |
| 3617 | 3600 | // \\pub fn main() void { |
| ... | ... | @@ -3648,22 +3631,22 @@ test "zig fmt: usingnamespace" { |
| 3648 | 3631 | // \\ |
| 3649 | 3632 | // ); |
| 3650 | 3633 | //} |
| 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 | |
| 3635 | test "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 | |
| 3667 | 3650 | //test "zig fmt: allow trailing line comments to do manual array formatting" { |
| 3668 | 3651 | // try testCanonical( |
| 3669 | 3652 | // \\fn foo() void { |
| ... | ... | @@ -3804,40 +3787,40 @@ test "zig fmt: usingnamespace" { |
| 3804 | 3787 | // \\ |
| 3805 | 3788 | // ); |
| 3806 | 3789 | //} |
| 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 | |
| 3791 | test "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 | |
| 3809 | test "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 | |
| 3841 | 3824 | //test "zig fmt: function params should align nicely" { |
| 3842 | 3825 | // try testCanonical( |
| 3843 | 3826 | // \\pub fn foo() void { |
| ... | ... | @@ -3853,29 +3836,29 @@ test "zig fmt: usingnamespace" { |
| 3853 | 3836 | // \\ |
| 3854 | 3837 | // ); |
| 3855 | 3838 | //} |
| 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 | |
| 3840 | test "recovery: top level" { |
| 3841 | try testError( |
| 3842 | \\test "" {inline} |
| 3843 | \\test "" {inline} |
| 3844 | , &[_]Error{ |
| 3845 | .ExpectedInlinable, |
| 3846 | .ExpectedInlinable, |
| 3847 | }); |
| 3848 | } |
| 3849 | |
| 3850 | test "recovery: block statements" { |
| 3851 | try testError( |
| 3852 | \\test "" { |
| 3853 | \\ foo + +; |
| 3854 | \\ inline; |
| 3855 | \\} |
| 3856 | , &[_]Error{ |
| 3857 | .InvalidToken, |
| 3858 | .ExpectedInlinable, |
| 3859 | }); |
| 3860 | } |
| 3861 | |
| 3879 | 3862 | //test "recovery: missing comma" { |
| 3880 | 3863 | // try testError( |
| 3881 | 3864 | // \\test "" { |
| ... | ... | @@ -3894,17 +3877,17 @@ test "zig fmt: usingnamespace" { |
| 3894 | 3877 | // .InvalidToken, |
| 3895 | 3878 | // }); |
| 3896 | 3879 | //} |
| 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 | |
| 3881 | test "recovery: extra qualifier" { |
| 3882 | try testError( |
| 3883 | \\const a: *const const u8; |
| 3884 | \\test "" |
| 3885 | , &[_]Error{ |
| 3886 | .ExtraConstQualifier, |
| 3887 | .ExpectedLBrace, |
| 3888 | }); |
| 3889 | } |
| 3890 | |
| 3908 | 3891 | //test "recovery: missing return type" { |
| 3909 | 3892 | // try testError( |
| 3910 | 3893 | // \\fn foo() { |
| ... | ... | @@ -3917,7 +3900,7 @@ test "zig fmt: usingnamespace" { |
| 3917 | 3900 | // .ExpectedLBrace, |
| 3918 | 3901 | // }); |
| 3919 | 3902 | //} |
| 3920 | | // |
| 3903 | |
| 3921 | 3904 | //test "recovery: continue after invalid decl" { |
| 3922 | 3905 | // try testError( |
| 3923 | 3906 | // \\fn foo { |
| ... | ... | @@ -3942,7 +3925,7 @@ test "zig fmt: usingnamespace" { |
| 3942 | 3925 | // .InvalidAnd, |
| 3943 | 3926 | // }); |
| 3944 | 3927 | //} |
| 3945 | | // |
| 3928 | |
| 3946 | 3929 | //test "recovery: invalid extern/inline" { |
| 3947 | 3930 | // try testError( |
| 3948 | 3931 | // \\inline test "" { a && b; } |
| ... | ... | @@ -3957,7 +3940,7 @@ test "zig fmt: usingnamespace" { |
| 3957 | 3940 | // .InvalidAnd, |
| 3958 | 3941 | // }); |
| 3959 | 3942 | //} |
| 3960 | | // |
| 3943 | |
| 3961 | 3944 | //test "recovery: missing semicolon" { |
| 3962 | 3945 | // try testError( |
| 3963 | 3946 | // \\test "" { |
| ... | ... | @@ -3974,7 +3957,7 @@ test "zig fmt: usingnamespace" { |
| 3974 | 3957 | // .ExpectedToken, |
| 3975 | 3958 | // }); |
| 3976 | 3959 | //} |
| 3977 | | // |
| 3960 | |
| 3978 | 3961 | //test "recovery: invalid container members" { |
| 3979 | 3962 | // try testError( |
| 3980 | 3963 | // \\usingnamespace; |
| ... | ... | @@ -3993,7 +3976,7 @@ test "zig fmt: usingnamespace" { |
| 3993 | 3976 | // .ExpectedToken, |
| 3994 | 3977 | // }); |
| 3995 | 3978 | //} |
| 3996 | | // |
| 3979 | |
| 3997 | 3980 | //test "recovery: invalid parameter" { |
| 3998 | 3981 | // try testError( |
| 3999 | 3982 | // \\fn main() void { |
| ... | ... | @@ -4003,7 +3986,7 @@ test "zig fmt: usingnamespace" { |
| 4003 | 3986 | // .ExpectedToken, |
| 4004 | 3987 | // }); |
| 4005 | 3988 | //} |
| 4006 | | // |
| 3989 | |
| 4007 | 3990 | //test "recovery: extra '}' at top level" { |
| 4008 | 3991 | // try testError( |
| 4009 | 3992 | // \\}}} |
| ... | ... | @@ -4018,16 +4001,16 @@ test "zig fmt: usingnamespace" { |
| 4018 | 4001 | // }); |
| 4019 | 4002 | //} |
| 4020 | 4003 | // |
| 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 | | // |
| 4004 | test "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 | |
| 4031 | 4014 | //test "recovery: invalid global error set access" { |
| 4032 | 4015 | // try testError( |
| 4033 | 4016 | // \\test "" { |
| ... | ... | @@ -4039,7 +4022,7 @@ test "zig fmt: usingnamespace" { |
| 4039 | 4022 | // .InvalidAnd, |
| 4040 | 4023 | // }); |
| 4041 | 4024 | //} |
| 4042 | | // |
| 4025 | |
| 4043 | 4026 | //test "recovery: invalid asterisk after pointer dereference" { |
| 4044 | 4027 | // try testError( |
| 4045 | 4028 | // \\test "" { |
| ... | ... | @@ -4057,7 +4040,7 @@ test "zig fmt: usingnamespace" { |
| 4057 | 4040 | // .InvalidAnd, |
| 4058 | 4041 | // }); |
| 4059 | 4042 | //} |
| 4060 | | // |
| 4043 | |
| 4061 | 4044 | //test "recovery: missing semicolon after if, for, while stmt" { |
| 4062 | 4045 | // try testError( |
| 4063 | 4046 | // \\test "" { |
| ... | ... | @@ -4073,27 +4056,27 @@ test "zig fmt: usingnamespace" { |
| 4073 | 4056 | // .InvalidAnd, |
| 4074 | 4057 | // }); |
| 4075 | 4058 | //} |
| 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 | |
| 4060 | test "recovery: invalid comptime" { |
| 4061 | try testError( |
| 4062 | \\comptime |
| 4063 | , &[_]Error{ |
| 4064 | .ExpectedBlockOrField, |
| 4065 | }); |
| 4066 | } |
| 4067 | |
| 4068 | test "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 | } |
| 4097 | 4080 | |
| 4098 | 4081 | const std = @import("std"); |
| 4099 | 4082 | const mem = std.mem; |