authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-08-30 14:31:47-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-09-01 17:54:06-07:00
logca21cad2bf3dcd765753dc93d608e67ae3661f10
tree39c3501fb7b23dc70be549818d7aab4087573c62
parent332eafeb7f3d866556ab767b960a04661bc43bc7

move syntax tests out of behavior tests

parser_test.zig is where the syntax tests go

5 files changed, 75 insertions(+), 69 deletions(-)

CMakeLists.txt+3-1
......@@ -363,7 +363,9 @@ set(ZIG_STAGE2_SOURCES
363363 "${CMAKE_SOURCE_DIR}/lib/std/crypto/siphash.zig"
364364 "${CMAKE_SOURCE_DIR}/lib/std/debug.zig"
365365 "${CMAKE_SOURCE_DIR}/lib/std/dwarf.zig"
366 "${CMAKE_SOURCE_DIR}/lib/std/dwarf_bits.zig"
366 "${CMAKE_SOURCE_DIR}/lib/std/dwarf/AT.zig"
367 "${CMAKE_SOURCE_DIR}/lib/std/dwarf/OP.zig"
368 "${CMAKE_SOURCE_DIR}/lib/std/dwarf/TAG.zig"
367369 "${CMAKE_SOURCE_DIR}/lib/std/elf.zig"
368370 "${CMAKE_SOURCE_DIR}/lib/std/event.zig"
369371 "${CMAKE_SOURCE_DIR}/lib/std/event/batch.zig"
lib/std/zig/parser_test.zig+71
......@@ -4837,6 +4837,77 @@ test "zig fmt: make single-line if no trailing comma" {
48374837 );
48384838}
48394839
4840test "zig fmt: make single-line if no trailing comma" {
4841 try testCanonical(
4842 \\// Test trailing comma syntax
4843 \\// zig fmt: off
4844 \\
4845 \\extern var a: c_int;
4846 \\extern "c" var b: c_int;
4847 \\export var c: c_int = 0;
4848 \\threadlocal var d: c_int = 0;
4849 \\extern threadlocal var e: c_int;
4850 \\extern "c" threadlocal var f: c_int;
4851 \\export threadlocal var g: c_int = 0;
4852 \\
4853 \\const struct_trailing_comma = struct { x: i32, y: i32, };
4854 \\const struct_no_comma = struct { x: i32, y: i32 };
4855 \\const struct_fn_no_comma = struct { fn m() void {} y: i32 };
4856 \\
4857 \\const enum_no_comma = enum { A, B };
4858 \\
4859 \\fn container_init() void {
4860 \\ const S = struct { x: i32, y: i32 };
4861 \\ _ = S { .x = 1, .y = 2 };
4862 \\ _ = S { .x = 1, .y = 2, };
4863 \\}
4864 \\
4865 \\fn type_expr_return1() if (true) A {}
4866 \\fn type_expr_return2() for (true) |_| A {}
4867 \\fn type_expr_return3() while (true) A {}
4868 \\
4869 \\fn switch_cases(x: i32) void {
4870 \\ switch (x) {
4871 \\ 1,2,3 => {},
4872 \\ 4,5, => {},
4873 \\ 6...8, => {},
4874 \\ else => {},
4875 \\ }
4876 \\}
4877 \\
4878 \\fn switch_prongs(x: i32) void {
4879 \\ switch (x) {
4880 \\ 0 => {},
4881 \\ else => {},
4882 \\ }
4883 \\ switch (x) {
4884 \\ 0 => {},
4885 \\ else => {}
4886 \\ }
4887 \\}
4888 \\
4889 \\const fn_no_comma = fn(i32, i32)void;
4890 \\const fn_trailing_comma = fn(i32, i32,)void;
4891 \\
4892 \\fn fn_calls() void {
4893 \\ fn add(x: i32, y: i32,) i32 { x + y };
4894 \\ _ = add(1, 2);
4895 \\ _ = add(1, 2,);
4896 \\}
4897 \\
4898 \\fn asm_lists() void {
4899 \\ if (false) { // Build AST but don't analyze
4900 \\ asm ("not real assembly"
4901 \\ :[a] "x" (x),);
4902 \\ asm ("not real assembly"
4903 \\ :[a] "x" (->i32),:[a] "x" (1),);
4904 \\ asm volatile ("still not real assembly"
4905 \\ :::"a","b",);
4906 \\ }
4907 \\}
4908 );
4909}
4910
48404911test "zig fmt: error for invalid bit range" {
48414912 try testError(
48424913 \\var x: []align(0:0:0)u8 = bar;
test/behavior.zig-1
......@@ -138,7 +138,6 @@ test {
138138 _ = @import("behavior/switch.zig");
139139 _ = @import("behavior/switch_prong_err_enum.zig");
140140 _ = @import("behavior/switch_prong_implicit_cast.zig");
141 _ = @import("behavior/syntax.zig");
142141 _ = @import("behavior/this.zig");
143142 _ = @import("behavior/truncate.zig");
144143 _ = @import("behavior/try.zig");
test/behavior/syntax.zig deleted-66
......@@ -1,66 +0,0 @@
1// Test trailing comma syntax
2// zig fmt: off
3
4extern var a: c_int;
5extern "c" var b: c_int;
6export var c: c_int = 0;
7threadlocal var d: c_int = 0;
8extern threadlocal var e: c_int;
9extern "c" threadlocal var f: c_int;
10export threadlocal var g: c_int = 0;
11
12const struct_trailing_comma = struct { x: i32, y: i32, };
13const struct_no_comma = struct { x: i32, y: i32 };
14const struct_fn_no_comma = struct { fn m() void {} y: i32 };
15
16const enum_no_comma = enum { A, B };
17
18fn container_init() void {
19 const S = struct { x: i32, y: i32 };
20 _ = S { .x = 1, .y = 2 };
21 _ = S { .x = 1, .y = 2, };
22}
23
24fn type_expr_return1() if (true) A {}
25fn type_expr_return2() for (true) |_| A {}
26fn type_expr_return3() while (true) A {}
27
28fn switch_cases(x: i32) void {
29 switch (x) {
30 1,2,3 => {},
31 4,5, => {},
32 6...8, => {},
33 else => {},
34 }
35}
36
37fn switch_prongs(x: i32) void {
38 switch (x) {
39 0 => {},
40 else => {},
41 }
42 switch (x) {
43 0 => {},
44 else => {}
45 }
46}
47
48const fn_no_comma = fn(i32, i32)void;
49const fn_trailing_comma = fn(i32, i32,)void;
50
51fn fn_calls() void {
52 fn add(x: i32, y: i32,) i32 { x + y };
53 _ = add(1, 2);
54 _ = add(1, 2,);
55}
56
57fn asm_lists() void {
58 if (false) { // Build AST but don't analyze
59 asm ("not real assembly"
60 :[a] "x" (x),);
61 asm ("not real assembly"
62 :[a] "x" (->i32),:[a] "x" (1),);
63 asm volatile ("still not real assembly"
64 :::"a","b",);
65 }
66}
test/behavior/usingnamespace_stage1.zig+1-1
......@@ -18,5 +18,5 @@ usingnamespace struct {
1818};
1919
2020test "usingnamespace does not redeclare an imported variable" {
21 comptime try std.testing.expect(foo == 42);
21 comptime try std.testing.expect(@This().foo == 42);
2222}