| author | |
| committer | |
| log | ca21cad2bf3dcd765753dc93d608e67ae3661f10 |
| tree | 39c3501fb7b23dc70be549818d7aab4087573c62 |
| parent | 332eafeb7f3d866556ab767b960a04661bc43bc7 |
parser_test.zig is where the syntax tests go5 files changed, 75 insertions(+), 69 deletions(-)
CMakeLists.txt+3-1| ... | @@ -363,7 +363,9 @@ set(ZIG_STAGE2_SOURCES | ... | @@ -363,7 +363,9 @@ set(ZIG_STAGE2_SOURCES |
| 363 | "${CMAKE_SOURCE_DIR}/lib/std/crypto/siphash.zig" | 363 | "${CMAKE_SOURCE_DIR}/lib/std/crypto/siphash.zig" |
| 364 | "${CMAKE_SOURCE_DIR}/lib/std/debug.zig" | 364 | "${CMAKE_SOURCE_DIR}/lib/std/debug.zig" |
| 365 | "${CMAKE_SOURCE_DIR}/lib/std/dwarf.zig" | 365 | "${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" | ||
| 367 | "${CMAKE_SOURCE_DIR}/lib/std/elf.zig" | 369 | "${CMAKE_SOURCE_DIR}/lib/std/elf.zig" |
| 368 | "${CMAKE_SOURCE_DIR}/lib/std/event.zig" | 370 | "${CMAKE_SOURCE_DIR}/lib/std/event.zig" |
| 369 | "${CMAKE_SOURCE_DIR}/lib/std/event/batch.zig" | 371 | "${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" { | ... | @@ -4837,6 +4837,77 @@ test "zig fmt: make single-line if no trailing comma" { |
| 4837 | ); | 4837 | ); |
| 4838 | } | 4838 | } |
| 4839 | 4839 | ||
| 4840 | test "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 | |||
| 4840 | test "zig fmt: error for invalid bit range" { | 4911 | test "zig fmt: error for invalid bit range" { |
| 4841 | try testError( | 4912 | try testError( |
| 4842 | \\var x: []align(0:0:0)u8 = bar; | 4913 | \\var x: []align(0:0:0)u8 = bar; |
test/behavior.zig-1| ... | @@ -138,7 +138,6 @@ test { | ... | @@ -138,7 +138,6 @@ test { |
| 138 | _ = @import("behavior/switch.zig"); | 138 | _ = @import("behavior/switch.zig"); |
| 139 | _ = @import("behavior/switch_prong_err_enum.zig"); | 139 | _ = @import("behavior/switch_prong_err_enum.zig"); |
| 140 | _ = @import("behavior/switch_prong_implicit_cast.zig"); | 140 | _ = @import("behavior/switch_prong_implicit_cast.zig"); |
| 141 | _ = @import("behavior/syntax.zig"); | ||
| 142 | _ = @import("behavior/this.zig"); | 141 | _ = @import("behavior/this.zig"); |
| 143 | _ = @import("behavior/truncate.zig"); | 142 | _ = @import("behavior/truncate.zig"); |
| 144 | _ = @import("behavior/try.zig"); | 143 | _ = @import("behavior/try.zig"); |
test/behavior/syntax.zig deleted-66| ... | @@ -1,66 +0,0 @@ | ||
| 1 | // Test trailing comma syntax | ||
| 2 | // zig fmt: off | ||
| 3 | |||
| 4 | extern var a: c_int; | ||
| 5 | extern "c" var b: c_int; | ||
| 6 | export var c: c_int = 0; | ||
| 7 | threadlocal var d: c_int = 0; | ||
| 8 | extern threadlocal var e: c_int; | ||
| 9 | extern "c" threadlocal var f: c_int; | ||
| 10 | export threadlocal var g: c_int = 0; | ||
| 11 | |||
| 12 | const struct_trailing_comma = struct { x: i32, y: i32, }; | ||
| 13 | const struct_no_comma = struct { x: i32, y: i32 }; | ||
| 14 | const struct_fn_no_comma = struct { fn m() void {} y: i32 }; | ||
| 15 | |||
| 16 | const enum_no_comma = enum { A, B }; | ||
| 17 | |||
| 18 | fn 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 | |||
| 24 | fn type_expr_return1() if (true) A {} | ||
| 25 | fn type_expr_return2() for (true) |_| A {} | ||
| 26 | fn type_expr_return3() while (true) A {} | ||
| 27 | |||
| 28 | fn switch_cases(x: i32) void { | ||
| 29 | switch (x) { | ||
| 30 | 1,2,3 => {}, | ||
| 31 | 4,5, => {}, | ||
| 32 | 6...8, => {}, | ||
| 33 | else => {}, | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | fn switch_prongs(x: i32) void { | ||
| 38 | switch (x) { | ||
| 39 | 0 => {}, | ||
| 40 | else => {}, | ||
| 41 | } | ||
| 42 | switch (x) { | ||
| 43 | 0 => {}, | ||
| 44 | else => {} | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | const fn_no_comma = fn(i32, i32)void; | ||
| 49 | const fn_trailing_comma = fn(i32, i32,)void; | ||
| 50 | |||
| 51 | fn fn_calls() void { | ||
| 52 | fn add(x: i32, y: i32,) i32 { x + y }; | ||
| 53 | _ = add(1, 2); | ||
| 54 | _ = add(1, 2,); | ||
| 55 | } | ||
| 56 | |||
| 57 | fn 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 { | ... | @@ -18,5 +18,5 @@ usingnamespace struct { |
| 18 | }; | 18 | }; |
| 19 | 19 | ||
| 20 | test "usingnamespace does not redeclare an imported variable" { | 20 | test "usingnamespace does not redeclare an imported variable" { |
| 21 | comptime try std.testing.expect(foo == 42); | 21 | comptime try std.testing.expect(@This().foo == 42); |
| 22 | } | 22 | } |