authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-04-30 18:49:05-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-04-30 18:49:05-04:00
log3e61c45f8936f6211ae9b61b2b0358c560344f7b
tree1424dc0b5bd8d55ece6c86bca6376eb551322355
parenteed49a210474af98f64961ed603feb6dfa60acde

zig fmt: consistent spacing for container inits


2 files changed, 14 insertions(+), 37 deletions(-)

std/zig/parser.zig+5-5
......@@ -3875,9 +3875,9 @@ pub const Parser = struct {
38753875 if (field_inits.len == 1) {
38763876 const field_init = field_inits.at(0);
38773877
3878 try stack.append(RenderState { .Text = "}" });
3878 try stack.append(RenderState { .Text = " }" });
38793879 try stack.append(RenderState { .FieldInitializer = field_init });
3880 try stack.append(RenderState { .Text = " {" });
3880 try stack.append(RenderState { .Text = "{ " });
38813881 try stack.append(RenderState { .Expression = suffix_op.lhs });
38823882 continue;
38833883 }
......@@ -3893,7 +3893,7 @@ pub const Parser = struct {
38933893 try stack.append(RenderState.PrintIndent);
38943894 }
38953895 try stack.append(RenderState { .Indent = indent + indent_delta });
3896 try stack.append(RenderState { .Text = " {\n"});
3896 try stack.append(RenderState { .Text = "{\n"});
38973897 try stack.append(RenderState { .Expression = suffix_op.lhs });
38983898 },
38993899 ast.Node.SuffixOp.Op.ArrayInitializer => |exprs| {
......@@ -3907,7 +3907,7 @@ pub const Parser = struct {
39073907
39083908 try stack.append(RenderState { .Text = "}" });
39093909 try stack.append(RenderState { .Expression = expr });
3910 try stack.append(RenderState { .Text = " {" });
3910 try stack.append(RenderState { .Text = "{" });
39113911 try stack.append(RenderState { .Expression = suffix_op.lhs });
39123912 continue;
39133913 }
......@@ -3924,7 +3924,7 @@ pub const Parser = struct {
39243924 try stack.append(RenderState.PrintIndent);
39253925 }
39263926 try stack.append(RenderState { .Indent = indent + indent_delta });
3927 try stack.append(RenderState { .Text = " {\n"});
3927 try stack.append(RenderState { .Text = "{\n"});
39283928 try stack.append(RenderState { .Expression = suffix_op.lhs });
39293929 },
39303930 }
std/zig/parser_test.zig+9-32
......@@ -1,12 +1,3 @@
1test "zig fmt: aggregate type init with only 1 field" {
2 try testCanonical(
3 \\comptime {
4 \\ assert(bar(Payload {.A = 1234}) == -10);
5 \\}
6 \\
7 );
8}
9
101test "zig fmt: union(enum(u32)) with assigned enum values" {
112 try testCanonical(
123 \\const MultipleChoice = union(enum(u32)) {
......@@ -124,7 +115,7 @@ test "zig fmt: same-line comment after field decl" {
124115
125116test "zig fmt: array literal with 1 item on 1 line" {
126117 try testCanonical(
127 \\var s = []const u64 {0} ** 25;
118 \\var s = []const u64{0} ** 25;
128119 \\
129120 );
130121}
......@@ -625,11 +616,11 @@ test "zig fmt: error set declaration" {
625616test "zig fmt: arrays" {
626617 try testCanonical(
627618 \\test "test array" {
628 \\ const a: [2]u8 = [2]u8 {
619 \\ const a: [2]u8 = [2]u8{
629620 \\ 1,
630621 \\ 2,
631622 \\ };
632 \\ const a: [2]u8 = []u8 {
623 \\ const a: [2]u8 = []u8{
633624 \\ 1,
634625 \\ 2,
635626 \\ };
......@@ -641,15 +632,17 @@ test "zig fmt: arrays" {
641632
642633test "zig fmt: container initializers" {
643634 try testCanonical(
644 \\const a1 = []u8{};
645 \\const a2 = []u8 {
635 \\const a0 = []u8{};
636 \\const a1 = []u8{1};
637 \\const a2 = []u8{
646638 \\ 1,
647639 \\ 2,
648640 \\ 3,
649641 \\ 4,
650642 \\};
651 \\const s1 = S{};
652 \\const s2 = S {
643 \\const s0 = S{};
644 \\const s1 = S{ .a = 1 };
645 \\const s2 = S{
653646 \\ .a = 1,
654647 \\ .b = 2,
655648 \\};
......@@ -718,7 +711,6 @@ test "zig fmt: switch" {
718711 \\ Float: f64,
719712 \\ };
720713 \\
721 \\ const u = Union {.Int = 0};
722714 \\ switch (u) {
723715 \\ Union.Int => |int| {},
724716 \\ Union.Float => |*float| unreachable,
......@@ -797,11 +789,6 @@ test "zig fmt: while" {
797789test "zig fmt: for" {
798790 try testCanonical(
799791 \\test "for" {
800 \\ const a = []u8 {
801 \\ 1,
802 \\ 2,
803 \\ 3,
804 \\ };
805792 \\ for (a) |v| {
806793 \\ continue;
807794 \\ }
......@@ -1032,16 +1019,6 @@ test "zig fmt: error return" {
10321019 );
10331020}
10341021
1035test "zig fmt: struct literals with fields on each line" {
1036 try testCanonical(
1037 \\var self = BufSet {
1038 \\ .hash_map = BufSetHashMap.init(a),
1039 \\ .hash_map2 = xyz,
1040 \\};
1041 \\
1042 );
1043}
1044
10451022const std = @import("std");
10461023const mem = std.mem;
10471024const warn = std.debug.warn;