authorgravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2018-03-31 14:18:09+02:00
committergravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2018-03-31 14:18:09+02:00
log26e56f2fab7c56829d51db1afb10acb0306a101f
tree730dd03a000eebc812589f998e954766f927e4c0
parent596f4b6002d3ed29adc8777b0417952cb79ad888

Each test now have it's own test name


1 files changed, 78 insertions(+), 44 deletions(-)

std/zig/parser.zig+78-44
......@@ -1557,7 +1557,7 @@ fn testCanonical(source: []const u8) !void {
15571557 }
15581558}
15591559
1560test "zig fmt" {
1560test "zig fmt: get stdout or fail" {
15611561 try testCanonical(
15621562 \\const std = @import("std");
15631563 \\
......@@ -1568,7 +1568,9 @@ test "zig fmt" {
15681568 \\}
15691569 \\
15701570 );
1571}
15711572
1573test "zig fmt: preserve spacing" {
15721574 try testCanonical(
15731575 \\const std = @import("std");
15741576 \\
......@@ -1581,25 +1583,33 @@ test "zig fmt" {
15811583 \\}
15821584 \\
15831585 );
1586}
15841587
1588test "zig fmt: return types" {
15851589 try testCanonical(
15861590 \\pub fn main() !void {}
15871591 \\pub fn main() var {}
15881592 \\pub fn main() i32 {}
15891593 \\
15901594 );
1595}
15911596
1597test "zig fmt: imports" {
15921598 try testCanonical(
15931599 \\const std = @import("std");
15941600 \\const std = @import();
15951601 \\
15961602 );
1603}
15971604
1605test "zig fmt: extern function" {
15981606 try testCanonical(
15991607 \\extern fn puts(s: &const u8) c_int;
16001608 \\
16011609 );
1610}
16021611
1612test "zig fmt: global declarations" {
16031613 try testCanonical(
16041614 \\const a = b;
16051615 \\pub const a = b;
......@@ -1611,66 +1621,71 @@ test "zig fmt" {
16111621 \\pub var a: i32 = b;
16121622 \\
16131623 );
1624}
16141625
1626test "zig fmt: extern declaration" {
16151627 try testCanonical(
16161628 \\extern var foo: c_int;
16171629 \\
16181630 );
1631}
16191632
1620 try testCanonical(
1633test "zig fmt: alignment" {
1634 try testCanonical(
16211635 \\var foo: c_int align(1);
16221636 \\
16231637 );
1638}
16241639
1640test "zig fmt: C main" {
16251641 try testCanonical(
16261642 \\fn main(argc: c_int, argv: &&u8) c_int {
16271643 \\ const a = b;
16281644 \\}
16291645 \\
16301646 );
1647}
16311648
1649test "zig fmt: return" {
16321650 try testCanonical(
16331651 \\fn foo(argc: c_int, argv: &&u8) c_int {
16341652 \\ return 0;
16351653 \\}
16361654 \\
16371655 );
1656}
16381657
1658test "zig fmt: pointer attributes" {
16391659 try testCanonical(
16401660 \\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;
16411664 \\
16421665 );
1666}
16431667
1668test "zig fmt: slice attributes" {
16441669 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;
16631674 \\
16641675 );
1676}
16651677
1666 try testCanonical(
1678test "zig fmt: test declaration" {
1679 try testCanonical(
16671680 \\test "test name" {
16681681 \\ const a = 1;
16691682 \\ var b = 1;
16701683 \\}
16711684 \\
16721685 );
1686}
16731687
1688test "zig fmt: infix operators" {
16741689 try testCanonical(
16751690 \\test "infix operators" {
16761691 \\ var i = undefined;
......@@ -1720,14 +1735,18 @@ test "zig fmt" {
17201735 \\}
17211736 \\
17221737 );
1738}
17231739
1740test "zig fmt: prefix operators" {
17241741 try testCanonical(
17251742 \\test "prefix operators" {
17261743 \\ try return --%~??!*&0;
17271744 \\}
17281745 \\
17291746 );
1747}
17301748
1749test "zig fmt: call expression" {
17311750 try testCanonical(
17321751 \\test "test calls" {
17331752 \\ a();
......@@ -1737,27 +1756,9 @@ test "zig fmt" {
17371756 \\}
17381757 \\
17391758 );
1759}
17401760
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
1761test "zig fmt: values" {
17611762 try testCanonical(
17621763 \\test "values" {
17631764 \\ 1;
......@@ -1780,9 +1781,34 @@ test "zig fmt" {
17801781 \\}
17811782 \\
17821783 );
1784}
17831785
1786test "zig fmt: indexing" {
17841787 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
1798test "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
1809test "zig fmt: precedence" {
1810 try testCanonical(
1811 \\test "precedence" {
17861812 \\ a!b();
17871813 \\ (a!b)();
17881814 \\ !a!b;
......@@ -1811,7 +1837,9 @@ test "zig fmt" {
18111837 \\}
18121838 \\
18131839 );
1840}
18141841
1842test "zig fmt: struct declaration" {
18151843 try testCanonical(
18161844 \\const S = struct {
18171845 \\ const Self = this;
......@@ -1839,8 +1867,10 @@ test "zig fmt" {
18391867 \\};
18401868 \\
18411869 );
1870}
18421871
1843 try testCanonical(
1872test "zig fmt: enum declaration" {
1873 try testCanonical(
18441874 \\const E = enum {
18451875 \\ Ok,
18461876 \\ SomethingElse = 0,
......@@ -1865,7 +1895,9 @@ test "zig fmt" {
18651895 \\};
18661896 \\
18671897 );
1898}
18681899
1900test "zig fmt: container initializers" {
18691901 try testCanonical(
18701902 \\const a1 = []u8{ };
18711903 \\const a2 = []u8{ 1, 2, 3, 4 };
......@@ -1873,9 +1905,11 @@ test "zig fmt" {
18731905 \\const s2 = S{ .a = 1, .b = 2, };
18741906 \\
18751907 );
1908}
18761909
1910test "zig fmt: zig fmt" {
18771911 try testCanonical(@embedFile("ast.zig"));
18781912 try testCanonical(@embedFile("index.zig"));
18791913 try testCanonical(@embedFile("parser.zig"));
18801914 try testCanonical(@embedFile("tokenizer.zig"));
1881}
1915}
\ No newline at end of file