| ... | ... | @@ -663,7 +663,9 @@ test "zig fmt: anon list literal 3 element comma" { |
| 663 | 663 | \\test { |
| 664 | 664 | \\ const x = .{ |
| 665 | 665 | \\ a, |
| 666 | \\ // foo |
| 666 | 667 | \\ b, |
| 668 | \\ |
| 667 | 669 | \\ c, |
| 668 | 670 | \\ }; |
| 669 | 671 | \\} |
| ... | ... | @@ -874,20 +876,20 @@ test "zig fmt: enum literal" { |
| 874 | 876 | ); |
| 875 | 877 | } |
| 876 | 878 | |
| 877 | | //test "zig fmt: enum literal inside array literal" { |
| 878 | | // try testCanonical( |
| 879 | | // \\test "enums in arrays" { |
| 880 | | // \\ var colors = []Color{.Green}; |
| 881 | | // \\ colors = []Colors{ .Green, .Cyan }; |
| 882 | | // \\ colors = []Colors{ |
| 883 | | // \\ .Grey, |
| 884 | | // \\ .Green, |
| 885 | | // \\ .Cyan, |
| 886 | | // \\ }; |
| 887 | | // \\} |
| 888 | | // \\ |
| 889 | | // ); |
| 890 | | //} |
| 879 | test "zig fmt: enum literal inside array literal" { |
| 880 | try testCanonical( |
| 881 | \\test "enums in arrays" { |
| 882 | \\ var colors = []Color{.Green}; |
| 883 | \\ colors = []Colors{ .Green, .Cyan }; |
| 884 | \\ colors = []Colors{ |
| 885 | \\ .Grey, |
| 886 | \\ .Green, |
| 887 | \\ .Cyan, |
| 888 | \\ }; |
| 889 | \\} |
| 890 | \\ |
| 891 | ); |
| 892 | } |
| 891 | 893 | |
| 892 | 894 | test "zig fmt: character literal larger than u8" { |
| 893 | 895 | try testCanonical( |
| ... | ... | @@ -954,56 +956,56 @@ test "zig fmt: linksection" { |
| 954 | 956 | // \\ |
| 955 | 957 | // ); |
| 956 | 958 | //} |
| 957 | | // |
| 958 | | //test "zig fmt: correctly space struct fields with doc comments" { |
| 959 | | // try testTransform( |
| 960 | | // \\pub const S = struct { |
| 961 | | // \\ /// A |
| 962 | | // \\ a: u8, |
| 963 | | // \\ /// B |
| 964 | | // \\ /// B (cont) |
| 965 | | // \\ b: u8, |
| 966 | | // \\ |
| 967 | | // \\ |
| 968 | | // \\ /// C |
| 969 | | // \\ c: u8, |
| 970 | | // \\}; |
| 971 | | // \\ |
| 972 | | // , |
| 973 | | // \\pub const S = struct { |
| 974 | | // \\ /// A |
| 975 | | // \\ a: u8, |
| 976 | | // \\ /// B |
| 977 | | // \\ /// B (cont) |
| 978 | | // \\ b: u8, |
| 979 | | // \\ |
| 980 | | // \\ /// C |
| 981 | | // \\ c: u8, |
| 982 | | // \\}; |
| 983 | | // \\ |
| 984 | | // ); |
| 985 | | //} |
| 986 | | // |
| 987 | | //test "zig fmt: doc comments on param decl" { |
| 988 | | // try testCanonical( |
| 989 | | // \\pub const Allocator = struct { |
| 990 | | // \\ shrinkFn: fn ( |
| 991 | | // \\ self: *Allocator, |
| 992 | | // \\ /// Guaranteed to be the same as what was returned from most recent call to |
| 993 | | // \\ /// `allocFn`, `reallocFn`, or `shrinkFn`. |
| 994 | | // \\ old_mem: []u8, |
| 995 | | // \\ /// Guaranteed to be the same as what was returned from most recent call to |
| 996 | | // \\ /// `allocFn`, `reallocFn`, or `shrinkFn`. |
| 997 | | // \\ old_alignment: u29, |
| 998 | | // \\ /// Guaranteed to be less than or equal to `old_mem.len`. |
| 999 | | // \\ new_byte_count: usize, |
| 1000 | | // \\ /// Guaranteed to be less than or equal to `old_alignment`. |
| 1001 | | // \\ new_alignment: u29, |
| 1002 | | // \\ ) []u8, |
| 1003 | | // \\}; |
| 1004 | | // \\ |
| 1005 | | // ); |
| 1006 | | //} |
| 959 | |
| 960 | test "zig fmt: correctly space struct fields with doc comments" { |
| 961 | try testTransform( |
| 962 | \\pub const S = struct { |
| 963 | \\ /// A |
| 964 | \\ a: u8, |
| 965 | \\ /// B |
| 966 | \\ /// B (cont) |
| 967 | \\ b: u8, |
| 968 | \\ |
| 969 | \\ |
| 970 | \\ /// C |
| 971 | \\ c: u8, |
| 972 | \\}; |
| 973 | \\ |
| 974 | , |
| 975 | \\pub const S = struct { |
| 976 | \\ /// A |
| 977 | \\ a: u8, |
| 978 | \\ /// B |
| 979 | \\ /// B (cont) |
| 980 | \\ b: u8, |
| 981 | \\ |
| 982 | \\ /// C |
| 983 | \\ c: u8, |
| 984 | \\}; |
| 985 | \\ |
| 986 | ); |
| 987 | } |
| 988 | |
| 989 | test "zig fmt: doc comments on param decl" { |
| 990 | try testCanonical( |
| 991 | \\pub const Allocator = struct { |
| 992 | \\ shrinkFn: fn ( |
| 993 | \\ self: *Allocator, |
| 994 | \\ /// Guaranteed to be the same as what was returned from most recent call to |
| 995 | \\ /// `allocFn`, `reallocFn`, or `shrinkFn`. |
| 996 | \\ old_mem: []u8, |
| 997 | \\ /// Guaranteed to be the same as what was returned from most recent call to |
| 998 | \\ /// `allocFn`, `reallocFn`, or `shrinkFn`. |
| 999 | \\ old_alignment: u29, |
| 1000 | \\ /// Guaranteed to be less than or equal to `old_mem.len`. |
| 1001 | \\ new_byte_count: usize, |
| 1002 | \\ /// Guaranteed to be less than or equal to `old_alignment`. |
| 1003 | \\ new_alignment: u29, |
| 1004 | \\ ) []u8, |
| 1005 | \\}; |
| 1006 | \\ |
| 1007 | ); |
| 1008 | } |
| 1007 | 1009 | |
| 1008 | 1010 | test "zig fmt: aligned struct field" { |
| 1009 | 1011 | try testCanonical( |
| ... | ... | @@ -1142,13 +1144,13 @@ test "zig fmt: aligned struct field" { |
| 1142 | 1144 | // \\ |
| 1143 | 1145 | // ); |
| 1144 | 1146 | //} |
| 1145 | | // |
| 1146 | | //test "zig fmt: pointer of unknown length" { |
| 1147 | | // try testCanonical( |
| 1148 | | // \\fn foo(ptr: [*]u8) void {} |
| 1149 | | // \\ |
| 1150 | | // ); |
| 1151 | | //} |
| 1147 | |
| 1148 | test "zig fmt: pointer of unknown length" { |
| 1149 | try testCanonical( |
| 1150 | \\fn foo(ptr: [*]u8) void {} |
| 1151 | \\ |
| 1152 | ); |
| 1153 | } |
| 1152 | 1154 | |
| 1153 | 1155 | test "zig fmt: spaces around slice operator" { |
| 1154 | 1156 | try testCanonical( |
| ... | ... | @@ -1370,25 +1372,25 @@ test "zig fmt: async call in if condition" { |
| 1370 | 1372 | // \\ |
| 1371 | 1373 | // ); |
| 1372 | 1374 | //} |
| 1373 | | // |
| 1374 | | //test "zig fmt: if-else with comment before else" { |
| 1375 | | // try testCanonical( |
| 1376 | | // \\comptime { |
| 1377 | | // \\ // cexp(finite|nan +- i inf|nan) = nan + i nan |
| 1378 | | // \\ if ((hx & 0x7fffffff) != 0x7f800000) { |
| 1379 | | // \\ return Complex(f32).new(y - y, y - y); |
| 1380 | | // \\ } // cexp(-inf +- i inf|nan) = 0 + i0 |
| 1381 | | // \\ else if (hx & 0x80000000 != 0) { |
| 1382 | | // \\ return Complex(f32).new(0, 0); |
| 1383 | | // \\ } // cexp(+inf +- i inf|nan) = inf + i nan |
| 1384 | | // \\ else { |
| 1385 | | // \\ return Complex(f32).new(x, y - y); |
| 1386 | | // \\ } |
| 1387 | | // \\} |
| 1388 | | // \\ |
| 1389 | | // ); |
| 1390 | | //} |
| 1391 | | // |
| 1375 | |
| 1376 | test "zig fmt: if-else with comment before else" { |
| 1377 | try testCanonical( |
| 1378 | \\comptime { |
| 1379 | \\ // cexp(finite|nan +- i inf|nan) = nan + i nan |
| 1380 | \\ if ((hx & 0x7fffffff) != 0x7f800000) { |
| 1381 | \\ return Complex(f32).new(y - y, y - y); |
| 1382 | \\ } // cexp(-inf +- i inf|nan) = 0 + i0 |
| 1383 | \\ else if (hx & 0x80000000 != 0) { |
| 1384 | \\ return Complex(f32).new(0, 0); |
| 1385 | \\ } // cexp(+inf +- i inf|nan) = inf + i nan |
| 1386 | \\ else { |
| 1387 | \\ return Complex(f32).new(x, y - y); |
| 1388 | \\ } |
| 1389 | \\} |
| 1390 | \\ |
| 1391 | ); |
| 1392 | } |
| 1393 | |
| 1392 | 1394 | //test "zig fmt: if nested" { |
| 1393 | 1395 | // try testCanonical( |
| 1394 | 1396 | // \\pub fn foo() void { |
| ... | ... | @@ -1467,17 +1469,17 @@ test "zig fmt: enum decl with no trailing comma" { |
| 1467 | 1469 | ); |
| 1468 | 1470 | } |
| 1469 | 1471 | |
| 1470 | | //test "zig fmt: switch comment before prong" { |
| 1471 | | // try testCanonical( |
| 1472 | | // \\comptime { |
| 1473 | | // \\ switch (a) { |
| 1474 | | // \\ // hi |
| 1475 | | // \\ 0 => {}, |
| 1476 | | // \\ } |
| 1477 | | // \\} |
| 1478 | | // \\ |
| 1479 | | // ); |
| 1480 | | //} |
| 1472 | test "zig fmt: switch comment before prong" { |
| 1473 | try testCanonical( |
| 1474 | \\comptime { |
| 1475 | \\ switch (a) { |
| 1476 | \\ // hi |
| 1477 | \\ 0 => {}, |
| 1478 | \\ } |
| 1479 | \\} |
| 1480 | \\ |
| 1481 | ); |
| 1482 | } |
| 1481 | 1483 | |
| 1482 | 1484 | test "zig fmt: struct literal no trailing comma" { |
| 1483 | 1485 | try testTransform( |
| ... | ... | @@ -1709,17 +1711,17 @@ test "zig fmt: multi line arguments without last comma" { |
| 1709 | 1711 | ); |
| 1710 | 1712 | } |
| 1711 | 1713 | |
| 1712 | | //test "zig fmt: empty block with only comment" { |
| 1713 | | // try testCanonical( |
| 1714 | | // \\comptime { |
| 1715 | | // \\ { |
| 1716 | | // \\ // comment |
| 1717 | | // \\ } |
| 1718 | | // \\} |
| 1719 | | // \\ |
| 1720 | | // ); |
| 1721 | | //} |
| 1722 | | // |
| 1714 | test "zig fmt: empty block with only comment" { |
| 1715 | try testCanonical( |
| 1716 | \\comptime { |
| 1717 | \\ { |
| 1718 | \\ // comment |
| 1719 | \\ } |
| 1720 | \\} |
| 1721 | \\ |
| 1722 | ); |
| 1723 | } |
| 1724 | |
| 1723 | 1725 | //test "zig fmt: no trailing comma on struct decl" { |
| 1724 | 1726 | // try testCanonical( |
| 1725 | 1727 | // \\const RoundParam = struct { |
| ... | ... | @@ -1781,15 +1783,15 @@ test "zig fmt: extra newlines at the end" { |
| 1781 | 1783 | // \\ |
| 1782 | 1784 | // ); |
| 1783 | 1785 | //} |
| 1784 | | // |
| 1785 | | //test "zig fmt: nested struct literal with one item" { |
| 1786 | | // try testCanonical( |
| 1787 | | // \\const a = foo{ |
| 1788 | | // \\ .item = bar{ .a = b }, |
| 1789 | | // \\}; |
| 1790 | | // \\ |
| 1791 | | // ); |
| 1792 | | //} |
| 1786 | |
| 1787 | test "zig fmt: nested struct literal with one item" { |
| 1788 | try testCanonical( |
| 1789 | \\const a = foo{ |
| 1790 | \\ .item = bar{ .a = b }, |
| 1791 | \\}; |
| 1792 | \\ |
| 1793 | ); |
| 1794 | } |
| 1793 | 1795 | |
| 1794 | 1796 | test "zig fmt: switch cases trailing comma" { |
| 1795 | 1797 | try testTransform( |
| ... | ... | @@ -1848,26 +1850,26 @@ test "zig fmt: slice align" { |
| 1848 | 1850 | // \\ |
| 1849 | 1851 | // ); |
| 1850 | 1852 | //} |
| 1851 | | // |
| 1852 | | //test "zig fmt: first thing in file is line comment" { |
| 1853 | | // try testCanonical( |
| 1854 | | // \\// Introspection and determination of system libraries needed by zig. |
| 1855 | | // \\ |
| 1856 | | // \\// Introspection and determination of system libraries needed by zig. |
| 1857 | | // \\ |
| 1858 | | // \\const std = @import("std"); |
| 1859 | | // \\ |
| 1860 | | // ); |
| 1861 | | //} |
| 1862 | | // |
| 1863 | | //test "zig fmt: line comment after doc comment" { |
| 1864 | | // try testCanonical( |
| 1865 | | // \\/// doc comment |
| 1866 | | // \\// line comment |
| 1867 | | // \\fn foo() void {} |
| 1868 | | // \\ |
| 1869 | | // ); |
| 1870 | | //} |
| 1853 | |
| 1854 | test "zig fmt: first thing in file is line comment" { |
| 1855 | try testCanonical( |
| 1856 | \\// Introspection and determination of system libraries needed by zig. |
| 1857 | \\ |
| 1858 | \\// Introspection and determination of system libraries needed by zig. |
| 1859 | \\ |
| 1860 | \\const std = @import("std"); |
| 1861 | \\ |
| 1862 | ); |
| 1863 | } |
| 1864 | |
| 1865 | test "zig fmt: line comment after doc comment" { |
| 1866 | try testCanonical( |
| 1867 | \\/// doc comment |
| 1868 | \\// line comment |
| 1869 | \\fn foo() void {} |
| 1870 | \\ |
| 1871 | ); |
| 1872 | } |
| 1871 | 1873 | |
| 1872 | 1874 | test "zig fmt: bit field alignment" { |
| 1873 | 1875 | try testCanonical( |
| ... | ... | @@ -1928,27 +1930,27 @@ test "zig fmt: nested blocks" { |
| 1928 | 1930 | ); |
| 1929 | 1931 | } |
| 1930 | 1932 | |
| 1931 | | //test "zig fmt: block with same line comment after end brace" { |
| 1932 | | // try testCanonical( |
| 1933 | | // \\comptime { |
| 1934 | | // \\ { |
| 1935 | | // \\ b(); |
| 1936 | | // \\ } // comment |
| 1937 | | // \\} |
| 1938 | | // \\ |
| 1939 | | // ); |
| 1940 | | //} |
| 1941 | | // |
| 1942 | | //test "zig fmt: statements with comment between" { |
| 1943 | | // try testCanonical( |
| 1944 | | // \\comptime { |
| 1945 | | // \\ a = b; |
| 1946 | | // \\ // comment |
| 1947 | | // \\ a = b; |
| 1948 | | // \\} |
| 1949 | | // \\ |
| 1950 | | // ); |
| 1951 | | //} |
| 1933 | test "zig fmt: block with same line comment after end brace" { |
| 1934 | try testCanonical( |
| 1935 | \\comptime { |
| 1936 | \\ { |
| 1937 | \\ b(); |
| 1938 | \\ } // comment |
| 1939 | \\} |
| 1940 | \\ |
| 1941 | ); |
| 1942 | } |
| 1943 | |
| 1944 | test "zig fmt: statements with comment between" { |
| 1945 | try testCanonical( |
| 1946 | \\comptime { |
| 1947 | \\ a = b; |
| 1948 | \\ // comment |
| 1949 | \\ a = b; |
| 1950 | \\} |
| 1951 | \\ |
| 1952 | ); |
| 1953 | } |
| 1952 | 1954 | |
| 1953 | 1955 | test "zig fmt: statements with empty line between" { |
| 1954 | 1956 | try testCanonical( |
| ... | ... | @@ -1969,60 +1971,60 @@ test "zig fmt: ptr deref operator and unwrap optional operator" { |
| 1969 | 1971 | ); |
| 1970 | 1972 | } |
| 1971 | 1973 | |
| 1972 | | //test "zig fmt: comment after if before another if" { |
| 1973 | | // try testCanonical( |
| 1974 | | // \\test "aoeu" { |
| 1975 | | // \\ // comment |
| 1976 | | // \\ if (x) { |
| 1977 | | // \\ bar(); |
| 1978 | | // \\ } |
| 1979 | | // \\} |
| 1980 | | // \\ |
| 1981 | | // \\test "aoeu" { |
| 1982 | | // \\ if (x) { |
| 1983 | | // \\ foo(); |
| 1984 | | // \\ } |
| 1985 | | // \\ // comment |
| 1986 | | // \\ if (x) { |
| 1987 | | // \\ bar(); |
| 1988 | | // \\ } |
| 1989 | | // \\} |
| 1990 | | // \\ |
| 1991 | | // ); |
| 1992 | | //} |
| 1993 | | // |
| 1994 | | //test "zig fmt: line comment between if block and else keyword" { |
| 1995 | | // try testCanonical( |
| 1996 | | // \\test "aoeu" { |
| 1997 | | // \\ // cexp(finite|nan +- i inf|nan) = nan + i nan |
| 1998 | | // \\ if ((hx & 0x7fffffff) != 0x7f800000) { |
| 1999 | | // \\ return Complex(f32).new(y - y, y - y); |
| 2000 | | // \\ } |
| 2001 | | // \\ // cexp(-inf +- i inf|nan) = 0 + i0 |
| 2002 | | // \\ else if (hx & 0x80000000 != 0) { |
| 2003 | | // \\ return Complex(f32).new(0, 0); |
| 2004 | | // \\ } |
| 2005 | | // \\ // cexp(+inf +- i inf|nan) = inf + i nan |
| 2006 | | // \\ // another comment |
| 2007 | | // \\ else { |
| 2008 | | // \\ return Complex(f32).new(x, y - y); |
| 2009 | | // \\ } |
| 2010 | | // \\} |
| 2011 | | // \\ |
| 2012 | | // ); |
| 2013 | | //} |
| 2014 | | // |
| 2015 | | //test "zig fmt: same line comments in expression" { |
| 2016 | | // try testCanonical( |
| 2017 | | // \\test "aoeu" { |
| 2018 | | // \\ const x = ( // a |
| 2019 | | // \\ 0 // b |
| 2020 | | // \\ ); // c |
| 2021 | | // \\} |
| 2022 | | // \\ |
| 2023 | | // ); |
| 2024 | | //} |
| 2025 | | // |
| 1974 | test "zig fmt: comment after if before another if" { |
| 1975 | try testCanonical( |
| 1976 | \\test "aoeu" { |
| 1977 | \\ // comment |
| 1978 | \\ if (x) { |
| 1979 | \\ bar(); |
| 1980 | \\ } |
| 1981 | \\} |
| 1982 | \\ |
| 1983 | \\test "aoeu" { |
| 1984 | \\ if (x) { |
| 1985 | \\ foo(); |
| 1986 | \\ } |
| 1987 | \\ // comment |
| 1988 | \\ if (x) { |
| 1989 | \\ bar(); |
| 1990 | \\ } |
| 1991 | \\} |
| 1992 | \\ |
| 1993 | ); |
| 1994 | } |
| 1995 | |
| 1996 | test "zig fmt: line comment between if block and else keyword" { |
| 1997 | try testCanonical( |
| 1998 | \\test "aoeu" { |
| 1999 | \\ // cexp(finite|nan +- i inf|nan) = nan + i nan |
| 2000 | \\ if ((hx & 0x7fffffff) != 0x7f800000) { |
| 2001 | \\ return Complex(f32).new(y - y, y - y); |
| 2002 | \\ } |
| 2003 | \\ // cexp(-inf +- i inf|nan) = 0 + i0 |
| 2004 | \\ else if (hx & 0x80000000 != 0) { |
| 2005 | \\ return Complex(f32).new(0, 0); |
| 2006 | \\ } |
| 2007 | \\ // cexp(+inf +- i inf|nan) = inf + i nan |
| 2008 | \\ // another comment |
| 2009 | \\ else { |
| 2010 | \\ return Complex(f32).new(x, y - y); |
| 2011 | \\ } |
| 2012 | \\} |
| 2013 | \\ |
| 2014 | ); |
| 2015 | } |
| 2016 | |
| 2017 | test "zig fmt: same line comments in expression" { |
| 2018 | try testCanonical( |
| 2019 | \\test "aoeu" { |
| 2020 | \\ const x = ( // a |
| 2021 | \\ 0 // b |
| 2022 | \\ ); // c |
| 2023 | \\} |
| 2024 | \\ |
| 2025 | ); |
| 2026 | } |
| 2027 | |
| 2026 | 2028 | //test "zig fmt: add comma on last switch prong" { |
| 2027 | 2029 | // try testTransform( |
| 2028 | 2030 | // \\test "aoeu" { |
| ... | ... | @@ -2051,127 +2053,126 @@ test "zig fmt: ptr deref operator and unwrap optional operator" { |
| 2051 | 2053 | // \\ |
| 2052 | 2054 | // ); |
| 2053 | 2055 | //} |
| 2054 | | // |
| 2055 | | //test "zig fmt: same-line comment after a statement" { |
| 2056 | | // try testCanonical( |
| 2057 | | // \\test "" { |
| 2058 | | // \\ a = b; |
| 2059 | | // \\ debug.assert(H.digest_size <= H.block_size); // HMAC makes this assumption |
| 2060 | | // \\ a = b; |
| 2061 | | // \\} |
| 2062 | | // \\ |
| 2063 | | // ); |
| 2064 | | //} |
| 2065 | | // |
| 2066 | | //test "zig fmt: same-line comment after var decl in struct" { |
| 2067 | | // try testCanonical( |
| 2068 | | // \\pub const vfs_cap_data = extern struct { |
| 2069 | | // \\ const Data = struct {}; // when on disk. |
| 2070 | | // \\}; |
| 2071 | | // \\ |
| 2072 | | // ); |
| 2073 | | //} |
| 2074 | | // |
| 2075 | | //test "zig fmt: same-line comment after field decl" { |
| 2076 | | // try testCanonical( |
| 2077 | | // \\pub const dirent = extern struct { |
| 2078 | | // \\ d_name: u8, |
| 2079 | | // \\ d_name: u8, // comment 1 |
| 2080 | | // \\ d_name: u8, |
| 2081 | | // \\ d_name: u8, // comment 2 |
| 2082 | | // \\ d_name: u8, |
| 2083 | | // \\}; |
| 2084 | | // \\ |
| 2085 | | // ); |
| 2086 | | //} |
| 2087 | | // |
| 2088 | | //test "zig fmt: same-line comment after switch prong" { |
| 2089 | | // try testCanonical( |
| 2090 | | // \\test "" { |
| 2091 | | // \\ switch (err) { |
| 2092 | | // \\ error.PathAlreadyExists => {}, // comment 2 |
| 2093 | | // \\ else => return err, // comment 1 |
| 2094 | | // \\ } |
| 2095 | | // \\} |
| 2096 | | // \\ |
| 2097 | | // ); |
| 2098 | | //} |
| 2099 | | // |
| 2100 | | //test "zig fmt: same-line comment after non-block if expression" { |
| 2101 | | // try testCanonical( |
| 2102 | | // \\comptime { |
| 2103 | | // \\ if (sr > n_uword_bits - 1) // d > r |
| 2104 | | // \\ return 0; |
| 2105 | | // \\} |
| 2106 | | // \\ |
| 2107 | | // ); |
| 2108 | | //} |
| 2109 | | // |
| 2110 | | //test "zig fmt: same-line comment on comptime expression" { |
| 2111 | | // try testCanonical( |
| 2112 | | // \\test "" { |
| 2113 | | // \\ comptime assert(@typeInfo(T) == .Int); // must pass an integer to absInt |
| 2114 | | // \\} |
| 2115 | | // \\ |
| 2116 | | // ); |
| 2117 | | //} |
| 2118 | 2056 | |
| 2119 | | test "zig fmt: switch with empty body" { |
| 2057 | test "zig fmt: same-line comment after a statement" { |
| 2058 | try testCanonical( |
| 2059 | \\test "" { |
| 2060 | \\ a = b; |
| 2061 | \\ debug.assert(H.digest_size <= H.block_size); // HMAC makes this assumption |
| 2062 | \\ a = b; |
| 2063 | \\} |
| 2064 | \\ |
| 2065 | ); |
| 2066 | } |
| 2067 | |
| 2068 | test "zig fmt: same-line comment after var decl in struct" { |
| 2069 | try testCanonical( |
| 2070 | \\pub const vfs_cap_data = extern struct { |
| 2071 | \\ const Data = struct {}; // when on disk. |
| 2072 | \\}; |
| 2073 | \\ |
| 2074 | ); |
| 2075 | } |
| 2076 | |
| 2077 | test "zig fmt: same-line comment after field decl" { |
| 2078 | try testCanonical( |
| 2079 | \\pub const dirent = extern struct { |
| 2080 | \\ d_name: u8, |
| 2081 | \\ d_name: u8, // comment 1 |
| 2082 | \\ d_name: u8, |
| 2083 | \\ d_name: u8, // comment 2 |
| 2084 | \\ d_name: u8, |
| 2085 | \\}; |
| 2086 | \\ |
| 2087 | ); |
| 2088 | } |
| 2089 | |
| 2090 | test "zig fmt: same-line comment after switch prong" { |
| 2091 | try testCanonical( |
| 2092 | \\test "" { |
| 2093 | \\ switch (err) { |
| 2094 | \\ error.PathAlreadyExists => {}, // comment 2 |
| 2095 | \\ else => return err, // comment 1 |
| 2096 | \\ } |
| 2097 | \\} |
| 2098 | \\ |
| 2099 | ); |
| 2100 | } |
| 2101 | |
| 2102 | test "zig fmt: same-line comment after non-block if expression" { |
| 2103 | try testCanonical( |
| 2104 | \\comptime { |
| 2105 | \\ if (sr > n_uword_bits - 1) // d > r |
| 2106 | \\ return 0; |
| 2107 | \\} |
| 2108 | \\ |
| 2109 | ); |
| 2110 | } |
| 2111 | |
| 2112 | test "zig fmt: same-line comment on comptime expression" { |
| 2113 | try testCanonical( |
| 2114 | \\test "" { |
| 2115 | \\ comptime assert(@typeInfo(T) == .Int); // must pass an integer to absInt |
| 2116 | \\} |
| 2117 | \\ |
| 2118 | ); |
| 2119 | } |
| 2120 | |
| 2121 | test "zig fmt: switch with empty body" { |
| 2122 | try testCanonical( |
| 2123 | \\test "" { |
| 2124 | \\ foo() catch |err| switch (err) {}; |
| 2125 | \\} |
| 2126 | \\ |
| 2127 | ); |
| 2128 | } |
| 2129 | |
| 2130 | test "zig fmt: line comments in struct initializer" { |
| 2131 | try testCanonical( |
| 2132 | \\fn foo() void { |
| 2133 | \\ return Self{ |
| 2134 | \\ .a = b, |
| 2135 | \\ |
| 2136 | \\ // Initialize these two fields to buffer_size so that |
| 2137 | \\ // in `readFn` we treat the state as being able to read |
| 2138 | \\ .start_index = buffer_size, |
| 2139 | \\ .end_index = buffer_size, |
| 2140 | \\ |
| 2141 | \\ // middle |
| 2142 | \\ |
| 2143 | \\ .a = b, |
| 2144 | \\ |
| 2145 | \\ // end |
| 2146 | \\ }; |
| 2147 | \\} |
| 2148 | \\ |
| 2149 | ); |
| 2150 | } |
| 2151 | |
| 2152 | test "zig fmt: first line comment in struct initializer" { |
| 2120 | 2153 | try testCanonical( |
| 2121 | | \\test "" { |
| 2122 | | \\ foo() catch |err| switch (err) {}; |
| 2154 | \\pub fn acquire(self: *Self) HeldLock { |
| 2155 | \\ return HeldLock{ |
| 2156 | \\ // guaranteed allocation elision |
| 2157 | \\ .held = self.lock.acquire(), |
| 2158 | \\ .value = &self.private_data, |
| 2159 | \\ }; |
| 2123 | 2160 | \\} |
| 2124 | 2161 | \\ |
| 2125 | 2162 | ); |
| 2126 | 2163 | } |
| 2127 | 2164 | |
| 2128 | | //test "zig fmt: line comments in struct initializer" { |
| 2129 | | // try testCanonical( |
| 2130 | | // \\fn foo() void { |
| 2131 | | // \\ return Self{ |
| 2132 | | // \\ .a = b, |
| 2133 | | // \\ |
| 2134 | | // \\ // Initialize these two fields to buffer_size so that |
| 2135 | | // \\ // in `readFn` we treat the state as being able to read |
| 2136 | | // \\ .start_index = buffer_size, |
| 2137 | | // \\ .end_index = buffer_size, |
| 2138 | | // \\ |
| 2139 | | // \\ // middle |
| 2140 | | // \\ |
| 2141 | | // \\ .a = b, |
| 2142 | | // \\ |
| 2143 | | // \\ // end |
| 2144 | | // \\ }; |
| 2145 | | // \\} |
| 2146 | | // \\ |
| 2147 | | // ); |
| 2148 | | //} |
| 2149 | | // |
| 2150 | | //test "zig fmt: first line comment in struct initializer" { |
| 2151 | | // try testCanonical( |
| 2152 | | // \\pub fn acquire(self: *Self) HeldLock { |
| 2153 | | // \\ return HeldLock{ |
| 2154 | | // \\ // guaranteed allocation elision |
| 2155 | | // \\ .held = self.lock.acquire(), |
| 2156 | | // \\ .value = &self.private_data, |
| 2157 | | // \\ }; |
| 2158 | | // \\} |
| 2159 | | // \\ |
| 2160 | | // ); |
| 2161 | | //} |
| 2162 | | // |
| 2163 | | //test "zig fmt: doc comments before struct field" { |
| 2164 | | // try testCanonical( |
| 2165 | | // \\pub const Allocator = struct { |
| 2166 | | // \\ /// Allocate byte_count bytes and return them in a slice, with the |
| 2167 | | // \\ /// slice's pointer aligned at least to alignment bytes. |
| 2168 | | // \\ allocFn: fn () void, |
| 2169 | | // \\}; |
| 2170 | | // \\ |
| 2171 | | // ); |
| 2172 | | //} |
| 2165 | test "zig fmt: doc comments before struct field" { |
| 2166 | try testCanonical( |
| 2167 | \\pub const Allocator = struct { |
| 2168 | \\ /// Allocate byte_count bytes and return them in a slice, with the |
| 2169 | \\ /// slice's pointer aligned at least to alignment bytes. |
| 2170 | \\ allocFn: fn () void, |
| 2171 | \\}; |
| 2172 | \\ |
| 2173 | ); |
| 2174 | } |
| 2173 | 2175 | |
| 2174 | | // TODO: replace this with the next test case when possible |
| 2175 | 2176 | test "zig fmt: error set declaration" { |
| 2176 | 2177 | try testCanonical( |
| 2177 | 2178 | \\const E = error{ |
| ... | ... | @@ -2180,58 +2181,30 @@ test "zig fmt: error set declaration" { |
| 2180 | 2181 | \\ |
| 2181 | 2182 | \\ C, |
| 2182 | 2183 | \\}; |
| 2184 | \\ |
| 2183 | 2185 | \\const Error = error{ |
| 2184 | 2186 | \\ /// no more memory |
| 2185 | 2187 | \\ OutOfMemory, |
| 2186 | 2188 | \\}; |
| 2189 | \\ |
| 2187 | 2190 | \\const Error = error{ |
| 2188 | 2191 | \\ /// no more memory |
| 2189 | 2192 | \\ OutOfMemory, |
| 2190 | 2193 | \\ |
| 2191 | 2194 | \\ /// another |
| 2192 | 2195 | \\ Another, |
| 2193 | | \\ /// and one more |
| 2194 | | \\ Another, |
| 2196 | \\ |
| 2197 | \\ // end |
| 2195 | 2198 | \\}; |
| 2199 | \\ |
| 2196 | 2200 | \\const Error = error{OutOfMemory}; |
| 2197 | 2201 | \\const Error = error{}; |
| 2202 | \\ |
| 2198 | 2203 | \\const Error = error{ OutOfMemory, OutOfTime }; |
| 2199 | 2204 | \\ |
| 2200 | 2205 | ); |
| 2201 | 2206 | } |
| 2202 | 2207 | |
| 2203 | | //test "zig fmt: error set declaration" { |
| 2204 | | // try testCanonical( |
| 2205 | | // \\const E = error{ |
| 2206 | | // \\ A, |
| 2207 | | // \\ B, |
| 2208 | | // \\ |
| 2209 | | // \\ C, |
| 2210 | | // \\}; |
| 2211 | | // \\ |
| 2212 | | // \\const Error = error{ |
| 2213 | | // \\ /// no more memory |
| 2214 | | // \\ OutOfMemory, |
| 2215 | | // \\}; |
| 2216 | | // \\ |
| 2217 | | // \\const Error = error{ |
| 2218 | | // \\ /// no more memory |
| 2219 | | // \\ OutOfMemory, |
| 2220 | | // \\ |
| 2221 | | // \\ /// another |
| 2222 | | // \\ Another, |
| 2223 | | // \\ |
| 2224 | | // \\ // end |
| 2225 | | // \\}; |
| 2226 | | // \\ |
| 2227 | | // \\const Error = error{OutOfMemory}; |
| 2228 | | // \\const Error = error{}; |
| 2229 | | // \\ |
| 2230 | | // \\const Error = error{ OutOfMemory, OutOfTime }; |
| 2231 | | // \\ |
| 2232 | | // ); |
| 2233 | | //} |
| 2234 | | |
| 2235 | 2208 | test "zig fmt: union(enum(u32)) with assigned enum values" { |
| 2236 | 2209 | try testCanonical( |
| 2237 | 2210 | \\const MultipleChoice = union(enum(u32)) { |
| ... | ... | @@ -2255,110 +2228,110 @@ test "zig fmt: resume from suspend block" { |
| 2255 | 2228 | ); |
| 2256 | 2229 | } |
| 2257 | 2230 | |
| 2258 | | //test "zig fmt: comments before error set decl" { |
| 2259 | | // try testCanonical( |
| 2260 | | // \\const UnexpectedError = error{ |
| 2261 | | // \\ /// The Operating System returned an undocumented error code. |
| 2262 | | // \\ Unexpected, |
| 2263 | | // \\ // another |
| 2264 | | // \\ Another, |
| 2265 | | // \\ |
| 2266 | | // \\ // in between |
| 2267 | | // \\ |
| 2268 | | // \\ // at end |
| 2269 | | // \\}; |
| 2270 | | // \\ |
| 2271 | | // ); |
| 2272 | | //} |
| 2273 | | // |
| 2274 | | //test "zig fmt: comments before switch prong" { |
| 2275 | | // try testCanonical( |
| 2276 | | // \\test "" { |
| 2277 | | // \\ switch (err) { |
| 2278 | | // \\ error.PathAlreadyExists => continue, |
| 2279 | | // \\ |
| 2280 | | // \\ // comment 1 |
| 2281 | | // \\ |
| 2282 | | // \\ // comment 2 |
| 2283 | | // \\ else => return err, |
| 2284 | | // \\ // at end |
| 2285 | | // \\ } |
| 2286 | | // \\} |
| 2287 | | // \\ |
| 2288 | | // ); |
| 2289 | | //} |
| 2290 | | // |
| 2291 | | //test "zig fmt: comments before var decl in struct" { |
| 2292 | | // try testCanonical( |
| 2293 | | // \\pub const vfs_cap_data = extern struct { |
| 2294 | | // \\ // All of these are mandated as little endian |
| 2295 | | // \\ // when on disk. |
| 2296 | | // \\ const Data = struct { |
| 2297 | | // \\ permitted: u32, |
| 2298 | | // \\ inheritable: u32, |
| 2299 | | // \\ }; |
| 2300 | | // \\ |
| 2301 | | // \\ // in between |
| 2302 | | // \\ |
| 2303 | | // \\ /// All of these are mandated as little endian |
| 2304 | | // \\ /// when on disk. |
| 2305 | | // \\ const Data = struct { |
| 2306 | | // \\ permitted: u32, |
| 2307 | | // \\ inheritable: u32, |
| 2308 | | // \\ }; |
| 2309 | | // \\ |
| 2310 | | // \\ // at end |
| 2311 | | // \\}; |
| 2312 | | // \\ |
| 2313 | | // ); |
| 2314 | | //} |
| 2315 | | // |
| 2316 | | //test "zig fmt: array literal with 1 item on 1 line" { |
| 2317 | | // try testCanonical( |
| 2318 | | // \\var s = []const u64{0} ** 25; |
| 2319 | | // \\ |
| 2320 | | // ); |
| 2321 | | //} |
| 2322 | | // |
| 2323 | | //test "zig fmt: comments before global variables" { |
| 2324 | | // try testCanonical( |
| 2325 | | // \\/// Foo copies keys and values before they go into the map, and |
| 2326 | | // \\/// frees them when they get removed. |
| 2327 | | // \\pub const Foo = struct {}; |
| 2328 | | // \\ |
| 2329 | | // ); |
| 2330 | | //} |
| 2331 | | // |
| 2332 | | //test "zig fmt: comments in statements" { |
| 2333 | | // try testCanonical( |
| 2334 | | // \\test "std" { |
| 2335 | | // \\ // statement comment |
| 2336 | | // \\ _ = @import("foo/bar.zig"); |
| 2337 | | // \\ |
| 2338 | | // \\ // middle |
| 2339 | | // \\ // middle2 |
| 2340 | | // \\ |
| 2341 | | // \\ // end |
| 2342 | | // \\} |
| 2343 | | // \\ |
| 2344 | | // ); |
| 2345 | | //} |
| 2346 | | // |
| 2347 | | //test "zig fmt: comments before test decl" { |
| 2348 | | // try testCanonical( |
| 2349 | | // \\/// top level doc comment |
| 2350 | | // \\test "hi" {} |
| 2351 | | // \\ |
| 2352 | | // \\// top level normal comment |
| 2353 | | // \\test "hi" {} |
| 2354 | | // \\ |
| 2355 | | // \\// middle |
| 2356 | | // \\ |
| 2357 | | // \\// end |
| 2358 | | // \\ |
| 2359 | | // ); |
| 2360 | | //} |
| 2361 | | // |
| 2231 | test "zig fmt: comments before error set decl" { |
| 2232 | try testCanonical( |
| 2233 | \\const UnexpectedError = error{ |
| 2234 | \\ /// The Operating System returned an undocumented error code. |
| 2235 | \\ Unexpected, |
| 2236 | \\ // another |
| 2237 | \\ Another, |
| 2238 | \\ |
| 2239 | \\ // in between |
| 2240 | \\ |
| 2241 | \\ // at end |
| 2242 | \\}; |
| 2243 | \\ |
| 2244 | ); |
| 2245 | } |
| 2246 | |
| 2247 | test "zig fmt: comments before switch prong" { |
| 2248 | try testCanonical( |
| 2249 | \\test "" { |
| 2250 | \\ switch (err) { |
| 2251 | \\ error.PathAlreadyExists => continue, |
| 2252 | \\ |
| 2253 | \\ // comment 1 |
| 2254 | \\ |
| 2255 | \\ // comment 2 |
| 2256 | \\ else => return err, |
| 2257 | \\ // at end |
| 2258 | \\ } |
| 2259 | \\} |
| 2260 | \\ |
| 2261 | ); |
| 2262 | } |
| 2263 | |
| 2264 | test "zig fmt: comments before var decl in struct" { |
| 2265 | try testCanonical( |
| 2266 | \\pub const vfs_cap_data = extern struct { |
| 2267 | \\ // All of these are mandated as little endian |
| 2268 | \\ // when on disk. |
| 2269 | \\ const Data = struct { |
| 2270 | \\ permitted: u32, |
| 2271 | \\ inheritable: u32, |
| 2272 | \\ }; |
| 2273 | \\ |
| 2274 | \\ // in between |
| 2275 | \\ |
| 2276 | \\ /// All of these are mandated as little endian |
| 2277 | \\ /// when on disk. |
| 2278 | \\ const Data = struct { |
| 2279 | \\ permitted: u32, |
| 2280 | \\ inheritable: u32, |
| 2281 | \\ }; |
| 2282 | \\ |
| 2283 | \\ // at end |
| 2284 | \\}; |
| 2285 | \\ |
| 2286 | ); |
| 2287 | } |
| 2288 | |
| 2289 | test "zig fmt: array literal with 1 item on 1 line" { |
| 2290 | try testCanonical( |
| 2291 | \\var s = []const u64{0} ** 25; |
| 2292 | \\ |
| 2293 | ); |
| 2294 | } |
| 2295 | |
| 2296 | test "zig fmt: comments before global variables" { |
| 2297 | try testCanonical( |
| 2298 | \\/// Foo copies keys and values before they go into the map, and |
| 2299 | \\/// frees them when they get removed. |
| 2300 | \\pub const Foo = struct {}; |
| 2301 | \\ |
| 2302 | ); |
| 2303 | } |
| 2304 | |
| 2305 | test "zig fmt: comments in statements" { |
| 2306 | try testCanonical( |
| 2307 | \\test "std" { |
| 2308 | \\ // statement comment |
| 2309 | \\ _ = @import("foo/bar.zig"); |
| 2310 | \\ |
| 2311 | \\ // middle |
| 2312 | \\ // middle2 |
| 2313 | \\ |
| 2314 | \\ // end |
| 2315 | \\} |
| 2316 | \\ |
| 2317 | ); |
| 2318 | } |
| 2319 | |
| 2320 | test "zig fmt: comments before test decl" { |
| 2321 | try testCanonical( |
| 2322 | \\/// top level doc comment |
| 2323 | \\test "hi" {} |
| 2324 | \\ |
| 2325 | \\// top level normal comment |
| 2326 | \\test "hi" {} |
| 2327 | \\ |
| 2328 | \\// middle |
| 2329 | \\ |
| 2330 | \\// end |
| 2331 | \\ |
| 2332 | ); |
| 2333 | } |
| 2334 | |
| 2362 | 2335 | //test "zig fmt: preserve spacing" { |
| 2363 | 2336 | // try testCanonical( |
| 2364 | 2337 | // \\const std = @import("std"); |
| ... | ... | @@ -2373,7 +2346,7 @@ test "zig fmt: resume from suspend block" { |
| 2373 | 2346 | // \\ |
| 2374 | 2347 | // ); |
| 2375 | 2348 | //} |
| 2376 | | // |
| 2349 | |
| 2377 | 2350 | //test "zig fmt: return types" { |
| 2378 | 2351 | // try testCanonical( |
| 2379 | 2352 | // \\pub fn main() !void {} |
| ... | ... | @@ -2798,43 +2771,43 @@ test "zig fmt: union declaration" { |
| 2798 | 2771 | ); |
| 2799 | 2772 | } |
| 2800 | 2773 | |
| 2801 | | //test "zig fmt: arrays" { |
| 2802 | | // try testCanonical( |
| 2803 | | // \\test "test array" { |
| 2804 | | // \\ const a: [2]u8 = [2]u8{ |
| 2805 | | // \\ 1, |
| 2806 | | // \\ 2, |
| 2807 | | // \\ }; |
| 2808 | | // \\ const a: [2]u8 = []u8{ |
| 2809 | | // \\ 1, |
| 2810 | | // \\ 2, |
| 2811 | | // \\ }; |
| 2812 | | // \\ const a: [0]u8 = []u8{}; |
| 2813 | | // \\ const x: [4:0]u8 = undefined; |
| 2814 | | // \\} |
| 2815 | | // \\ |
| 2816 | | // ); |
| 2817 | | //} |
| 2774 | test "zig fmt: arrays" { |
| 2775 | try testCanonical( |
| 2776 | \\test "test array" { |
| 2777 | \\ const a: [2]u8 = [2]u8{ |
| 2778 | \\ 1, |
| 2779 | \\ 2, |
| 2780 | \\ }; |
| 2781 | \\ const a: [2]u8 = []u8{ |
| 2782 | \\ 1, |
| 2783 | \\ 2, |
| 2784 | \\ }; |
| 2785 | \\ const a: [0]u8 = []u8{}; |
| 2786 | \\ const x: [4:0]u8 = undefined; |
| 2787 | \\} |
| 2788 | \\ |
| 2789 | ); |
| 2790 | } |
| 2818 | 2791 | |
| 2819 | | //test "zig fmt: container initializers" { |
| 2820 | | // try testCanonical( |
| 2821 | | // \\const a0 = []u8{}; |
| 2822 | | // \\const a1 = []u8{1}; |
| 2823 | | // \\const a2 = []u8{ |
| 2824 | | // \\ 1, |
| 2825 | | // \\ 2, |
| 2826 | | // \\ 3, |
| 2827 | | // \\ 4, |
| 2828 | | // \\}; |
| 2829 | | // \\const s0 = S{}; |
| 2830 | | // \\const s1 = S{ .a = 1 }; |
| 2831 | | // \\const s2 = S{ |
| 2832 | | // \\ .a = 1, |
| 2833 | | // \\ .b = 2, |
| 2834 | | // \\}; |
| 2835 | | // \\ |
| 2836 | | // ); |
| 2837 | | //} |
| 2792 | test "zig fmt: container initializers" { |
| 2793 | try testCanonical( |
| 2794 | \\const a0 = []u8{}; |
| 2795 | \\const a1 = []u8{1}; |
| 2796 | \\const a2 = []u8{ |
| 2797 | \\ 1, |
| 2798 | \\ 2, |
| 2799 | \\ 3, |
| 2800 | \\ 4, |
| 2801 | \\}; |
| 2802 | \\const s0 = S{}; |
| 2803 | \\const s1 = S{ .a = 1 }; |
| 2804 | \\const s2 = S{ |
| 2805 | \\ .a = 1, |
| 2806 | \\ .b = 2, |
| 2807 | \\}; |
| 2808 | \\ |
| 2809 | ); |
| 2810 | } |
| 2838 | 2811 | |
| 2839 | 2812 | test "zig fmt: catch" { |
| 2840 | 2813 | try testCanonical( |
| ... | ... | @@ -3563,62 +3536,62 @@ test "zig fmt: integer literals with underscore separators" { |
| 3563 | 3536 | ); |
| 3564 | 3537 | } |
| 3565 | 3538 | |
| 3566 | | //test "zig fmt: hex literals with underscore separators" { |
| 3567 | | // try testTransform( |
| 3568 | | // \\pub fn orMask(a: [ 1_000 ]u64, b: [ 1_000] u64) [1_000]u64 { |
| 3569 | | // \\ var c: [1_000]u64 = [1]u64{ 0xFFFF_FFFF_FFFF_FFFF}**1_000; |
| 3570 | | // \\ for (c [ 0_0 .. ]) |_, i| { |
| 3571 | | // \\ c[i] = (a[i] | b[i]) & 0xCCAA_CCAA_CCAA_CCAA; |
| 3572 | | // \\ } |
| 3573 | | // \\ return c; |
| 3574 | | // \\} |
| 3575 | | // \\ |
| 3576 | | // \\ |
| 3577 | | // , |
| 3578 | | // \\pub fn orMask(a: [1_000]u64, b: [1_000]u64) [1_000]u64 { |
| 3579 | | // \\ var c: [1_000]u64 = [1]u64{0xFFFF_FFFF_FFFF_FFFF} ** 1_000; |
| 3580 | | // \\ for (c[0_0..]) |_, i| { |
| 3581 | | // \\ c[i] = (a[i] | b[i]) & 0xCCAA_CCAA_CCAA_CCAA; |
| 3582 | | // \\ } |
| 3583 | | // \\ return c; |
| 3584 | | // \\} |
| 3585 | | // \\ |
| 3586 | | // ); |
| 3587 | | //} |
| 3539 | test "zig fmt: hex literals with underscore separators" { |
| 3540 | try testTransform( |
| 3541 | \\pub fn orMask(a: [ 1_000 ]u64, b: [ 1_000] u64) [1_000]u64 { |
| 3542 | \\ var c: [1_000]u64 = [1]u64{ 0xFFFF_FFFF_FFFF_FFFF}**1_000; |
| 3543 | \\ for (c [ 0_0 .. ]) |_, i| { |
| 3544 | \\ c[i] = (a[i] | b[i]) & 0xCCAA_CCAA_CCAA_CCAA; |
| 3545 | \\ } |
| 3546 | \\ return c; |
| 3547 | \\} |
| 3548 | \\ |
| 3549 | \\ |
| 3550 | , |
| 3551 | \\pub fn orMask(a: [1_000]u64, b: [1_000]u64) [1_000]u64 { |
| 3552 | \\ var c: [1_000]u64 = [1]u64{0xFFFF_FFFF_FFFF_FFFF} ** 1_000; |
| 3553 | \\ for (c[0_0..]) |_, i| { |
| 3554 | \\ c[i] = (a[i] | b[i]) & 0xCCAA_CCAA_CCAA_CCAA; |
| 3555 | \\ } |
| 3556 | \\ return c; |
| 3557 | \\} |
| 3558 | \\ |
| 3559 | ); |
| 3560 | } |
| 3588 | 3561 | |
| 3589 | | //test "zig fmt: decimal float literals with underscore separators" { |
| 3590 | | // try testTransform( |
| 3591 | | // \\pub fn main() void { |
| 3592 | | // \\ const a:f64=(10.0e-0+(10.e+0))+10_00.00_00e-2+00_00.00_10e+4; |
| 3593 | | // \\ const b:f64=010.0--0_10.+0_1_0.0_0+1e2; |
| 3594 | | // \\ std.debug.warn("a: {}, b: {} -> a+b: {}\n", .{ a, b, a + b }); |
| 3595 | | // \\} |
| 3596 | | // , |
| 3597 | | // \\pub fn main() void { |
| 3598 | | // \\ const a: f64 = (10.0e-0 + (10.e+0)) + 10_00.00_00e-2 + 00_00.00_10e+4; |
| 3599 | | // \\ const b: f64 = 010.0 - -0_10. + 0_1_0.0_0 + 1e2; |
| 3600 | | // \\ std.debug.warn("a: {}, b: {} -> a+b: {}\n", .{ a, b, a + b }); |
| 3601 | | // \\} |
| 3602 | | // \\ |
| 3603 | | // ); |
| 3604 | | //} |
| 3562 | test "zig fmt: decimal float literals with underscore separators" { |
| 3563 | try testTransform( |
| 3564 | \\pub fn main() void { |
| 3565 | \\ const a:f64=(10.0e-0+(10.e+0))+10_00.00_00e-2+00_00.00_10e+4; |
| 3566 | \\ const b:f64=010.0--0_10.+0_1_0.0_0+1e2; |
| 3567 | \\ std.debug.warn("a: {}, b: {} -> a+b: {}\n", .{ a, b, a + b }); |
| 3568 | \\} |
| 3569 | , |
| 3570 | \\pub fn main() void { |
| 3571 | \\ const a: f64 = (10.0e-0 + (10.e+0)) + 10_00.00_00e-2 + 00_00.00_10e+4; |
| 3572 | \\ const b: f64 = 010.0 - -0_10. + 0_1_0.0_0 + 1e2; |
| 3573 | \\ std.debug.warn("a: {}, b: {} -> a+b: {}\n", .{ a, b, a + b }); |
| 3574 | \\} |
| 3575 | \\ |
| 3576 | ); |
| 3577 | } |
| 3605 | 3578 | |
| 3606 | | //test "zig fmt: hexadeciaml float literals with underscore separators" { |
| 3607 | | // try testTransform( |
| 3608 | | // \\pub fn main() void { |
| 3609 | | // \\ const a: f64 = (0x10.0p-0+(0x10.p+0))+0x10_00.00_00p-8+0x00_00.00_10p+16; |
| 3610 | | // \\ const b: f64 = 0x0010.0--0x00_10.+0x10.00+0x1p4; |
| 3611 | | // \\ std.debug.warn("a: {}, b: {} -> a+b: {}\n", .{ a, b, a + b }); |
| 3612 | | // \\} |
| 3613 | | // , |
| 3614 | | // \\pub fn main() void { |
| 3615 | | // \\ const a: f64 = (0x10.0p-0 + (0x10.p+0)) + 0x10_00.00_00p-8 + 0x00_00.00_10p+16; |
| 3616 | | // \\ const b: f64 = 0x0010.0 - -0x00_10. + 0x10.00 + 0x1p4; |
| 3617 | | // \\ std.debug.warn("a: {}, b: {} -> a+b: {}\n", .{ a, b, a + b }); |
| 3618 | | // \\} |
| 3619 | | // \\ |
| 3620 | | // ); |
| 3621 | | //} |
| 3579 | test "zig fmt: hexadeciaml float literals with underscore separators" { |
| 3580 | try testTransform( |
| 3581 | \\pub fn main() void { |
| 3582 | \\ const a: f64 = (0x10.0p-0+(0x10.p+0))+0x10_00.00_00p-8+0x00_00.00_10p+16; |
| 3583 | \\ const b: f64 = 0x0010.0--0x00_10.+0x10.00+0x1p4; |
| 3584 | \\ std.debug.warn("a: {}, b: {} -> a+b: {}\n", .{ a, b, a + b }); |
| 3585 | \\} |
| 3586 | , |
| 3587 | \\pub fn main() void { |
| 3588 | \\ const a: f64 = (0x10.0p-0 + (0x10.p+0)) + 0x10_00.00_00p-8 + 0x00_00.00_10p+16; |
| 3589 | \\ const b: f64 = 0x0010.0 - -0x00_10. + 0x10.00 + 0x1p4; |
| 3590 | \\ std.debug.warn("a: {}, b: {} -> a+b: {}\n", .{ a, b, a + b }); |
| 3591 | \\} |
| 3592 | \\ |
| 3593 | ); |
| 3594 | } |
| 3622 | 3595 | |
| 3623 | 3596 | //test "zig fmt: C var args" { |
| 3624 | 3597 | // try testCanonical( |