| ... | @@ -1648,6 +1648,13 @@ test "zig fmt" { | ... | @@ -1648,6 +1648,13 @@ test "zig fmt" { |
| 1648 | \\ | 1648 | \\ |
| 1649 | ); | 1649 | ); |
| 1650 | | 1650 | |
| | 1651 | try testCanonical( |
| | 1652 | \\extern fn f1(s: [][]align(1) []const []volatile u8) c_int; |
| | 1653 | \\extern fn f2(s: []align(1) const []align(1) volatile []const volatile u8) c_int; |
| | 1654 | \\extern fn f3(s: []align(1) const volatile u8) c_int; |
| | 1655 | \\ |
| | 1656 | ); |
| | 1657 | |
| 1651 | try testCanonical( | 1658 | try testCanonical( |
| 1652 | \\fn f1(a: bool, b: bool) bool { | 1659 | \\fn f1(a: bool, b: bool) bool { |
| 1653 | \\ a != b; | 1660 | \\ a != b; |
| ... | @@ -1716,7 +1723,7 @@ test "zig fmt" { | ... | @@ -1716,7 +1723,7 @@ test "zig fmt" { |
| 1716 | | 1723 | |
| 1717 | try testCanonical( | 1724 | try testCanonical( |
| 1718 | \\test "prefix operators" { | 1725 | \\test "prefix operators" { |
| 1719 | \\ --%~??!*&0; | 1726 | \\ try return --%~??!*&0; |
| 1720 | \\} | 1727 | \\} |
| 1721 | \\ | 1728 | \\ |
| 1722 | ); | 1729 | ); |
| ... | @@ -1730,4 +1737,145 @@ test "zig fmt" { | ... | @@ -1730,4 +1737,145 @@ test "zig fmt" { |
| 1730 | \\} | 1737 | \\} |
| 1731 | \\ | 1738 | \\ |
| 1732 | ); | 1739 | ); |
| | 1740 | |
| | 1741 | try testCanonical( |
| | 1742 | \\test "test index" { |
| | 1743 | \\ a[0]; |
| | 1744 | \\ a[0 + 5]; |
| | 1745 | \\ a[0..]; |
| | 1746 | \\ a[0..5]; |
| | 1747 | \\} |
| | 1748 | \\ |
| | 1749 | ); |
| | 1750 | |
| | 1751 | try testCanonical( |
| | 1752 | \\test "test array" { |
| | 1753 | \\ const a : [2]u8 = [2]u8{ 1, 2 }; |
| | 1754 | \\ const a : [2]u8 = []u8{ 1, 2 }; |
| | 1755 | \\ const a : [0]u8 = []u8{}; |
| | 1756 | \\} |
| | 1757 | \\ |
| | 1758 | ); |
| | 1759 | |
| | 1760 | // PrimaryExpression = Integer | Float | String | CharLiteral | KeywordLiteral | GroupedExpression | BlockExpression(BlockOrExpression) | Symbol | ("@" Symbol FnCallExpression) | ArrayType | FnProto | AsmExpression | ContainerDecl | ("continue" option(":" Symbol)) | ErrorSetDecl | PromiseType |
| | 1761 | try testCanonical( |
| | 1762 | \\test "values" { |
| | 1763 | \\ 1; |
| | 1764 | \\ 1.0; |
| | 1765 | \\ "string"; |
| | 1766 | \\ c"cstring"; |
| | 1767 | \\ \\ Multi |
| | 1768 | \\ \\ line |
| | 1769 | \\ \\ string |
| | 1770 | \\ ; |
| | 1771 | \\ 'c'; |
| | 1772 | \\ true; |
| | 1773 | \\ false; |
| | 1774 | \\ null; |
| | 1775 | \\ undefined; |
| | 1776 | \\ error; |
| | 1777 | \\ this; |
| | 1778 | \\ unreachable; |
| | 1779 | \\ suspend; |
| | 1780 | \\} |
| | 1781 | \\ |
| | 1782 | ); |
| | 1783 | |
| | 1784 | try testCanonical( |
| | 1785 | \\test "percendence" { |
| | 1786 | \\ a!b(); |
| | 1787 | \\ (a!b)(); |
| | 1788 | \\ !a!b; |
| | 1789 | \\ !(a!b); |
| | 1790 | \\ !a{}; |
| | 1791 | \\ !(a{}); |
| | 1792 | \\ a + b{}; |
| | 1793 | \\ (a + b){}; |
| | 1794 | \\ a << b + c; |
| | 1795 | \\ (a << b) + c; |
| | 1796 | \\ a & b << c; |
| | 1797 | \\ (a & b) << c; |
| | 1798 | \\ a ^ b & c; |
| | 1799 | \\ (a ^ b) & c; |
| | 1800 | \\ a | b ^ c; |
| | 1801 | \\ (a | b) ^ c; |
| | 1802 | \\ a == b | c; |
| | 1803 | \\ (a == b) | c; |
| | 1804 | \\ a and b == c; |
| | 1805 | \\ (a and b) == c; |
| | 1806 | \\ a or b and c; |
| | 1807 | \\ (a or b) and c; |
| | 1808 | \\ (a or b) and c; |
| | 1809 | \\ a = b or c; |
| | 1810 | \\ (a = b) or c; |
| | 1811 | \\} |
| | 1812 | \\ |
| | 1813 | ); |
| | 1814 | |
| | 1815 | try testCanonical( |
| | 1816 | \\const S = struct { |
| | 1817 | \\ const Self = this; |
| | 1818 | \\ f1: u8, |
| | 1819 | \\ |
| | 1820 | \\ fn method(self: &Self) Self { |
| | 1821 | \\ return *self; |
| | 1822 | \\ } |
| | 1823 | \\ |
| | 1824 | \\ f2: u8, |
| | 1825 | \\}; |
| | 1826 | \\ |
| | 1827 | \\const Ps = packed struct { |
| | 1828 | \\ a: u8, |
| | 1829 | \\ b: u8, |
| | 1830 | \\ |
| | 1831 | \\ c: u8, |
| | 1832 | \\}; |
| | 1833 | \\ |
| | 1834 | \\const Es = extern struct { |
| | 1835 | \\ a: u8, |
| | 1836 | \\ b: u8, |
| | 1837 | \\ |
| | 1838 | \\ c: u8, |
| | 1839 | \\}; |
| | 1840 | \\ |
| | 1841 | ); |
| | 1842 | |
| | 1843 | try testCanonical( |
| | 1844 | \\const E = enum { |
| | 1845 | \\ Ok, |
| | 1846 | \\ SomethingElse = 0, |
| | 1847 | \\}; |
| | 1848 | \\ |
| | 1849 | \\const E2 = enum(u8) { |
| | 1850 | \\ Ok, |
| | 1851 | \\ SomethingElse = 255, |
| | 1852 | \\ SomethingThird, |
| | 1853 | \\}; |
| | 1854 | \\ |
| | 1855 | \\const Ee = extern enum { |
| | 1856 | \\ Ok, |
| | 1857 | \\ SomethingElse, |
| | 1858 | \\ SomethingThird, |
| | 1859 | \\}; |
| | 1860 | \\ |
| | 1861 | \\const Ep = packed enum { |
| | 1862 | \\ Ok, |
| | 1863 | \\ SomethingElse, |
| | 1864 | \\ SomethingThird, |
| | 1865 | \\}; |
| | 1866 | \\ |
| | 1867 | ); |
| | 1868 | |
| | 1869 | try testCanonical( |
| | 1870 | \\const a1 = []u8{ }; |
| | 1871 | \\const a2 = []u8{ 1, 2, 3, 4 }; |
| | 1872 | \\const s1 = S{ }; |
| | 1873 | \\const s2 = S{ .a = 1, .b = 2, }; |
| | 1874 | \\ |
| | 1875 | ); |
| | 1876 | |
| | 1877 | try testCanonical(@embedFile("ast.zig")); |
| | 1878 | try testCanonical(@embedFile("index.zig")); |
| | 1879 | try testCanonical(@embedFile("parser.zig")); |
| | 1880 | try testCanonical(@embedFile("tokenizer.zig")); |
| 1733 | } | 1881 | } |