Commit b7914d901c

Andrew Kelley <andrew@ziglang.org>
2020-05-02 20:53:20
add test coverage for top level fields
closes #2022
1 parent 8ebcca6
Changed files (2)
lib
test
stage1
behavior
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 {
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);