zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit b7914d901c8c5761457a4774858f1004febc2d3a (tree)
parent 8ebcca6734e07aea29098ca4c63c0216b3099d0e
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sat,  2 May 2020 14:53:20 -0400

add test coverage for top level fields

closes #2022

Diffstat:
Mlib/std/zig/parser_test.zig | 9+++++++++
Mtest/stage1/behavior/struct.zig | 10++++++++++
2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig @@ -1,3 +1,12 @@ +test "zig fmt: top-level fields" { + try testCanonical( + \\a: did_you_know, + \\b: all_files_are, + \\structs: ?x, + \\ + ); +} + test "zig fmt: decl between fields" { try testError( \\const S = struct { diff --git a/test/stage1/behavior/struct.zig b/test/stage1/behavior/struct.zig @@ -11,6 +11,16 @@ const StructWithNoFields = struct { }; const empty_global_instance = StructWithNoFields{}; +top_level_field: i32, + +test "top level fields" { + var instance = @This(){ + .top_level_field = 1234, + }; + instance.top_level_field += 1; + expectEqual(@as(i32, 1235), instance.top_level_field); +} + test "call struct static method" { const result = StructWithNoFields.add(3, 4); expect(result == 7);