zig fmt: multiline string literals + array init

This commit is contained in:
Andrew Kelley
2021-02-23 17:00:33 -07:00
parent 6f4a1bafcf
commit bb89c619ed
2 changed files with 91 additions and 62 deletions

View File

@@ -3986,68 +3986,71 @@ test "zig fmt: allow trailing line comments to do manual array formatting" {
);
}
//test "zig fmt: multiline string literals should play nice with array initializers" {
// try testCanonical(
// \\fn main() void {
// \\ var a = .{.{.{.{.{.{.{.{
// \\ 0,
// \\ }}}}}}}};
// \\ myFunc(.{
// \\ "aaaaaaa", "bbbbbb", "ccccc",
// \\ "dddd", ("eee"), ("fff"),
// \\ ("gggg"),
// \\ // Line comment
// \\ \\Multiline String Literals can be quite long
// \\ ,
// \\ \\Multiline String Literals can be quite long
// \\ \\Multiline String Literals can be quite long
// \\ ,
// \\ \\Multiline String Literals can be quite long
// \\ \\Multiline String Literals can be quite long
// \\ \\Multiline String Literals can be quite long
// \\ \\Multiline String Literals can be quite long
// \\ ,
// \\ (
// \\ \\Multiline String Literals can be quite long
// \\ ),
// \\ .{
// \\ \\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// \\ \\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// \\ \\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// \\ },
// \\ .{(
// \\ \\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// \\ )},
// \\ .{
// \\ "xxxxxxx", "xxx",
// \\ (
// \\ \\ xxx
// \\ ),
// \\ "xxx", "xxx",
// \\ },
// \\ .{ "xxxxxxx", "xxx", "xxx", "xxx" }, .{ "xxxxxxx", "xxx", "xxx", "xxx" },
// \\ "aaaaaaa", "bbbbbb", "ccccc", // -
// \\ "dddd", ("eee"), ("fff"),
// \\ .{
// \\ "xxx", "xxx",
// \\ (
// \\ \\ xxx
// \\ ),
// \\ "xxxxxxxxxxxxxx", "xxx",
// \\ },
// \\ .{
// \\ (
// \\ \\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// \\ ),
// \\ \\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// \\ },
// \\ \\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// \\ \\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// \\ });
// \\}
// \\
// );
//}
test "zig fmt: multiline string literals should play nice with array initializers" {
try testCanonical(
\\fn main() void {
\\ var a = .{.{.{.{.{.{.{.{
\\ 0,
\\ }}}}}}}};
\\ myFunc(.{
\\ "aaaaaaa", "bbbbbb", "ccccc",
\\ "dddd", ("eee"), ("fff"),
\\ ("gggg"),
\\ // Line comment
\\ \\Multiline String Literals can be quite long
\\ ,
\\ \\Multiline String Literals can be quite long
\\ \\Multiline String Literals can be quite long
\\ ,
\\ \\Multiline String Literals can be quite long
\\ \\Multiline String Literals can be quite long
\\ \\Multiline String Literals can be quite long
\\ \\Multiline String Literals can be quite long
\\ ,
\\ (
\\ \\Multiline String Literals can be quite long
\\ ),
\\ .{
\\ \\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\\ \\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\\ \\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\\ },
\\ .{(
\\ \\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\\ )},
\\ .{
\\ "xxxxxxx", "xxx",
\\ (
\\ \\ xxx
\\ ),
\\ "xxx",
\\ "xxx",
\\ },
\\ .{ "xxxxxxx", "xxx", "xxx", "xxx" },
\\ .{ "xxxxxxx", "xxx", "xxx", "xxx" },
\\ "aaaaaaa", "bbbbbb", "ccccc", // -
\\ "dddd", ("eee"), ("fff"),
\\ .{
\\ "xxx", "xxx",
\\ (
\\ \\ xxx
\\ ),
\\ "xxxxxxxxxxxxxx",
\\ "xxx",
\\ },
\\ .{
\\ (
\\ \\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\\ ),
\\ \\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\\ },
\\ \\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\\ \\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\\ });
\\}
\\
);
}
test "zig fmt: use of comments and multiline string literals may force the parameters over multiple lines" {
try testCanonical(