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 {...@@ -3875,9 +3875,9 @@ pub const Parser = struct {
3875 if (field_inits.len == 1) {3875 if (field_inits.len == 1) {
3876 const field_init = field_inits.at(0);3876 const field_init = field_inits.at(0);
38773877
3878 try stack.append(RenderState { .Text = "}" });3878 try stack.append(RenderState { .Text = " }" });
3879 try stack.append(RenderState { .FieldInitializer = field_init });3879 try stack.append(RenderState { .FieldInitializer = field_init });
3880 try stack.append(RenderState { .Text = " {" });3880 try stack.append(RenderState { .Text = "{ " });
3881 try stack.append(RenderState { .Expression = suffix_op.lhs });3881 try stack.append(RenderState { .Expression = suffix_op.lhs });
3882 continue;3882 continue;
3883 }3883 }
...@@ -3893,7 +3893,7 @@ pub const Parser = struct {...@@ -3893,7 +3893,7 @@ pub const Parser = struct {
3893 try stack.append(RenderState.PrintIndent);3893 try stack.append(RenderState.PrintIndent);
3894 }3894 }
3895 try stack.append(RenderState { .Indent = indent + indent_delta });3895 try stack.append(RenderState { .Indent = indent + indent_delta });
3896 try stack.append(RenderState { .Text = " {\n"});3896 try stack.append(RenderState { .Text = "{\n"});
3897 try stack.append(RenderState { .Expression = suffix_op.lhs });3897 try stack.append(RenderState { .Expression = suffix_op.lhs });
3898 },3898 },
3899 ast.Node.SuffixOp.Op.ArrayInitializer => |exprs| {3899 ast.Node.SuffixOp.Op.ArrayInitializer => |exprs| {
...@@ -3907,7 +3907,7 @@ pub const Parser = struct {...@@ -3907,7 +3907,7 @@ pub const Parser = struct {
39073907
3908 try stack.append(RenderState { .Text = "}" });3908 try stack.append(RenderState { .Text = "}" });
3909 try stack.append(RenderState { .Expression = expr });3909 try stack.append(RenderState { .Expression = expr });
3910 try stack.append(RenderState { .Text = " {" });3910 try stack.append(RenderState { .Text = "{" });
3911 try stack.append(RenderState { .Expression = suffix_op.lhs });3911 try stack.append(RenderState { .Expression = suffix_op.lhs });
3912 continue;3912 continue;
3913 }3913 }
...@@ -3924,7 +3924,7 @@ pub const Parser = struct {...@@ -3924,7 +3924,7 @@ pub const Parser = struct {
3924 try stack.append(RenderState.PrintIndent);3924 try stack.append(RenderState.PrintIndent);
3925 }3925 }
3926 try stack.append(RenderState { .Indent = indent + indent_delta });3926 try stack.append(RenderState { .Indent = indent + indent_delta });
3927 try stack.append(RenderState { .Text = " {\n"});3927 try stack.append(RenderState { .Text = "{\n"});
3928 try stack.append(RenderState { .Expression = suffix_op.lhs });3928 try stack.append(RenderState { .Expression = suffix_op.lhs });
3929 },3929 },
3930 }3930 }
std/zig/parser_test.zig+9-32
...@@ -1,12 +1,3 @@...@@ -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
10test "zig fmt: union(enum(u32)) with assigned enum values" {1test "zig fmt: union(enum(u32)) with assigned enum values" {
11 try testCanonical(2 try testCanonical(
12 \\const MultipleChoice = union(enum(u32)) {3 \\const MultipleChoice = union(enum(u32)) {
...@@ -124,7 +115,7 @@ test "zig fmt: same-line comment after field decl" {...@@ -124,7 +115,7 @@ test "zig fmt: same-line comment after field decl" {
124115
125test "zig fmt: array literal with 1 item on 1 line" {116test "zig fmt: array literal with 1 item on 1 line" {
126 try testCanonical(117 try testCanonical(
127 \\var s = []const u64 {0} ** 25;118 \\var s = []const u64{0} ** 25;
128 \\119 \\
129 );120 );
130}121}
...@@ -625,11 +616,11 @@ test "zig fmt: error set declaration" {...@@ -625,11 +616,11 @@ test "zig fmt: error set declaration" {
625test "zig fmt: arrays" {616test "zig fmt: arrays" {
626 try testCanonical(617 try testCanonical(
627 \\test "test array" {618 \\test "test array" {
628 \\ const a: [2]u8 = [2]u8 {619 \\ const a: [2]u8 = [2]u8{
629 \\ 1,620 \\ 1,
630 \\ 2,621 \\ 2,
631 \\ };622 \\ };
632 \\ const a: [2]u8 = []u8 {623 \\ const a: [2]u8 = []u8{
633 \\ 1,624 \\ 1,
634 \\ 2,625 \\ 2,
635 \\ };626 \\ };
...@@ -641,15 +632,17 @@ test "zig fmt: arrays" {...@@ -641,15 +632,17 @@ test "zig fmt: arrays" {
641632
642test "zig fmt: container initializers" {633test "zig fmt: container initializers" {
643 try testCanonical(634 try testCanonical(
644 \\const a1 = []u8{};635 \\const a0 = []u8{};
645 \\const a2 = []u8 {636 \\const a1 = []u8{1};
637 \\const a2 = []u8{
646 \\ 1,638 \\ 1,
647 \\ 2,639 \\ 2,
648 \\ 3,640 \\ 3,
649 \\ 4,641 \\ 4,
650 \\};642 \\};
651 \\const s1 = S{};643 \\const s0 = S{};
652 \\const s2 = S {644 \\const s1 = S{ .a = 1 };
645 \\const s2 = S{
653 \\ .a = 1,646 \\ .a = 1,
654 \\ .b = 2,647 \\ .b = 2,
655 \\};648 \\};
...@@ -718,7 +711,6 @@ test "zig fmt: switch" {...@@ -718,7 +711,6 @@ test "zig fmt: switch" {
718 \\ Float: f64,711 \\ Float: f64,
719 \\ };712 \\ };
720 \\713 \\
721 \\ const u = Union {.Int = 0};
722 \\ switch (u) {714 \\ switch (u) {
723 \\ Union.Int => |int| {},715 \\ Union.Int => |int| {},
724 \\ Union.Float => |*float| unreachable,716 \\ Union.Float => |*float| unreachable,
...@@ -797,11 +789,6 @@ test "zig fmt: while" {...@@ -797,11 +789,6 @@ test "zig fmt: while" {
797test "zig fmt: for" {789test "zig fmt: for" {
798 try testCanonical(790 try testCanonical(
799 \\test "for" {791 \\test "for" {
800 \\ const a = []u8 {
801 \\ 1,
802 \\ 2,
803 \\ 3,
804 \\ };
805 \\ for (a) |v| {792 \\ for (a) |v| {
806 \\ continue;793 \\ continue;
807 \\ }794 \\ }
...@@ -1032,16 +1019,6 @@ test "zig fmt: error return" {...@@ -1032,16 +1019,6 @@ test "zig fmt: error return" {
1032 );1019 );
1033}1020}
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
1045const std = @import("std");1022const std = @import("std");
1046const mem = std.mem;1023const mem = std.mem;
1047const warn = std.debug.warn;1024const warn = std.debug.warn;