From ca21cad2bf3dcd765753dc93d608e67ae3661f10 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 30 Aug 2021 14:31:47 -0700 Subject: [PATCH] move syntax tests out of behavior tests parser_test.zig is where the syntax tests go --- CMakeLists.txt | 4 +- lib/std/zig/parser_test.zig | 71 +++++++++++++++++++++++++ test/behavior.zig | 1 - test/behavior/syntax.zig | 66 ----------------------- test/behavior/usingnamespace_stage1.zig | 2 +- 5 files changed, 75 insertions(+), 69 deletions(-) delete mode 100644 test/behavior/syntax.zig diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f68c2c649..695cf5b414 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -363,7 +363,9 @@ set(ZIG_STAGE2_SOURCES "${CMAKE_SOURCE_DIR}/lib/std/crypto/siphash.zig" "${CMAKE_SOURCE_DIR}/lib/std/debug.zig" "${CMAKE_SOURCE_DIR}/lib/std/dwarf.zig" - "${CMAKE_SOURCE_DIR}/lib/std/dwarf_bits.zig" + "${CMAKE_SOURCE_DIR}/lib/std/dwarf/AT.zig" + "${CMAKE_SOURCE_DIR}/lib/std/dwarf/OP.zig" + "${CMAKE_SOURCE_DIR}/lib/std/dwarf/TAG.zig" "${CMAKE_SOURCE_DIR}/lib/std/elf.zig" "${CMAKE_SOURCE_DIR}/lib/std/event.zig" "${CMAKE_SOURCE_DIR}/lib/std/event/batch.zig" diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index ff6ba8b63a..95fb3f6bc0 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -4837,6 +4837,77 @@ test "zig fmt: make single-line if no trailing comma" { ); } +test "zig fmt: make single-line if no trailing comma" { + try testCanonical( + \\// Test trailing comma syntax + \\// zig fmt: off + \\ + \\extern var a: c_int; + \\extern "c" var b: c_int; + \\export var c: c_int = 0; + \\threadlocal var d: c_int = 0; + \\extern threadlocal var e: c_int; + \\extern "c" threadlocal var f: c_int; + \\export threadlocal var g: c_int = 0; + \\ + \\const struct_trailing_comma = struct { x: i32, y: i32, }; + \\const struct_no_comma = struct { x: i32, y: i32 }; + \\const struct_fn_no_comma = struct { fn m() void {} y: i32 }; + \\ + \\const enum_no_comma = enum { A, B }; + \\ + \\fn container_init() void { + \\ const S = struct { x: i32, y: i32 }; + \\ _ = S { .x = 1, .y = 2 }; + \\ _ = S { .x = 1, .y = 2, }; + \\} + \\ + \\fn type_expr_return1() if (true) A {} + \\fn type_expr_return2() for (true) |_| A {} + \\fn type_expr_return3() while (true) A {} + \\ + \\fn switch_cases(x: i32) void { + \\ switch (x) { + \\ 1,2,3 => {}, + \\ 4,5, => {}, + \\ 6...8, => {}, + \\ else => {}, + \\ } + \\} + \\ + \\fn switch_prongs(x: i32) void { + \\ switch (x) { + \\ 0 => {}, + \\ else => {}, + \\ } + \\ switch (x) { + \\ 0 => {}, + \\ else => {} + \\ } + \\} + \\ + \\const fn_no_comma = fn(i32, i32)void; + \\const fn_trailing_comma = fn(i32, i32,)void; + \\ + \\fn fn_calls() void { + \\ fn add(x: i32, y: i32,) i32 { x + y }; + \\ _ = add(1, 2); + \\ _ = add(1, 2,); + \\} + \\ + \\fn asm_lists() void { + \\ if (false) { // Build AST but don't analyze + \\ asm ("not real assembly" + \\ :[a] "x" (x),); + \\ asm ("not real assembly" + \\ :[a] "x" (->i32),:[a] "x" (1),); + \\ asm volatile ("still not real assembly" + \\ :::"a","b",); + \\ } + \\} + ); +} + test "zig fmt: error for invalid bit range" { try testError( \\var x: []align(0:0:0)u8 = bar; diff --git a/test/behavior.zig b/test/behavior.zig index 80de1880d8..b39c50df32 100644 --- a/test/behavior.zig +++ b/test/behavior.zig @@ -138,7 +138,6 @@ test { _ = @import("behavior/switch.zig"); _ = @import("behavior/switch_prong_err_enum.zig"); _ = @import("behavior/switch_prong_implicit_cast.zig"); - _ = @import("behavior/syntax.zig"); _ = @import("behavior/this.zig"); _ = @import("behavior/truncate.zig"); _ = @import("behavior/try.zig"); diff --git a/test/behavior/syntax.zig b/test/behavior/syntax.zig deleted file mode 100644 index c5f9fc70b1..0000000000 --- a/test/behavior/syntax.zig +++ /dev/null @@ -1,66 +0,0 @@ -// Test trailing comma syntax -// zig fmt: off - -extern var a: c_int; -extern "c" var b: c_int; -export var c: c_int = 0; -threadlocal var d: c_int = 0; -extern threadlocal var e: c_int; -extern "c" threadlocal var f: c_int; -export threadlocal var g: c_int = 0; - -const struct_trailing_comma = struct { x: i32, y: i32, }; -const struct_no_comma = struct { x: i32, y: i32 }; -const struct_fn_no_comma = struct { fn m() void {} y: i32 }; - -const enum_no_comma = enum { A, B }; - -fn container_init() void { - const S = struct { x: i32, y: i32 }; - _ = S { .x = 1, .y = 2 }; - _ = S { .x = 1, .y = 2, }; -} - -fn type_expr_return1() if (true) A {} -fn type_expr_return2() for (true) |_| A {} -fn type_expr_return3() while (true) A {} - -fn switch_cases(x: i32) void { - switch (x) { - 1,2,3 => {}, - 4,5, => {}, - 6...8, => {}, - else => {}, - } -} - -fn switch_prongs(x: i32) void { - switch (x) { - 0 => {}, - else => {}, - } - switch (x) { - 0 => {}, - else => {} - } -} - -const fn_no_comma = fn(i32, i32)void; -const fn_trailing_comma = fn(i32, i32,)void; - -fn fn_calls() void { - fn add(x: i32, y: i32,) i32 { x + y }; - _ = add(1, 2); - _ = add(1, 2,); -} - -fn asm_lists() void { - if (false) { // Build AST but don't analyze - asm ("not real assembly" - :[a] "x" (x),); - asm ("not real assembly" - :[a] "x" (->i32),:[a] "x" (1),); - asm volatile ("still not real assembly" - :::"a","b",); - } -} diff --git a/test/behavior/usingnamespace_stage1.zig b/test/behavior/usingnamespace_stage1.zig index b529b24dd4..30babc5381 100644 --- a/test/behavior/usingnamespace_stage1.zig +++ b/test/behavior/usingnamespace_stage1.zig @@ -18,5 +18,5 @@ usingnamespace struct { }; test "usingnamespace does not redeclare an imported variable" { - comptime try std.testing.expect(foo == 42); + comptime try std.testing.expect(@This().foo == 42); }