zig fmt: consistent spacing for container inits

This commit is contained in:
Andrew Kelley 2018-04-30 18:49:05 -04:00
parent eed49a2104
commit 3e61c45f89
2 changed files with 14 additions and 37 deletions

View File

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

View File

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