| ... | ... | @@ -1557,7 +1557,7 @@ fn testCanonical(source: []const u8) !void { |
| 1557 | 1557 | } |
| 1558 | 1558 | } |
| 1559 | 1559 | |
| 1560 | | test "zig fmt" { |
| 1560 | test "zig fmt: get stdout or fail" { |
| 1561 | 1561 | try testCanonical( |
| 1562 | 1562 | \\const std = @import("std"); |
| 1563 | 1563 | \\ |
| ... | ... | @@ -1568,7 +1568,9 @@ test "zig fmt" { |
| 1568 | 1568 | \\} |
| 1569 | 1569 | \\ |
| 1570 | 1570 | ); |
| 1571 | } |
| 1571 | 1572 | |
| 1573 | test "zig fmt: preserve spacing" { |
| 1572 | 1574 | try testCanonical( |
| 1573 | 1575 | \\const std = @import("std"); |
| 1574 | 1576 | \\ |
| ... | ... | @@ -1581,25 +1583,33 @@ test "zig fmt" { |
| 1581 | 1583 | \\} |
| 1582 | 1584 | \\ |
| 1583 | 1585 | ); |
| 1586 | } |
| 1584 | 1587 | |
| 1588 | test "zig fmt: return types" { |
| 1585 | 1589 | try testCanonical( |
| 1586 | 1590 | \\pub fn main() !void {} |
| 1587 | 1591 | \\pub fn main() var {} |
| 1588 | 1592 | \\pub fn main() i32 {} |
| 1589 | 1593 | \\ |
| 1590 | 1594 | ); |
| 1595 | } |
| 1591 | 1596 | |
| 1597 | test "zig fmt: imports" { |
| 1592 | 1598 | try testCanonical( |
| 1593 | 1599 | \\const std = @import("std"); |
| 1594 | 1600 | \\const std = @import(); |
| 1595 | 1601 | \\ |
| 1596 | 1602 | ); |
| 1603 | } |
| 1597 | 1604 | |
| 1605 | test "zig fmt: extern function" { |
| 1598 | 1606 | try testCanonical( |
| 1599 | 1607 | \\extern fn puts(s: &const u8) c_int; |
| 1600 | 1608 | \\ |
| 1601 | 1609 | ); |
| 1610 | } |
| 1602 | 1611 | |
| 1612 | test "zig fmt: global declarations" { |
| 1603 | 1613 | try testCanonical( |
| 1604 | 1614 | \\const a = b; |
| 1605 | 1615 | \\pub const a = b; |
| ... | ... | @@ -1611,66 +1621,71 @@ test "zig fmt" { |
| 1611 | 1621 | \\pub var a: i32 = b; |
| 1612 | 1622 | \\ |
| 1613 | 1623 | ); |
| 1624 | } |
| 1614 | 1625 | |
| 1626 | test "zig fmt: extern declaration" { |
| 1615 | 1627 | try testCanonical( |
| 1616 | 1628 | \\extern var foo: c_int; |
| 1617 | 1629 | \\ |
| 1618 | 1630 | ); |
| 1631 | } |
| 1619 | 1632 | |
| 1620 | | try testCanonical( |
| 1633 | test "zig fmt: alignment" { |
| 1634 | try testCanonical( |
| 1621 | 1635 | \\var foo: c_int align(1); |
| 1622 | 1636 | \\ |
| 1623 | 1637 | ); |
| 1638 | } |
| 1624 | 1639 | |
| 1640 | test "zig fmt: C main" { |
| 1625 | 1641 | try testCanonical( |
| 1626 | 1642 | \\fn main(argc: c_int, argv: &&u8) c_int { |
| 1627 | 1643 | \\ const a = b; |
| 1628 | 1644 | \\} |
| 1629 | 1645 | \\ |
| 1630 | 1646 | ); |
| 1647 | } |
| 1631 | 1648 | |
| 1649 | test "zig fmt: return" { |
| 1632 | 1650 | try testCanonical( |
| 1633 | 1651 | \\fn foo(argc: c_int, argv: &&u8) c_int { |
| 1634 | 1652 | \\ return 0; |
| 1635 | 1653 | \\} |
| 1636 | 1654 | \\ |
| 1637 | 1655 | ); |
| 1656 | } |
| 1638 | 1657 | |
| 1658 | test "zig fmt: pointer attributes" { |
| 1639 | 1659 | try testCanonical( |
| 1640 | 1660 | \\extern fn f1(s: &align(&u8) u8) c_int; |
| 1661 | \\extern fn f2(s: &&align(1) &const &volatile u8) c_int; |
| 1662 | \\extern fn f3(s: &align(1) const &align(1) volatile &const volatile u8) c_int; |
| 1663 | \\extern fn f4(s: &align(1) const volatile u8) c_int; |
| 1641 | 1664 | \\ |
| 1642 | 1665 | ); |
| 1666 | } |
| 1643 | 1667 | |
| 1668 | test "zig fmt: slice attributes" { |
| 1644 | 1669 | try testCanonical( |
| 1645 | | \\extern fn f1(s: &&align(1) &const &volatile u8) c_int; |
| 1646 | | \\extern fn f2(s: &align(1) const &align(1) volatile &const volatile u8) c_int; |
| 1647 | | \\extern fn f3(s: &align(1) const volatile u8) c_int; |
| 1648 | | \\ |
| 1649 | | ); |
| 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 | | |
| 1658 | | try testCanonical( |
| 1659 | | \\fn f1(a: bool, b: bool) bool { |
| 1660 | | \\ a != b; |
| 1661 | | \\ return a == b; |
| 1662 | | \\} |
| 1670 | \\extern fn f1(s: &align(&u8) u8) c_int; |
| 1671 | \\extern fn f2(s: &&align(1) &const &volatile u8) c_int; |
| 1672 | \\extern fn f3(s: &align(1) const &align(1) volatile &const volatile u8) c_int; |
| 1673 | \\extern fn f4(s: &align(1) const volatile u8) c_int; |
| 1663 | 1674 | \\ |
| 1664 | 1675 | ); |
| 1676 | } |
| 1665 | 1677 | |
| 1666 | | try testCanonical( |
| 1678 | test "zig fmt: test declaration" { |
| 1679 | try testCanonical( |
| 1667 | 1680 | \\test "test name" { |
| 1668 | 1681 | \\ const a = 1; |
| 1669 | 1682 | \\ var b = 1; |
| 1670 | 1683 | \\} |
| 1671 | 1684 | \\ |
| 1672 | 1685 | ); |
| 1686 | } |
| 1673 | 1687 | |
| 1688 | test "zig fmt: infix operators" { |
| 1674 | 1689 | try testCanonical( |
| 1675 | 1690 | \\test "infix operators" { |
| 1676 | 1691 | \\ var i = undefined; |
| ... | ... | @@ -1720,14 +1735,18 @@ test "zig fmt" { |
| 1720 | 1735 | \\} |
| 1721 | 1736 | \\ |
| 1722 | 1737 | ); |
| 1738 | } |
| 1723 | 1739 | |
| 1740 | test "zig fmt: prefix operators" { |
| 1724 | 1741 | try testCanonical( |
| 1725 | 1742 | \\test "prefix operators" { |
| 1726 | 1743 | \\ try return --%~??!*&0; |
| 1727 | 1744 | \\} |
| 1728 | 1745 | \\ |
| 1729 | 1746 | ); |
| 1747 | } |
| 1730 | 1748 | |
| 1749 | test "zig fmt: call expression" { |
| 1731 | 1750 | try testCanonical( |
| 1732 | 1751 | \\test "test calls" { |
| 1733 | 1752 | \\ a(); |
| ... | ... | @@ -1737,27 +1756,9 @@ test "zig fmt" { |
| 1737 | 1756 | \\} |
| 1738 | 1757 | \\ |
| 1739 | 1758 | ); |
| 1759 | } |
| 1740 | 1760 | |
| 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 | test "zig fmt: values" { |
| 1761 | 1762 | try testCanonical( |
| 1762 | 1763 | \\test "values" { |
| 1763 | 1764 | \\ 1; |
| ... | ... | @@ -1780,9 +1781,34 @@ test "zig fmt" { |
| 1780 | 1781 | \\} |
| 1781 | 1782 | \\ |
| 1782 | 1783 | ); |
| 1784 | } |
| 1783 | 1785 | |
| 1786 | test "zig fmt: indexing" { |
| 1784 | 1787 | try testCanonical( |
| 1785 | | \\test "precendence" { |
| 1788 | \\test "test index" { |
| 1789 | \\ a[0]; |
| 1790 | \\ a[0 + 5]; |
| 1791 | \\ a[0..]; |
| 1792 | \\ a[0..5]; |
| 1793 | \\} |
| 1794 | \\ |
| 1795 | ); |
| 1796 | } |
| 1797 | |
| 1798 | test "zig fmt: arrays" { |
| 1799 | try testCanonical( |
| 1800 | \\test "test array" { |
| 1801 | \\ const a: [2]u8 = [2]u8{ 1, 2 }; |
| 1802 | \\ const a: [2]u8 = []u8{ 1, 2 }; |
| 1803 | \\ const a: [0]u8 = []u8{}; |
| 1804 | \\} |
| 1805 | \\ |
| 1806 | ); |
| 1807 | } |
| 1808 | |
| 1809 | test "zig fmt: precedence" { |
| 1810 | try testCanonical( |
| 1811 | \\test "precedence" { |
| 1786 | 1812 | \\ a!b(); |
| 1787 | 1813 | \\ (a!b)(); |
| 1788 | 1814 | \\ !a!b; |
| ... | ... | @@ -1811,7 +1837,9 @@ test "zig fmt" { |
| 1811 | 1837 | \\} |
| 1812 | 1838 | \\ |
| 1813 | 1839 | ); |
| 1840 | } |
| 1814 | 1841 | |
| 1842 | test "zig fmt: struct declaration" { |
| 1815 | 1843 | try testCanonical( |
| 1816 | 1844 | \\const S = struct { |
| 1817 | 1845 | \\ const Self = this; |
| ... | ... | @@ -1839,8 +1867,10 @@ test "zig fmt" { |
| 1839 | 1867 | \\}; |
| 1840 | 1868 | \\ |
| 1841 | 1869 | ); |
| 1870 | } |
| 1842 | 1871 | |
| 1843 | | try testCanonical( |
| 1872 | test "zig fmt: enum declaration" { |
| 1873 | try testCanonical( |
| 1844 | 1874 | \\const E = enum { |
| 1845 | 1875 | \\ Ok, |
| 1846 | 1876 | \\ SomethingElse = 0, |
| ... | ... | @@ -1865,7 +1895,9 @@ test "zig fmt" { |
| 1865 | 1895 | \\}; |
| 1866 | 1896 | \\ |
| 1867 | 1897 | ); |
| 1898 | } |
| 1868 | 1899 | |
| 1900 | test "zig fmt: container initializers" { |
| 1869 | 1901 | try testCanonical( |
| 1870 | 1902 | \\const a1 = []u8{ }; |
| 1871 | 1903 | \\const a2 = []u8{ 1, 2, 3, 4 }; |
| ... | ... | @@ -1873,9 +1905,11 @@ test "zig fmt" { |
| 1873 | 1905 | \\const s2 = S{ .a = 1, .b = 2, }; |
| 1874 | 1906 | \\ |
| 1875 | 1907 | ); |
| 1908 | } |
| 1876 | 1909 | |
| 1910 | test "zig fmt: zig fmt" { |
| 1877 | 1911 | try testCanonical(@embedFile("ast.zig")); |
| 1878 | 1912 | try testCanonical(@embedFile("index.zig")); |
| 1879 | 1913 | try testCanonical(@embedFile("parser.zig")); |
| 1880 | 1914 | try testCanonical(@embedFile("tokenizer.zig")); |
| 1881 | | } |
| 1915 | } |
| | \ No newline at end of file |