diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-04-30 18:49:05 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-04-30 18:49:05 -0400 |
| commit | 3e61c45f8936f6211ae9b61b2b0358c560344f7b (patch) | |
| tree | 1424dc0b5bd8d55ece6c86bca6376eb551322355 /std | |
| parent | eed49a210474af98f64961ed603feb6dfa60acde (diff) | |
| download | zig-3e61c45f8936f6211ae9b61b2b0358c560344f7b.tar.gz zig-3e61c45f8936f6211ae9b61b2b0358c560344f7b.zip | |
zig fmt: consistent spacing for container inits
Diffstat (limited to 'std')
| -rw-r--r-- | std/zig/parser.zig | 10 | ||||
| -rw-r--r-- | std/zig/parser_test.zig | 41 |
2 files changed, 14 insertions, 37 deletions
diff --git a/std/zig/parser.zig b/std/zig/parser.zig index 5e3f3bff59..b50150580e 100644 --- a/std/zig/parser.zig +++ b/std/zig/parser.zig @@ -3875,9 +3875,9 @@ pub const Parser = struct { if (field_inits.len == 1) { const field_init = field_inits.at(0); - try stack.append(RenderState { .Text = "}" }); + try stack.append(RenderState { .Text = " }" }); try stack.append(RenderState { .FieldInitializer = field_init }); - try stack.append(RenderState { .Text = " {" }); + try stack.append(RenderState { .Text = "{ " }); try stack.append(RenderState { .Expression = suffix_op.lhs }); continue; } @@ -3893,7 +3893,7 @@ pub const Parser = struct { try stack.append(RenderState.PrintIndent); } try stack.append(RenderState { .Indent = indent + indent_delta }); - try stack.append(RenderState { .Text = " {\n"}); + try stack.append(RenderState { .Text = "{\n"}); try stack.append(RenderState { .Expression = suffix_op.lhs }); }, ast.Node.SuffixOp.Op.ArrayInitializer => |exprs| { @@ -3907,7 +3907,7 @@ pub const Parser = struct { try stack.append(RenderState { .Text = "}" }); try stack.append(RenderState { .Expression = expr }); - try stack.append(RenderState { .Text = " {" }); + try stack.append(RenderState { .Text = "{" }); try stack.append(RenderState { .Expression = suffix_op.lhs }); continue; } @@ -3924,7 +3924,7 @@ pub const Parser = struct { try stack.append(RenderState.PrintIndent); } try stack.append(RenderState { .Indent = indent + indent_delta }); - try stack.append(RenderState { .Text = " {\n"}); + try stack.append(RenderState { .Text = "{\n"}); try stack.append(RenderState { .Expression = suffix_op.lhs }); }, } diff --git a/std/zig/parser_test.zig b/std/zig/parser_test.zig index 8b0002e6bd..81f9e56223 100644 --- a/std/zig/parser_test.zig +++ b/std/zig/parser_test.zig @@ -1,12 +1,3 @@ -test "zig fmt: aggregate type init with only 1 field" { - try testCanonical( - \\comptime { - \\ assert(bar(Payload {.A = 1234}) == -10); - \\} - \\ - ); -} - test "zig fmt: union(enum(u32)) with assigned enum values" { try testCanonical( \\const MultipleChoice = union(enum(u32)) { @@ -124,7 +115,7 @@ test "zig fmt: same-line comment after field decl" { test "zig fmt: array literal with 1 item on 1 line" { try testCanonical( - \\var s = []const u64 {0} ** 25; + \\var s = []const u64{0} ** 25; \\ ); } @@ -625,11 +616,11 @@ test "zig fmt: error set declaration" { test "zig fmt: arrays" { try testCanonical( \\test "test array" { - \\ const a: [2]u8 = [2]u8 { + \\ const a: [2]u8 = [2]u8{ \\ 1, \\ 2, \\ }; - \\ const a: [2]u8 = []u8 { + \\ const a: [2]u8 = []u8{ \\ 1, \\ 2, \\ }; @@ -641,15 +632,17 @@ test "zig fmt: arrays" { test "zig fmt: container initializers" { try testCanonical( - \\const a1 = []u8{}; - \\const a2 = []u8 { + \\const a0 = []u8{}; + \\const a1 = []u8{1}; + \\const a2 = []u8{ \\ 1, \\ 2, \\ 3, \\ 4, \\}; - \\const s1 = S{}; - \\const s2 = S { + \\const s0 = S{}; + \\const s1 = S{ .a = 1 }; + \\const s2 = S{ \\ .a = 1, \\ .b = 2, \\}; @@ -718,7 +711,6 @@ test "zig fmt: switch" { \\ Float: f64, \\ }; \\ - \\ const u = Union {.Int = 0}; \\ switch (u) { \\ Union.Int => |int| {}, \\ Union.Float => |*float| unreachable, @@ -797,11 +789,6 @@ test "zig fmt: while" { test "zig fmt: for" { try testCanonical( \\test "for" { - \\ const a = []u8 { - \\ 1, - \\ 2, - \\ 3, - \\ }; \\ for (a) |v| { \\ continue; \\ } @@ -1032,16 +1019,6 @@ test "zig fmt: error return" { ); } -test "zig fmt: struct literals with fields on each line" { - try testCanonical( - \\var self = BufSet { - \\ .hash_map = BufSetHashMap.init(a), - \\ .hash_map2 = xyz, - \\}; - \\ - ); -} - const std = @import("std"); const mem = std.mem; const warn = std.debug.warn; |
