add test coverage for top level fields

closes #2022
This commit is contained in:
Andrew Kelley 2020-05-02 14:53:20 -04:00
parent 8ebcca6734
commit b7914d901c
2 changed files with 19 additions and 0 deletions

View File

@ -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 {

View File

@ -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);