mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
parent
8da9cc85af
commit
68d2f68ed8
4 changed files with 107 additions and 72 deletions
|
|
@ -5500,6 +5500,35 @@ test "zig fmt: canonicalize symbols (keywords)" {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "zig fmt: no space before newline before multiline string" {
|
||||||
|
try testCanonical(
|
||||||
|
\\const S = struct {
|
||||||
|
\\ text: []const u8,
|
||||||
|
\\ comment: []const u8,
|
||||||
|
\\};
|
||||||
|
\\
|
||||||
|
\\test {
|
||||||
|
\\ const s1 = .{
|
||||||
|
\\ .text =
|
||||||
|
\\ \\hello
|
||||||
|
\\ \\world
|
||||||
|
\\ ,
|
||||||
|
\\ .comment = "test",
|
||||||
|
\\ };
|
||||||
|
\\ _ = s1;
|
||||||
|
\\ const s2 = .{
|
||||||
|
\\ .comment = "test",
|
||||||
|
\\ .text =
|
||||||
|
\\ \\hello
|
||||||
|
\\ \\world
|
||||||
|
\\ ,
|
||||||
|
\\ };
|
||||||
|
\\ _ = s2;
|
||||||
|
\\}
|
||||||
|
\\
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Normalize \xNN and \u{NN} escapes and unicode inside @"" escapes.
|
// Normalize \xNN and \u{NN} escapes and unicode inside @"" escapes.
|
||||||
test "zig fmt: canonicalize symbols (character escapes)" {
|
test "zig fmt: canonicalize symbols (character escapes)" {
|
||||||
try testTransform(
|
try testTransform(
|
||||||
|
|
|
||||||
|
|
@ -1675,7 +1675,12 @@ fn renderStructInit(
|
||||||
|
|
||||||
try renderToken(ais, tree, struct_init.ast.lbrace + 1, .none); // .
|
try renderToken(ais, tree, struct_init.ast.lbrace + 1, .none); // .
|
||||||
try renderIdentifier(ais, tree, struct_init.ast.lbrace + 2, .space, .eagerly_unquote); // name
|
try renderIdentifier(ais, tree, struct_init.ast.lbrace + 2, .space, .eagerly_unquote); // name
|
||||||
try renderToken(ais, tree, struct_init.ast.lbrace + 3, .space); // =
|
// Don't output a space after the = if expression is a multiline string,
|
||||||
|
// since then it will start on the next line.
|
||||||
|
const nodes = tree.nodes.items(.tag);
|
||||||
|
const expr = nodes[struct_init.ast.fields[0]];
|
||||||
|
var space_after_equal: Space = if (expr == .multiline_string_literal) .none else .space;
|
||||||
|
try renderToken(ais, tree, struct_init.ast.lbrace + 3, space_after_equal); // =
|
||||||
try renderExpression(gpa, ais, tree, struct_init.ast.fields[0], .comma);
|
try renderExpression(gpa, ais, tree, struct_init.ast.fields[0], .comma);
|
||||||
|
|
||||||
for (struct_init.ast.fields[1..]) |field_init| {
|
for (struct_init.ast.fields[1..]) |field_init| {
|
||||||
|
|
@ -1683,7 +1688,8 @@ fn renderStructInit(
|
||||||
try renderExtraNewlineToken(ais, tree, init_token - 3);
|
try renderExtraNewlineToken(ais, tree, init_token - 3);
|
||||||
try renderToken(ais, tree, init_token - 3, .none); // .
|
try renderToken(ais, tree, init_token - 3, .none); // .
|
||||||
try renderIdentifier(ais, tree, init_token - 2, .space, .eagerly_unquote); // name
|
try renderIdentifier(ais, tree, init_token - 2, .space, .eagerly_unquote); // name
|
||||||
try renderToken(ais, tree, init_token - 1, .space); // =
|
space_after_equal = if (nodes[field_init] == .multiline_string_literal) .none else .space;
|
||||||
|
try renderToken(ais, tree, init_token - 1, space_after_equal); // =
|
||||||
try renderExpression(gpa, ais, tree, field_init, .comma);
|
try renderExpression(gpa, ais, tree, field_init, .comma);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue