commit 7193385f942eaaf9a8bc1307e9997176002b6259 (tree)
parent 174a275c76afd10be79d399132765f0f2c1cea99
Author: Motiejus Jakštys <motiejus@jakstys.lt>
Date: Wed, 11 Feb 2026 09:28:05 +0000
parser: reorder tests, fix check_test_order.py for new file layout
Update check_test_order.py to handle header/footer split correctly
when infrastructure code is at both start and end of file.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Diffstat:
2 files changed, 477 insertions(+), 153 deletions(-)
diff --git a/check_test_order.py b/check_test_order.py
@@ -14,20 +14,23 @@ def extract_test_names(path):
def extract_test_blocks(path):
- """Split file into infrastructure + list of (name, content) test blocks."""
+ """Split file into: header, list of (name, content) test blocks, footer."""
with open(path) as f:
lines = f.readlines()
- infra = []
+ header = []
+ footer = []
blocks = []
current_name = None
current_lines = []
brace_depth = 0
in_test = False
+ found_first_test = False
for line in lines:
m = re.match(r'^test "(.+?)" \{', line)
if m and not in_test:
+ found_first_test = True
if current_name is not None:
blocks.append((current_name, "".join(current_lines)))
current_name = m.group(1)
@@ -41,13 +44,35 @@ def extract_test_blocks(path):
brace_depth += line.count("{") - line.count("}")
if brace_depth == 0:
in_test = False
- elif current_name is None:
- infra.append(line)
+ elif not found_first_test:
+ header.append(line)
+ else:
+ # Non-test content after tests started — could be blank lines
+ # between tests or footer content
+ if current_name is not None:
+ # Append to previous test block as trailing content
+ current_lines.append(line)
+ else:
+ footer.append(line)
if current_name is not None:
blocks.append((current_name, "".join(current_lines)))
- return "".join(infra), blocks
+ # Anything after the last test block is footer
+ # Split last block's trailing non-test content into footer
+ if blocks:
+ last_name, last_content = blocks[-1]
+ last_lines = last_content.split('\n')
+ # Find where the test block ends (} at column 0)
+ test_end = len(last_lines)
+ for i, line in enumerate(last_lines):
+ if line == '}' and i > 0:
+ test_end = i + 1
+ if test_end < len(last_lines):
+ blocks[-1] = (last_name, '\n'.join(last_lines[:test_end]) + '\n')
+ footer = ['\n'.join(last_lines[test_end:]) + '\n'] + footer
+
+ return "".join(header), blocks, "".join(footer)
def main():
@@ -88,7 +113,7 @@ def main():
return 1
# Fix: reorder
- infra, blocks = extract_test_blocks(OURS)
+ header, blocks, footer = extract_test_blocks(OURS)
block_map = {name: content for name, content in blocks}
# Reorder: upstream-ordered first, then extras
@@ -104,11 +129,11 @@ def main():
seen.add(name)
with open(OURS, "w") as f:
- f.write(infra)
+ f.write(header)
for _, content in ordered:
f.write("\n")
f.write(content)
- f.write("\n")
+ f.write(footer)
print(f"Fixed: {len(ordered)} tests reordered")
return 0
diff --git a/parser_test.zig b/parser_test.zig
@@ -4,6 +4,7 @@ const print = std.debug.print;
const io = std.io;
const maxInt = std.math.maxInt;
+
test "zig fmt: remove extra whitespace at start and end of file with comment between" {
try testTransform(
\\
@@ -17,6 +18,7 @@ test "zig fmt: remove extra whitespace at start and end of file with comment bet
);
}
+
test "zig fmt: tuple struct" {
try testCanonical(
\\const T = struct {
@@ -31,6 +33,7 @@ test "zig fmt: tuple struct" {
);
}
+
test "zig fmt: preserves clobbers in inline asm with stray comma" {
try testTransform(
\\fn foo() void {
@@ -63,6 +66,7 @@ test "zig fmt: preserves clobbers in inline asm with stray comma" {
);
}
+
test "zig fmt: remove trailing comma at the end of assembly clobber" {
try testTransform(
\\fn foo() void {
@@ -85,6 +89,7 @@ test "zig fmt: remove trailing comma at the end of assembly clobber" {
);
}
+
test "zig fmt: respect line breaks in struct field value declaration" {
try testCanonical(
\\const Foo = struct {
@@ -110,6 +115,7 @@ test "zig fmt: respect line breaks in struct field value declaration" {
);
}
+
test "zig fmt: respect line breaks before functions" {
try testCanonical(
\\const std = @import("std");
@@ -127,6 +133,7 @@ test "zig fmt: respect line breaks before functions" {
);
}
+
test "zig fmt: rewrite callconv(.@\"inline\") to the inline keyword" {
try testTransform(
\\fn foo() callconv(.@"inline") void {}
@@ -141,6 +148,7 @@ test "zig fmt: rewrite callconv(.@\"inline\") to the inline keyword" {
);
}
+
test "zig fmt: simple top level comptime block" {
try testCanonical(
\\// line comment
@@ -149,6 +157,7 @@ test "zig fmt: simple top level comptime block" {
);
}
+
test "zig fmt: two spaced line comments before decl" {
try testCanonical(
\\// line comment
@@ -159,6 +168,7 @@ test "zig fmt: two spaced line comments before decl" {
);
}
+
test "zig fmt: respect line breaks after var declarations" {
try testCanonical(
\\const crc =
@@ -174,6 +184,7 @@ test "zig fmt: respect line breaks after var declarations" {
);
}
+
test "zig fmt: multiline string mixed with comments" {
try testCanonical(
\\const s1 =
@@ -204,12 +215,14 @@ test "zig fmt: multiline string mixed with comments" {
);
}
+
test "zig fmt: empty file" {
try testCanonical(
\\
);
}
+
test "zig fmt: file ends in comment" {
try testTransform(
\\ //foobar
@@ -219,6 +232,7 @@ test "zig fmt: file ends in comment" {
);
}
+
test "zig fmt: file ends in multi line comment" {
try testTransform(
\\ \\foobar
@@ -228,6 +242,7 @@ test "zig fmt: file ends in multi line comment" {
);
}
+
test "zig fmt: file ends in comment after var decl" {
try testTransform(
\\const x = 42;
@@ -239,6 +254,7 @@ test "zig fmt: file ends in comment after var decl" {
);
}
+
test "zig fmt: if statement" {
try testCanonical(
\\test "" {
@@ -249,6 +265,7 @@ test "zig fmt: if statement" {
);
}
+
test "zig fmt: top-level fields" {
try testCanonical(
\\a: did_you_know,
@@ -258,6 +275,7 @@ test "zig fmt: top-level fields" {
);
}
+
test "zig fmt: top-level tuple function call type" {
try testCanonical(
\\foo()
@@ -265,6 +283,7 @@ test "zig fmt: top-level tuple function call type" {
);
}
+
test "zig fmt: top-level enum missing 'const name ='" {
try testError(
\\enum(u32)
@@ -272,6 +291,7 @@ test "zig fmt: top-level enum missing 'const name ='" {
, &[_]Error{.expected_token});
}
+
test "zig fmt: top-level for/while loop" {
try testCanonical(
\\for (foo) |_| foo
@@ -283,6 +303,7 @@ test "zig fmt: top-level for/while loop" {
);
}
+
test "zig fmt: top-level bare asterisk+identifier" {
try testCanonical(
\\*x
@@ -290,6 +311,7 @@ test "zig fmt: top-level bare asterisk+identifier" {
);
}
+
test "zig fmt: top-level bare asterisk+asterisk+identifier" {
try testCanonical(
\\**x
@@ -297,6 +319,7 @@ test "zig fmt: top-level bare asterisk+asterisk+identifier" {
);
}
+
test "zig fmt: errdefer with payload" {
try testCanonical(
\\pub fn main() anyerror!void {
@@ -310,6 +333,7 @@ test "zig fmt: errdefer with payload" {
);
}
+
test "zig fmt: nosuspend block" {
try testCanonical(
\\pub fn main() anyerror!void {
@@ -321,6 +345,7 @@ test "zig fmt: nosuspend block" {
);
}
+
test "zig fmt: container declaration, single line" {
try testCanonical(
\\const X = struct { foo: i32 };
@@ -332,6 +357,7 @@ test "zig fmt: container declaration, single line" {
);
}
+
test "zig fmt: container declaration, one item, multi line trailing comma" {
try testCanonical(
\\test "" {
@@ -345,6 +371,7 @@ test "zig fmt: container declaration, one item, multi line trailing comma" {
);
}
+
test "zig fmt: container declaration, no trailing comma on separate line" {
try testTransform(
\\test "" {
@@ -365,6 +392,7 @@ test "zig fmt: container declaration, no trailing comma on separate line" {
);
}
+
test "zig fmt: container declaration, line break, no trailing comma" {
try testTransform(
\\const X = struct {
@@ -375,6 +403,7 @@ test "zig fmt: container declaration, line break, no trailing comma" {
);
}
+
test "zig fmt: container declaration, transform trailing comma" {
try testTransform(
\\const X = struct {
@@ -388,6 +417,7 @@ test "zig fmt: container declaration, transform trailing comma" {
);
}
+
test "zig fmt: container declaration, comment, add trailing comma" {
try testTransform(
\\const X = struct {
@@ -413,6 +443,7 @@ test "zig fmt: container declaration, comment, add trailing comma" {
);
}
+
test "zig fmt: container declaration, multiline string, add trailing comma" {
try testTransform(
\\const X = struct {
@@ -432,6 +463,7 @@ test "zig fmt: container declaration, multiline string, add trailing comma" {
);
}
+
test "zig fmt: container declaration, doc comment on member, add trailing comma" {
try testTransform(
\\pub const Pos = struct {
@@ -451,6 +483,7 @@ test "zig fmt: container declaration, doc comment on member, add trailing comma"
);
}
+
test "zig fmt: remove empty lines at start/end of container decl" {
try testTransform(
\\const X = struct {
@@ -471,6 +504,7 @@ test "zig fmt: remove empty lines at start/end of container decl" {
);
}
+
test "zig fmt: remove empty lines at start/end of block" {
try testTransform(
\\test {
@@ -491,6 +525,7 @@ test "zig fmt: remove empty lines at start/end of block" {
);
}
+
test "zig fmt: allow empty line before comment at start of block" {
try testCanonical(
\\test {
@@ -502,6 +537,7 @@ test "zig fmt: allow empty line before comment at start of block" {
);
}
+
test "zig fmt: trailing comma in fn parameter list" {
try testCanonical(
\\pub fn f(
@@ -544,6 +580,7 @@ test "zig fmt: trailing comma in fn parameter list" {
);
}
+
test "zig fmt: comptime struct field" {
try testCanonical(
\\const Foo = struct {
@@ -554,6 +591,7 @@ test "zig fmt: comptime struct field" {
);
}
+
test "zig fmt: break from block" {
try testCanonical(
\\const a = blk: {
@@ -572,6 +610,7 @@ test "zig fmt: break from block" {
);
}
+
test "zig fmt: grouped expressions (parentheses)" {
try testCanonical(
\\const r = (x + y) * (a + b);
@@ -579,6 +618,7 @@ test "zig fmt: grouped expressions (parentheses)" {
);
}
+
test "zig fmt: c pointer type" {
try testCanonical(
\\pub extern fn repro() [*c]const u8;
@@ -586,6 +626,7 @@ test "zig fmt: c pointer type" {
);
}
+
test "zig fmt: builtin call with trailing comma" {
try testCanonical(
\\pub fn main() void {
@@ -601,6 +642,7 @@ test "zig fmt: builtin call with trailing comma" {
);
}
+
test "zig fmt: asm expression with comptime content" {
try testTransform(
\\comptime {
@@ -645,6 +687,7 @@ test "zig fmt: asm expression with comptime content" {
);
}
+
test "zig fmt: array types last token" {
try testCanonical(
\\test {
@@ -658,6 +701,7 @@ test "zig fmt: array types last token" {
);
}
+
test "zig fmt: sentinel-terminated array type" {
try testCanonical(
\\pub fn cStrToPrefixedFileW(s: [*:0]const u8) ![PATH_MAX_WIDE:0]u16 {
@@ -667,6 +711,7 @@ test "zig fmt: sentinel-terminated array type" {
);
}
+
test "zig fmt: sentinel-terminated slice type" {
try testCanonical(
\\pub fn toSlice(self: Buffer) [:0]u8 {
@@ -676,6 +721,7 @@ test "zig fmt: sentinel-terminated slice type" {
);
}
+
test "zig fmt: pointer-to-one with modifiers" {
try testCanonical(
\\const x: *u32 = undefined;
@@ -685,6 +731,7 @@ test "zig fmt: pointer-to-one with modifiers" {
);
}
+
test "zig fmt: pointer-to-many with modifiers" {
try testCanonical(
\\const x: [*]u32 = undefined;
@@ -694,6 +741,7 @@ test "zig fmt: pointer-to-many with modifiers" {
);
}
+
test "zig fmt: sentinel pointer with modifiers" {
try testCanonical(
\\const x: [*:42]u32 = undefined;
@@ -703,6 +751,7 @@ test "zig fmt: sentinel pointer with modifiers" {
);
}
+
test "zig fmt: c pointer with modifiers" {
try testCanonical(
\\const x: [*c]u32 = undefined;
@@ -712,6 +761,7 @@ test "zig fmt: c pointer with modifiers" {
);
}
+
test "zig fmt: slice with modifiers" {
try testCanonical(
\\const x: []u32 = undefined;
@@ -720,6 +770,7 @@ test "zig fmt: slice with modifiers" {
);
}
+
test "zig fmt: sentinel slice with modifiers" {
try testCanonical(
\\const x: [:42]u32 = undefined;
@@ -728,6 +779,7 @@ test "zig fmt: sentinel slice with modifiers" {
);
}
+
test "zig fmt: anon literal in array" {
try testCanonical(
\\var arr: [2]Foo = .{
@@ -738,6 +790,7 @@ test "zig fmt: anon literal in array" {
);
}
+
test "zig fmt: alignment in anonymous literal" {
try testTransform(
\\const a = .{
@@ -756,6 +809,7 @@ test "zig fmt: alignment in anonymous literal" {
);
}
+
test "zig fmt: anon struct literal 0 element" {
try testCanonical(
\\test {
@@ -765,6 +819,7 @@ test "zig fmt: anon struct literal 0 element" {
);
}
+
test "zig fmt: anon struct literal 1 element" {
try testCanonical(
\\test {
@@ -774,6 +829,7 @@ test "zig fmt: anon struct literal 1 element" {
);
}
+
test "zig fmt: anon struct literal 1 element comma" {
try testCanonical(
\\test {
@@ -785,6 +841,7 @@ test "zig fmt: anon struct literal 1 element comma" {
);
}
+
test "zig fmt: anon struct literal 2 element" {
try testCanonical(
\\test {
@@ -794,6 +851,7 @@ test "zig fmt: anon struct literal 2 element" {
);
}
+
test "zig fmt: anon struct literal 2 element comma" {
try testCanonical(
\\test {
@@ -806,6 +864,7 @@ test "zig fmt: anon struct literal 2 element comma" {
);
}
+
test "zig fmt: anon struct literal 3 element" {
try testCanonical(
\\test {
@@ -815,6 +874,7 @@ test "zig fmt: anon struct literal 3 element" {
);
}
+
test "zig fmt: anon struct literal 3 element comma" {
try testCanonical(
\\test {
@@ -828,6 +888,7 @@ test "zig fmt: anon struct literal 3 element comma" {
);
}
+
test "zig fmt: struct literal 0 element" {
try testCanonical(
\\test {
@@ -837,6 +898,7 @@ test "zig fmt: struct literal 0 element" {
);
}
+
test "zig fmt: struct literal 1 element" {
try testCanonical(
\\test {
@@ -846,6 +908,7 @@ test "zig fmt: struct literal 1 element" {
);
}
+
test "zig fmt: Unicode code point literal larger than u8" {
try testCanonical(
\\test {
@@ -857,6 +920,7 @@ test "zig fmt: Unicode code point literal larger than u8" {
);
}
+
test "zig fmt: struct literal 2 element" {
try testCanonical(
\\test {
@@ -866,6 +930,7 @@ test "zig fmt: struct literal 2 element" {
);
}
+
test "zig fmt: struct literal 2 element comma" {
try testCanonical(
\\test {
@@ -878,6 +943,7 @@ test "zig fmt: struct literal 2 element comma" {
);
}
+
test "zig fmt: struct literal 3 element" {
try testCanonical(
\\test {
@@ -887,6 +953,7 @@ test "zig fmt: struct literal 3 element" {
);
}
+
test "zig fmt: struct literal 3 element comma" {
try testCanonical(
\\test {
@@ -900,6 +967,7 @@ test "zig fmt: struct literal 3 element comma" {
);
}
+
test "zig fmt: anon list literal 1 element" {
try testCanonical(
\\test {
@@ -909,6 +977,7 @@ test "zig fmt: anon list literal 1 element" {
);
}
+
test "zig fmt: anon list literal 1 element comma" {
try testCanonical(
\\test {
@@ -920,6 +989,7 @@ test "zig fmt: anon list literal 1 element comma" {
);
}
+
test "zig fmt: anon list literal 2 element" {
try testCanonical(
\\test {
@@ -929,6 +999,7 @@ test "zig fmt: anon list literal 2 element" {
);
}
+
test "zig fmt: anon list literal 2 element comma" {
try testCanonical(
\\test {
@@ -941,6 +1012,7 @@ test "zig fmt: anon list literal 2 element comma" {
);
}
+
test "zig fmt: anon list literal 3 element" {
try testCanonical(
\\test {
@@ -950,6 +1022,7 @@ test "zig fmt: anon list literal 3 element" {
);
}
+
test "zig fmt: anon list literal 3 element comma" {
try testCanonical(
\\test {
@@ -965,6 +1038,7 @@ test "zig fmt: anon list literal 3 element comma" {
);
}
+
test "zig fmt: array literal 0 element" {
try testCanonical(
\\test {
@@ -974,6 +1048,7 @@ test "zig fmt: array literal 0 element" {
);
}
+
test "zig fmt: array literal 1 element" {
try testCanonical(
\\test {
@@ -983,6 +1058,7 @@ test "zig fmt: array literal 1 element" {
);
}
+
test "zig fmt: array literal 1 element comma" {
try testCanonical(
\\test {
@@ -994,6 +1070,7 @@ test "zig fmt: array literal 1 element comma" {
);
}
+
test "zig fmt: array literal 2 element" {
try testCanonical(
\\test {
@@ -1003,6 +1080,7 @@ test "zig fmt: array literal 2 element" {
);
}
+
test "zig fmt: array literal 2 element comma" {
try testCanonical(
\\test {
@@ -1015,6 +1093,7 @@ test "zig fmt: array literal 2 element comma" {
);
}
+
test "zig fmt: array literal 3 element" {
try testCanonical(
\\test {
@@ -1024,6 +1103,7 @@ test "zig fmt: array literal 3 element" {
);
}
+
test "zig fmt: array literal 3 element comma" {
try testCanonical(
\\test {
@@ -1037,6 +1117,7 @@ test "zig fmt: array literal 3 element comma" {
);
}
+
test "zig fmt: sentinel array literal 1 element" {
try testCanonical(
\\test {
@@ -1046,6 +1127,7 @@ test "zig fmt: sentinel array literal 1 element" {
);
}
+
test "zig fmt: slices" {
try testCanonical(
\\const a = b[0..];
@@ -1056,6 +1138,7 @@ test "zig fmt: slices" {
);
}
+
test "zig fmt: slices with spaces in bounds" {
try testCanonical(
\\const a = b[0 + 0 ..];
@@ -1066,6 +1149,7 @@ test "zig fmt: slices with spaces in bounds" {
);
}
+
test "zig fmt: block in slice expression" {
try testCanonical(
\\const a = b[{
@@ -1084,6 +1168,7 @@ test "zig fmt: block in slice expression" {
);
}
+
test "zig fmt: whitespace fixes" {
try testTransform("test \"\" {\r\n\tconst hi = x;\r\n}\n// zig fmt: off\ntest \"\"{\r\n\tconst a = b;}\r\n",
\\test "" {
@@ -1096,6 +1181,7 @@ test "zig fmt: whitespace fixes" {
);
}
+
test "zig fmt: while else err prong with no block" {
try testCanonical(
\\test "" {
@@ -1108,6 +1194,7 @@ test "zig fmt: while else err prong with no block" {
);
}
+
test "zig fmt: tagged union with enum values" {
try testCanonical(
\\const MultipleChoice2 = union(enum(u32)) {
@@ -1125,6 +1212,7 @@ test "zig fmt: tagged union with enum values" {
);
}
+
test "zig fmt: tagged union enum tag last token" {
try testCanonical(
\\test {
@@ -1144,6 +1232,7 @@ test "zig fmt: tagged union enum tag last token" {
);
}
+
test "zig fmt: allowzero pointer" {
try testCanonical(
\\const T = [*]allowzero const u8;
@@ -1151,6 +1240,7 @@ test "zig fmt: allowzero pointer" {
);
}
+
test "zig fmt: empty enum decls" {
try testCanonical(
\\const A = enum {};
@@ -1161,6 +1251,7 @@ test "zig fmt: empty enum decls" {
);
}
+
test "zig fmt: empty union decls" {
try testCanonical(
\\const A = union {};
@@ -1172,6 +1263,7 @@ test "zig fmt: empty union decls" {
);
}
+
test "zig fmt: enum literal" {
try testCanonical(
\\const x = .hi;
@@ -1179,6 +1271,7 @@ test "zig fmt: enum literal" {
);
}
+
test "zig fmt: enum literal inside array literal" {
try testCanonical(
\\test "enums in arrays" {
@@ -1194,6 +1287,7 @@ test "zig fmt: enum literal inside array literal" {
);
}
+
test "zig fmt: character literal larger than u8" {
try testCanonical(
\\const x = '\u{01f4a9}';
@@ -1201,6 +1295,7 @@ test "zig fmt: character literal larger than u8" {
);
}
+
test "zig fmt: infix operator and then multiline string literal" {
try testCanonical(
\\const x = "" ++
@@ -1210,6 +1305,7 @@ test "zig fmt: infix operator and then multiline string literal" {
);
}
+
test "zig fmt: infix operator and then multiline string literal over multiple lines" {
try testCanonical(
\\const x = "" ++
@@ -1221,6 +1317,7 @@ test "zig fmt: infix operator and then multiline string literal over multiple li
);
}
+
test "zig fmt: C pointers" {
try testCanonical(
\\const Ptr = [*c]i32;
@@ -1228,6 +1325,7 @@ test "zig fmt: C pointers" {
);
}
+
test "zig fmt: threadlocal" {
try testCanonical(
\\threadlocal var x: i32 = 1234;
@@ -1235,6 +1333,7 @@ test "zig fmt: threadlocal" {
);
}
+
test "zig fmt: linksection" {
try testCanonical(
\\export var aoeu: u64 linksection(".text.derp") = 1234;
@@ -1243,6 +1342,7 @@ test "zig fmt: linksection" {
);
}
+
test "zig fmt: addrspace" {
try testCanonical(
\\export var python_length: u64 align(1) addrspace(.generic);
@@ -1253,6 +1353,7 @@ test "zig fmt: addrspace" {
);
}
+
test "zig fmt: correctly space struct fields with doc comments" {
try testTransform(
\\pub const S = struct {
@@ -1282,6 +1383,7 @@ test "zig fmt: correctly space struct fields with doc comments" {
);
}
+
test "zig fmt: doc comments on param decl" {
try testCanonical(
\\pub const Allocator = struct {
@@ -1303,6 +1405,7 @@ test "zig fmt: doc comments on param decl" {
);
}
+
test "zig fmt: aligned struct field" {
try testCanonical(
\\pub const S = struct {
@@ -1318,6 +1421,7 @@ test "zig fmt: aligned struct field" {
);
}
+
test "zig fmt: comment to disable/enable zig fmt first" {
try testCanonical(
\\// Test trailing comma syntax
@@ -1327,6 +1431,7 @@ test "zig fmt: comment to disable/enable zig fmt first" {
);
}
+
test "zig fmt: 'zig fmt: (off|on)' can be surrounded by arbitrary whitespace" {
try testTransform(
\\// Test trailing comma syntax
@@ -1346,6 +1451,7 @@ test "zig fmt: 'zig fmt: (off|on)' can be surrounded by arbitrary whitespace" {
);
}
+
test "zig fmt: comment to disable/enable zig fmt" {
try testTransform(
\\const a = b;
@@ -1363,6 +1469,7 @@ test "zig fmt: comment to disable/enable zig fmt" {
);
}
+
test "zig fmt: line comment following 'zig fmt: off'" {
try testCanonical(
\\// zig fmt: off
@@ -1371,6 +1478,7 @@ test "zig fmt: line comment following 'zig fmt: off'" {
);
}
+
test "zig fmt: doc comment following 'zig fmt: off'" {
try testCanonical(
\\// zig fmt: off
@@ -1379,6 +1487,7 @@ test "zig fmt: doc comment following 'zig fmt: off'" {
);
}
+
test "zig fmt: line and doc comment following 'zig fmt: off'" {
try testCanonical(
\\// zig fmt: off
@@ -1388,6 +1497,7 @@ test "zig fmt: line and doc comment following 'zig fmt: off'" {
);
}
+
test "zig fmt: doc and line comment following 'zig fmt: off'" {
try testCanonical(
\\// zig fmt: off
@@ -1397,6 +1507,7 @@ test "zig fmt: doc and line comment following 'zig fmt: off'" {
);
}
+
test "zig fmt: alternating 'zig fmt: off' and 'zig fmt: on'" {
try testCanonical(
\\// zig fmt: off
@@ -1414,6 +1525,7 @@ test "zig fmt: alternating 'zig fmt: off' and 'zig fmt: on'" {
);
}
+
test "zig fmt: line comment following 'zig fmt: on'" {
try testCanonical(
\\// zig fmt: off
@@ -1425,6 +1537,7 @@ test "zig fmt: line comment following 'zig fmt: on'" {
);
}
+
test "zig fmt: doc comment following 'zig fmt: on'" {
try testCanonical(
\\// zig fmt: off
@@ -1436,6 +1549,7 @@ test "zig fmt: doc comment following 'zig fmt: on'" {
);
}
+
test "zig fmt: line and doc comment following 'zig fmt: on'" {
try testCanonical(
\\// zig fmt: off
@@ -1448,6 +1562,7 @@ test "zig fmt: line and doc comment following 'zig fmt: on'" {
);
}
+
test "zig fmt: doc and line comment following 'zig fmt: on'" {
try testCanonical(
\\// zig fmt: off
@@ -1460,6 +1575,7 @@ test "zig fmt: doc and line comment following 'zig fmt: on'" {
);
}
+
test "zig fmt: 'zig fmt: (off|on)' works in the middle of code" {
try testTransform(
\\test "" {
@@ -1486,6 +1602,7 @@ test "zig fmt: 'zig fmt: (off|on)' works in the middle of code" {
);
}
+
test "zig fmt: 'zig fmt: on' indentation is unchanged" {
try testCanonical(
\\fn initOptionsAndLayouts(output: *Output, context: *Context) !void {
@@ -1507,6 +1624,7 @@ test "zig fmt: 'zig fmt: on' indentation is unchanged" {
);
}
+
test "zig fmt: pointer of unknown length" {
try testCanonical(
\\fn foo(ptr: [*]u8) void {}
@@ -1514,6 +1632,7 @@ test "zig fmt: pointer of unknown length" {
);
}
+
test "zig fmt: spaces around slice operator" {
try testCanonical(
\\var a = b[c..d];
@@ -1528,6 +1647,7 @@ test "zig fmt: spaces around slice operator" {
);
}
+
test "zig fmt: 2nd arg multiline string" {
try testCanonical(
\\comptime {
@@ -1556,6 +1676,7 @@ test "zig fmt: 2nd arg multiline string" {
);
}
+
test "zig fmt: 2nd arg multiline string many args" {
try testCanonical(
\\comptime {
@@ -1567,6 +1688,7 @@ test "zig fmt: 2nd arg multiline string many args" {
);
}
+
test "zig fmt: final arg multiline string" {
try testCanonical(
\\comptime {
@@ -1578,6 +1700,7 @@ test "zig fmt: final arg multiline string" {
);
}
+
test "zig fmt: if condition wraps" {
try testTransform(
\\comptime {
@@ -1659,6 +1782,7 @@ test "zig fmt: if condition wraps" {
);
}
+
test "zig fmt: if condition has line break but must not wrap" {
try testCanonical(
\\comptime {
@@ -1683,6 +1807,7 @@ test "zig fmt: if condition has line break but must not wrap" {
);
}
+
test "zig fmt: if condition has line break but must not wrap (no fn call comma)" {
try testCanonical(
\\comptime {
@@ -1704,6 +1829,7 @@ test "zig fmt: if condition has line break but must not wrap (no fn call comma)"
);
}
+
test "zig fmt: function call with multiline argument" {
try testCanonical(
\\comptime {
@@ -1716,6 +1842,7 @@ test "zig fmt: function call with multiline argument" {
);
}
+
test "zig fmt: if-else with comment before else" {
try testCanonical(
\\comptime {
@@ -1734,6 +1861,7 @@ test "zig fmt: if-else with comment before else" {
);
}
+
test "zig fmt: if nested" {
try testCanonical(
\\pub fn foo() void {
@@ -1757,6 +1885,7 @@ test "zig fmt: if nested" {
);
}
+
test "zig fmt: respect line breaks in if-else" {
try testCanonical(
\\comptime {
@@ -1776,6 +1905,7 @@ test "zig fmt: respect line breaks in if-else" {
);
}
+
test "zig fmt: respect line breaks after infix operators" {
try testCanonical(
\\comptime {
@@ -1793,6 +1923,7 @@ test "zig fmt: respect line breaks after infix operators" {
);
}
+
test "zig fmt: fn decl with trailing comma" {
try testTransform(
\\fn foo(a: i32, b: i32,) void {}
@@ -1805,6 +1936,7 @@ test "zig fmt: fn decl with trailing comma" {
);
}
+
test "zig fmt: enum decl with no trailing comma" {
try testTransform(
\\const StrLitKind = enum {Normal, C};
@@ -1814,6 +1946,7 @@ test "zig fmt: enum decl with no trailing comma" {
);
}
+
test "zig fmt: switch comment before prong" {
try testCanonical(
\\comptime {
@@ -1826,6 +1959,7 @@ test "zig fmt: switch comment before prong" {
);
}
+
test "zig fmt: switch comment after prong" {
try testCanonical(
\\comptime {
@@ -1839,6 +1973,7 @@ test "zig fmt: switch comment after prong" {
);
}
+
test "zig fmt: struct literal no trailing comma" {
try testTransform(
\\const a = foo{ .x = 1, .y = 2 };
@@ -1857,6 +1992,7 @@ test "zig fmt: struct literal no trailing comma" {
);
}
+
test "zig fmt: struct literal containing a multiline expression" {
try testTransform(
\\const a = A{ .x = if (f1()) 10 else 20 };
@@ -1918,6 +2054,7 @@ test "zig fmt: struct literal containing a multiline expression" {
);
}
+
test "zig fmt: array literal with hint" {
try testTransform(
\\const a = []u8{
@@ -1995,6 +2132,7 @@ test "zig fmt: array literal with hint" {
);
}
+
test "zig fmt: array literal vertical column alignment" {
try testTransform(
\\const a = []u8{
@@ -2042,6 +2180,7 @@ test "zig fmt: array literal vertical column alignment" {
);
}
+
test "zig fmt: multiline string with backslash at end of line" {
try testCanonical(
\\comptime {
@@ -2053,6 +2192,7 @@ test "zig fmt: multiline string with backslash at end of line" {
);
}
+
test "zig fmt: multiline string parameter in fn call with trailing comma" {
try testCanonical(
\\fn foo() void {
@@ -2071,6 +2211,7 @@ test "zig fmt: multiline string parameter in fn call with trailing comma" {
);
}
+
test "zig fmt: trailing comma on fn call" {
try testCanonical(
\\comptime {
@@ -2084,6 +2225,7 @@ test "zig fmt: trailing comma on fn call" {
);
}
+
test "zig fmt: multi line arguments without last comma" {
try testTransform(
\\pub fn foo(
@@ -2103,6 +2245,7 @@ test "zig fmt: multi line arguments without last comma" {
);
}
+
test "zig fmt: empty block with only comment" {
try testCanonical(
\\comptime {
@@ -2114,6 +2257,7 @@ test "zig fmt: empty block with only comment" {
);
}
+
test "zig fmt: trailing commas on struct decl" {
try testTransform(
\\const RoundParam = struct {
@@ -2133,6 +2277,7 @@ test "zig fmt: trailing commas on struct decl" {
);
}
+
test "zig fmt: extra newlines at the end" {
try testTransform(
\\const a = b;
@@ -2145,6 +2290,7 @@ test "zig fmt: extra newlines at the end" {
);
}
+
test "zig fmt: simple asm" {
try testTransform(
\\comptime {
@@ -2182,6 +2328,7 @@ test "zig fmt: simple asm" {
);
}
+
test "zig fmt: nested struct literal with one item" {
try testCanonical(
\\const a = foo{
@@ -2191,6 +2338,7 @@ test "zig fmt: nested struct literal with one item" {
);
}
+
test "zig fmt: switch cases trailing comma" {
try testTransform(
\\test "switch cases trailing comma"{
@@ -2225,6 +2373,7 @@ test "zig fmt: switch cases trailing comma" {
);
}
+
test "zig fmt: slice align" {
try testCanonical(
\\const A = struct {
@@ -2234,6 +2383,7 @@ test "zig fmt: slice align" {
);
}
+
test "zig fmt: add trailing comma to array literal" {
try testTransform(
\\comptime {
@@ -2255,6 +2405,7 @@ test "zig fmt: add trailing comma to array literal" {
);
}
+
test "zig fmt: first thing in file is line comment" {
try testCanonical(
\\// Introspection and determination of system libraries needed by zig.
@@ -2266,6 +2417,7 @@ test "zig fmt: first thing in file is line comment" {
);
}
+
test "zig fmt: line comment after doc comment" {
try testCanonical(
\\/// doc comment
@@ -2275,6 +2427,7 @@ test "zig fmt: line comment after doc comment" {
);
}
+
test "zig fmt: bit field alignment" {
try testCanonical(
\\test {
@@ -2284,6 +2437,7 @@ test "zig fmt: bit field alignment" {
);
}
+
test "zig fmt: nested switch" {
try testCanonical(
\\test {
@@ -2298,6 +2452,7 @@ test "zig fmt: nested switch" {
);
}
+
test "zig fmt: float literal with exponent" {
try testCanonical(
\\pub const f64_true_min = 4.94065645841246544177e-324;
@@ -2306,6 +2461,7 @@ test "zig fmt: float literal with exponent" {
);
}
+
test "zig fmt: if-else end of comptime" {
try testCanonical(
\\comptime {
@@ -2319,6 +2475,7 @@ test "zig fmt: if-else end of comptime" {
);
}
+
test "zig fmt: nested blocks" {
try testCanonical(
\\comptime {
@@ -2334,6 +2491,7 @@ test "zig fmt: nested blocks" {
);
}
+
test "zig fmt: block with same line comment after end brace" {
try testCanonical(
\\comptime {
@@ -2345,6 +2503,7 @@ test "zig fmt: block with same line comment after end brace" {
);
}
+
test "zig fmt: statements with comment between" {
try testCanonical(
\\comptime {
@@ -2356,6 +2515,7 @@ test "zig fmt: statements with comment between" {
);
}
+
test "zig fmt: statements with empty line between" {
try testCanonical(
\\comptime {
@@ -2367,6 +2527,7 @@ test "zig fmt: statements with empty line between" {
);
}
+
test "zig fmt: ptr deref operator and unwrap optional operator" {
try testCanonical(
\\const a = b.*;
@@ -2375,6 +2536,7 @@ test "zig fmt: ptr deref operator and unwrap optional operator" {
);
}
+
test "zig fmt: comment after if before another if" {
try testCanonical(
\\test "aoeu" {
@@ -2397,6 +2559,7 @@ test "zig fmt: comment after if before another if" {
);
}
+
test "zig fmt: line comment between if block and else keyword" {
try testCanonical(
\\test "aoeu" {
@@ -2418,6 +2581,7 @@ test "zig fmt: line comment between if block and else keyword" {
);
}
+
test "zig fmt: same line comments in expression" {
try testCanonical(
\\test "aoeu" {
@@ -2429,6 +2593,7 @@ test "zig fmt: same line comments in expression" {
);
}
+
test "zig fmt: add comma on last switch prong" {
try testTransform(
\\test "aoeu" {
@@ -2458,6 +2623,7 @@ test "zig fmt: add comma on last switch prong" {
);
}
+
test "zig fmt: same-line comment after a statement" {
try testCanonical(
\\test "" {
@@ -2469,6 +2635,7 @@ test "zig fmt: same-line comment after a statement" {
);
}
+
test "zig fmt: same-line comment after var decl in struct" {
try testCanonical(
\\pub const vfs_cap_data = extern struct {
@@ -2478,6 +2645,7 @@ test "zig fmt: same-line comment after var decl in struct" {
);
}
+
test "zig fmt: same-line comment after field decl" {
try testCanonical(
\\pub const dirent = extern struct {
@@ -2491,6 +2659,7 @@ test "zig fmt: same-line comment after field decl" {
);
}
+
test "zig fmt: same-line comment after switch prong" {
try testCanonical(
\\test "" {
@@ -2503,6 +2672,7 @@ test "zig fmt: same-line comment after switch prong" {
);
}
+
test "zig fmt: same-line comment after non-block if expression" {
try testCanonical(
\\comptime {
@@ -2513,6 +2683,7 @@ test "zig fmt: same-line comment after non-block if expression" {
);
}
+
test "zig fmt: same-line comment on comptime expression" {
try testCanonical(
\\test "" {
@@ -2522,6 +2693,7 @@ test "zig fmt: same-line comment on comptime expression" {
);
}
+
test "zig fmt: switch with empty body" {
try testCanonical(
\\test "" {
@@ -2531,6 +2703,7 @@ test "zig fmt: switch with empty body" {
);
}
+
test "zig fmt: line comments in struct initializer" {
try testCanonical(
\\fn foo() void {
@@ -2553,6 +2726,7 @@ test "zig fmt: line comments in struct initializer" {
);
}
+
test "zig fmt: first line comment in struct initializer" {
try testCanonical(
\\pub fn acquire(self: *Self) HeldLock {
@@ -2566,6 +2740,7 @@ test "zig fmt: first line comment in struct initializer" {
);
}
+
test "zig fmt: doc comments before struct field" {
try testCanonical(
\\pub const Allocator = struct {
@@ -2577,6 +2752,7 @@ test "zig fmt: doc comments before struct field" {
);
}
+
test "zig fmt: error set declaration" {
try testCanonical(
\\const E = error{
@@ -2609,6 +2785,7 @@ test "zig fmt: error set declaration" {
);
}
+
test "zig fmt: union(enum(u32)) with assigned enum values" {
try testCanonical(
\\const MultipleChoice = union(enum(u32)) {
@@ -2621,6 +2798,7 @@ test "zig fmt: union(enum(u32)) with assigned enum values" {
);
}
+
test "zig fmt: resume from suspend block" {
try testCanonical(
\\fn foo() void {
@@ -2632,6 +2810,7 @@ test "zig fmt: resume from suspend block" {
);
}
+
test "zig fmt: comments before error set decl" {
try testCanonical(
\\const UnexpectedError = error{
@@ -2648,6 +2827,7 @@ test "zig fmt: comments before error set decl" {
);
}
+
test "zig fmt: comments before switch prong" {
try testCanonical(
\\test "" {
@@ -2665,6 +2845,7 @@ test "zig fmt: comments before switch prong" {
);
}
+
test "zig fmt: comments before var decl in struct" {
try testCanonical(
\\pub const vfs_cap_data = extern struct {
@@ -2690,6 +2871,7 @@ test "zig fmt: comments before var decl in struct" {
);
}
+
test "zig fmt: array literal with 1 item on 1 line" {
try testCanonical(
\\var s = []const u64{0} ** 25;
@@ -2697,6 +2879,7 @@ test "zig fmt: array literal with 1 item on 1 line" {
);
}
+
test "zig fmt: comments before global variables" {
try testCanonical(
\\/// Foo copies keys and values before they go into the map, and
@@ -2706,6 +2889,7 @@ test "zig fmt: comments before global variables" {
);
}
+
test "zig fmt: comments in statements" {
try testCanonical(
\\test "std" {
@@ -2721,6 +2905,7 @@ test "zig fmt: comments in statements" {
);
}
+
test "zig fmt: comments before test decl" {
try testCanonical(
\\// top level normal comment
@@ -2733,6 +2918,7 @@ test "zig fmt: comments before test decl" {
);
}
+
test "zig fmt: preserve spacing" {
try testCanonical(
\\const std = @import("std");
@@ -2748,6 +2934,7 @@ test "zig fmt: preserve spacing" {
);
}
+
test "zig fmt: return types" {
try testCanonical(
\\pub fn main() !void {}
@@ -2757,6 +2944,7 @@ test "zig fmt: return types" {
);
}
+
test "zig fmt: imports" {
try testCanonical(
\\const std = @import("std");
@@ -2765,6 +2953,7 @@ test "zig fmt: imports" {
);
}
+
test "zig fmt: global declarations" {
try testCanonical(
\\const a = b;
@@ -2787,6 +2976,7 @@ test "zig fmt: global declarations" {
);
}
+
test "zig fmt: extern declaration" {
try testCanonical(
\\extern var foo: c_int;
@@ -2794,6 +2984,7 @@ test "zig fmt: extern declaration" {
);
}
+
test "zig fmt: alignment" {
try testCanonical(
\\var foo: c_int align(1);
@@ -2801,6 +2992,7 @@ test "zig fmt: alignment" {
);
}
+
test "zig fmt: C main" {
try testCanonical(
\\fn main(argc: c_int, argv: **u8) c_int {
@@ -2810,6 +3002,7 @@ test "zig fmt: C main" {
);
}
+
test "zig fmt: return" {
try testCanonical(
\\fn foo(argc: c_int, argv: **u8) c_int {
@@ -2823,6 +3016,7 @@ test "zig fmt: return" {
);
}
+
test "zig fmt: function attributes" {
try testCanonical(
\\export fn foo() void {}
@@ -2837,6 +3031,7 @@ test "zig fmt: function attributes" {
);
}
+
test "zig fmt: nested pointers with ** tokens" {
try testCanonical(
\\const x: *u32 = undefined;
@@ -2850,6 +3045,7 @@ test "zig fmt: nested pointers with ** tokens" {
);
}
+
test "zig fmt: pointer attributes" {
try testCanonical(
\\extern fn f1(s: *align(*u8) u8) c_int;
@@ -2861,6 +3057,7 @@ test "zig fmt: pointer attributes" {
);
}
+
test "zig fmt: slice attributes" {
try testCanonical(
\\extern fn f1(s: []align(*u8) u8) c_int;
@@ -2872,6 +3069,7 @@ test "zig fmt: slice attributes" {
);
}
+
test "zig fmt: test declaration" {
try testCanonical(
\\test "test name" {
@@ -2882,6 +3080,7 @@ test "zig fmt: test declaration" {
);
}
+
test "zig fmt: destructure" {
try testCanonical(
\\comptime {
@@ -2901,6 +3100,7 @@ test "zig fmt: destructure" {
);
}
+
test "zig fmt: infix operators" {
try testCanonical(
\\test {
@@ -2933,6 +3133,7 @@ test "zig fmt: infix operators" {
);
}
+
test "zig fmt: precedence" {
try testCanonical(
\\test "precedence" {
@@ -2965,6 +3166,7 @@ test "zig fmt: precedence" {
);
}
+
test "zig fmt: prefix operators" {
try testCanonical(
\\test "prefix operators" {
@@ -2974,6 +3176,7 @@ test "zig fmt: prefix operators" {
);
}
+
test "zig fmt: call expression" {
try testCanonical(
\\test "test calls" {
@@ -2986,6 +3189,7 @@ test "zig fmt: call expression" {
);
}
+
test "zig fmt: anytype type" {
try testCanonical(
\\fn print(args: anytype) @This() {}
@@ -2993,6 +3197,7 @@ test "zig fmt: anytype type" {
);
}
+
test "zig fmt: functions" {
try testCanonical(
\\extern fn puts(s: *const u8) c_int;
@@ -3017,6 +3222,7 @@ test "zig fmt: functions" {
);
}
+
test "zig fmt: multiline string" {
try testCanonical(
\\test "" {
@@ -3035,6 +3241,7 @@ test "zig fmt: multiline string" {
);
}
+
test "zig fmt: multiline string with CRLF line endings" {
try testTransform("" ++
"const s =\r\n" ++
@@ -3051,6 +3258,7 @@ test "zig fmt: multiline string with CRLF line endings" {
);
}
+
test "zig fmt: values" {
try testCanonical(
\\test "values" {
@@ -3070,6 +3278,7 @@ test "zig fmt: values" {
);
}
+
test "zig fmt: indexing" {
try testCanonical(
\\test "test index" {
@@ -3090,6 +3299,7 @@ test "zig fmt: indexing" {
);
}
+
test "zig fmt: struct declaration" {
try testCanonical(
\\const S = struct {
@@ -3128,6 +3338,7 @@ test "zig fmt: struct declaration" {
);
}
+
test "zig fmt: enum declaration" {
try testCanonical(
\\const E = enum {
@@ -3156,6 +3367,7 @@ test "zig fmt: enum declaration" {
);
}
+
test "zig fmt: union declaration" {
try testCanonical(
\\const U = union {
@@ -3196,6 +3408,7 @@ test "zig fmt: union declaration" {
);
}
+
test "zig fmt: arrays" {
try testCanonical(
\\test "test array" {
@@ -3214,6 +3427,7 @@ test "zig fmt: arrays" {
);
}
+
test "zig fmt: container initializers" {
try testCanonical(
\\const a0 = []u8{};
@@ -3234,6 +3448,7 @@ test "zig fmt: container initializers" {
);
}
+
test "zig fmt: catch" {
try testCanonical(
\\test "catch" {
@@ -3249,6 +3464,7 @@ test "zig fmt: catch" {
);
}
+
test "zig fmt: blocks" {
try testCanonical(
\\test "blocks" {
@@ -3271,6 +3487,7 @@ test "zig fmt: blocks" {
);
}
+
test "zig fmt: switch" {
try testCanonical(
\\test "switch" {
@@ -3326,6 +3543,7 @@ test "zig fmt: switch" {
);
}
+
test "zig fmt: switch multiline string" {
try testCanonical(
\\test "switch multiline string" {
@@ -3357,6 +3575,7 @@ test "zig fmt: switch multiline string" {
);
}
+
test "zig fmt: while" {
try testCanonical(
\\test "while" {
@@ -3432,6 +3651,7 @@ test "zig fmt: while" {
);
}
+
test "zig fmt: for" {
try testCanonical(
\\test "for" {
@@ -3533,6 +3753,7 @@ test "zig fmt: for" {
);
}
+
test "zig fmt: for if" {
try testCanonical(
\\test {
@@ -3558,6 +3779,7 @@ test "zig fmt: for if" {
);
}
+
test "zig fmt: if for" {
try testCanonical(
\\test {
@@ -3583,6 +3805,7 @@ test "zig fmt: if for" {
);
}
+
test "zig fmt: while if" {
try testCanonical(
\\test {
@@ -3608,6 +3831,7 @@ test "zig fmt: while if" {
);
}
+
test "zig fmt: if while" {
try testCanonical(
\\test {
@@ -3633,6 +3857,7 @@ test "zig fmt: if while" {
);
}
+
test "zig fmt: while for" {
try testCanonical(
\\test {
@@ -3658,6 +3883,7 @@ test "zig fmt: while for" {
);
}
+
test "zig fmt: for while" {
try testCanonical(
\\test {
@@ -3683,6 +3909,7 @@ test "zig fmt: for while" {
);
}
+
test "zig fmt: if" {
try testCanonical(
\\test "if" {
@@ -3732,6 +3959,7 @@ test "zig fmt: if" {
);
}
+
test "zig fmt: fix single statement if/for/while line breaks" {
try testTransform(
\\test {
@@ -3784,6 +4012,7 @@ test "zig fmt: fix single statement if/for/while line breaks" {
);
}
+
test "zig fmt: defer" {
try testCanonical(
\\test "defer" {
@@ -3804,6 +4033,7 @@ test "zig fmt: defer" {
);
}
+
test "zig fmt: comptime" {
try testCanonical(
\\fn a() u8 {
@@ -3843,6 +4073,7 @@ test "zig fmt: comptime" {
);
}
+
test "zig fmt: fn type" {
try testCanonical(
\\fn a(i: u8) u8 {
@@ -3856,6 +4087,7 @@ test "zig fmt: fn type" {
);
}
+
test "zig fmt: inline asm" {
try testTransform(
\\pub fn syscall1(number: usize, arg1: usize) usize {
@@ -3880,6 +4112,7 @@ test "zig fmt: inline asm" {
);
}
+
test "zig fmt: nosuspend" {
try testCanonical(
\\const a = nosuspend foo();
@@ -3887,6 +4120,7 @@ test "zig fmt: nosuspend" {
);
}
+
test "zig fmt: Block after if" {
try testCanonical(
\\test {
@@ -3902,6 +4136,7 @@ test "zig fmt: Block after if" {
);
}
+
test "zig fmt: string identifier" {
try testCanonical(
\\const @"a b" = @"c d".@"e f";
@@ -3910,6 +4145,7 @@ test "zig fmt: string identifier" {
);
}
+
test "zig fmt: error return" {
try testCanonical(
\\fn err() anyerror {
@@ -3920,6 +4156,7 @@ test "zig fmt: error return" {
);
}
+
test "zig fmt: comptime block in container" {
try testCanonical(
\\pub fn container() type {
@@ -3935,6 +4172,7 @@ test "zig fmt: comptime block in container" {
);
}
+
test "zig fmt: inline asm parameter alignment" {
try testCanonical(
\\pub fn main() void {
@@ -3972,6 +4210,7 @@ test "zig fmt: inline asm parameter alignment" {
);
}
+
test "zig fmt: multiline string in array" {
try testCanonical(
\\const Foo = [][]const u8{
@@ -3997,6 +4236,7 @@ test "zig fmt: multiline string in array" {
);
}
+
test "zig fmt: file ends with struct field" {
try testCanonical(
\\a: bool
@@ -4004,6 +4244,7 @@ test "zig fmt: file ends with struct field" {
);
}
+
test "zig fmt: comment after empty comment" {
try testCanonical(
\\const x = true; //
@@ -4014,6 +4255,7 @@ test "zig fmt: comment after empty comment" {
);
}
+
test "zig fmt: line comment in array" {
try testTransform(
\\test "a" {
@@ -4046,6 +4288,7 @@ test "zig fmt: line comment in array" {
);
}
+
test "zig fmt: comment after params" {
try testTransform(
\\fn a(
@@ -4072,6 +4315,7 @@ test "zig fmt: comment after params" {
);
}
+
test "zig fmt: comment in array initializer/access" {
try testCanonical(
\\test "a" {
@@ -4108,6 +4352,7 @@ test "zig fmt: comment in array initializer/access" {
);
}
+
test "zig fmt: comments at several places in struct init" {
try testTransform(
\\var bar = Bar{
@@ -4135,6 +4380,7 @@ test "zig fmt: comments at several places in struct init" {
);
}
+
test "zig fmt: container doc comments" {
try testCanonical(
\\//! tld 1
@@ -4191,6 +4437,7 @@ test "zig fmt: container doc comments" {
);
}
+
test "zig fmt: remove newlines surrounding doc comment" {
try testTransform(
\\
@@ -4207,6 +4454,7 @@ test "zig fmt: remove newlines surrounding doc comment" {
);
}
+
test "zig fmt: remove newlines surrounding doc comment between members" {
try testTransform(
\\f1: i32,
@@ -4225,6 +4473,7 @@ test "zig fmt: remove newlines surrounding doc comment between members" {
);
}
+
test "zig fmt: remove newlines surrounding doc comment between members within container decl (1)" {
try testTransform(
\\const Foo = struct {
@@ -4248,6 +4497,7 @@ test "zig fmt: remove newlines surrounding doc comment between members within co
);
}
+
test "zig fmt: remove newlines surrounding doc comment between members within container decl (2)" {
try testTransform(
\\const Foo = struct {
@@ -4270,6 +4520,7 @@ test "zig fmt: remove newlines surrounding doc comment between members within co
);
}
+
test "zig fmt: remove newlines surrounding doc comment within container decl" {
try testTransform(
\\const Foo = struct {
@@ -4289,6 +4540,7 @@ test "zig fmt: remove newlines surrounding doc comment within container decl" {
);
}
+
test "zig fmt: comments with CRLF line endings" {
try testTransform("" ++
"//! Top-level doc comment\r\n" ++
@@ -4311,6 +4563,7 @@ test "zig fmt: comments with CRLF line endings" {
);
}
+
test "zig fmt: else comptime expr" {
try testCanonical(
\\comptime {
@@ -4326,6 +4579,7 @@ test "zig fmt: else comptime expr" {
);
}
+
test "zig fmt: integer literals with underscore separators" {
try testTransform(
\\const
@@ -4339,6 +4593,7 @@ test "zig fmt: integer literals with underscore separators" {
);
}
+
test "zig fmt: hex literals with underscore separators" {
try testTransform(
\\pub fn orMask(a: [ 1_000 ]u64, b: [ 1_000] u64) [1_000]u64 {
@@ -4362,6 +4617,7 @@ test "zig fmt: hex literals with underscore separators" {
);
}
+
test "zig fmt: decimal float literals with underscore separators" {
try testTransform(
\\pub fn main() void {
@@ -4379,6 +4635,7 @@ test "zig fmt: decimal float literals with underscore separators" {
);
}
+
test "zig fmt: hexadecimal float literals with underscore separators" {
try testTransform(
\\pub fn main() void {
@@ -4396,6 +4653,7 @@ test "zig fmt: hexadecimal float literals with underscore separators" {
);
}
+
test "zig fmt: C var args" {
try testCanonical(
\\pub extern "c" fn printf(format: [*:0]const u8, ...) c_int;
@@ -4403,6 +4661,7 @@ test "zig fmt: C var args" {
);
}
+
test "zig fmt: Only indent multiline string literals in function calls" {
try testCanonical(
\\test "zig fmt:" {
@@ -4420,6 +4679,7 @@ test "zig fmt: Only indent multiline string literals in function calls" {
);
}
+
test "zig fmt: Don't add extra newline after if" {
try testCanonical(
\\pub fn atomicSymLink(allocator: Allocator, existing_path: []const u8, new_path: []const u8) !void {
@@ -4431,6 +4691,7 @@ test "zig fmt: Don't add extra newline after if" {
);
}
+
test "zig fmt: comments in ternary ifs" {
try testCanonical(
\\const x = if (true) {
@@ -4450,6 +4711,7 @@ test "zig fmt: comments in ternary ifs" {
);
}
+
test "zig fmt: while statement in blockless if" {
try testCanonical(
\\pub fn main() void {
@@ -4464,6 +4726,7 @@ test "zig fmt: while statement in blockless if" {
);
}
+
test "zig fmt: test comments in field access chain" {
try testCanonical(
\\pub const str = struct {
@@ -4499,6 +4762,7 @@ test "zig fmt: test comments in field access chain" {
);
}
+
test "zig fmt: allow line break before field access" {
try testCanonical(
\\test {
@@ -4547,6 +4811,7 @@ test "zig fmt: allow line break before field access" {
);
}
+
test "zig fmt: Indent comma correctly after multiline string literals in arg list (trailing comma)" {
try testCanonical(
\\fn foo() void {
@@ -4572,6 +4837,7 @@ test "zig fmt: Indent comma correctly after multiline string literals in arg lis
);
}
+
test "zig fmt: regression test for #5722" {
try testCanonical(
\\pub fn sendViewTags(self: Self) void {
@@ -4587,6 +4853,7 @@ test "zig fmt: regression test for #5722" {
);
}
+
test "zig fmt: regression test for #8974" {
try testCanonical(
\\pub const VARIABLE;
@@ -4594,6 +4861,7 @@ test "zig fmt: regression test for #8974" {
);
}
+
test "zig fmt: allow trailing line comments to do manual array formatting" {
try testCanonical(
\\fn foo() void {
@@ -4632,6 +4900,7 @@ 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 {
@@ -4698,6 +4967,7 @@ test "zig fmt: multiline string literals should play nice with array initializer
);
}
+
test "zig fmt: use of comments and multiline string literals may force the parameters over multiple lines" {
try testCanonical(
\\pub fn makeMemUndefined(qzz: []u8) i1 {
@@ -4738,6 +5008,7 @@ test "zig fmt: use of comments and multiline string literals may force the param
);
}
+
test "zig fmt: single argument trailing commas in @builtins()" {
try testCanonical(
\\pub fn foo(qzz: []u8) i1 {
@@ -4756,6 +5027,7 @@ test "zig fmt: single argument trailing commas in @builtins()" {
);
}
+
test "zig fmt: trailing comma should force multiline 1 column" {
try testTransform(
\\pub const UUID_NULL: uuid_t = [16]u8{0,0,0,0,};
@@ -4771,6 +5043,7 @@ test "zig fmt: trailing comma should force multiline 1 column" {
);
}
+
test "zig fmt: function params should align nicely" {
try testCanonical(
\\pub fn foo() void {
@@ -4787,6 +5060,7 @@ test "zig fmt: function params should align nicely" {
);
}
+
test "zig fmt: fn proto end with anytype and comma" {
try testCanonical(
\\pub fn format(
@@ -4796,6 +5070,7 @@ test "zig fmt: fn proto end with anytype and comma" {
);
}
+
test "zig fmt: space after top level doc comment" {
try testCanonical(
\\//! top level doc comment
@@ -4805,6 +5080,7 @@ test "zig fmt: space after top level doc comment" {
);
}
+
test "zig fmt: remove trailing whitespace after container doc comment" {
try testTransform(
\\//! top level doc comment
@@ -4815,6 +5091,7 @@ test "zig fmt: remove trailing whitespace after container doc comment" {
);
}
+
test "zig fmt: remove trailing whitespace after doc comment" {
try testTransform(
\\/// doc comment
@@ -4827,6 +5104,7 @@ test "zig fmt: remove trailing whitespace after doc comment" {
);
}
+
test "zig fmt: for loop with ptr payload and index" {
try testCanonical(
\\test {
@@ -4839,6 +5117,7 @@ test "zig fmt: for loop with ptr payload and index" {
);
}
+
test "zig fmt: proper indent line comment after multi-line single expr while loop" {
try testCanonical(
\\test {
@@ -4852,6 +5131,7 @@ test "zig fmt: proper indent line comment after multi-line single expr while loo
);
}
+
test "zig fmt: extern function with missing param name" {
try testCanonical(
\\extern fn a(
@@ -4863,6 +5143,7 @@ test "zig fmt: extern function with missing param name" {
);
}
+
test "zig fmt: respect extra newline between switch items" {
try testCanonical(
\\const a = switch (b) {
@@ -4876,6 +5157,7 @@ test "zig fmt: respect extra newline between switch items" {
);
}
+
test "zig fmt: assignment with inline for and inline while" {
try testCanonical(
\\const tmp = inline for (items) |item| {};
@@ -4888,6 +5170,7 @@ test "zig fmt: assignment with inline for and inline while" {
);
}
+
test "zig fmt: saturating arithmetic" {
try testCanonical(
\\test {
@@ -4908,6 +5191,7 @@ test "zig fmt: saturating arithmetic" {
);
}
+
test "zig fmt: insert trailing comma if there are comments between switch values" {
try testTransform(
\\const a = switch (b) {
@@ -4939,6 +5223,7 @@ test "zig fmt: insert trailing comma if there are comments between switch values
);
}
+
test "zig fmt: insert trailing comma if comments in array init" {
try testTransform(
\\var a = .{
@@ -4976,6 +5261,7 @@ test "zig fmt: insert trailing comma if comments in array init" {
);
}
+
test "zig fmt: make single-line if no trailing comma" {
try testTransform(
\\test "function call no trailing comma" {
@@ -5023,6 +5309,7 @@ test "zig fmt: make single-line if no trailing comma" {
);
}
+
test "zig fmt: preserve container doc comment in container without trailing comma" {
try testTransform(
\\const A = enum(u32) {
@@ -5038,151 +5325,6 @@ test "zig fmt: preserve container doc comment in container without trailing comm
);
}
-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;
- \\}
- \\
- );
-}
-
-test "zig fmt: don't canonicalize _ in enums" {
- try testTransform(
- \\const A = enum {
- \\ first,
- \\ second,
- \\ third,
- \\ _,
- \\};
- \\const B = enum {
- \\ @"_",
- \\ @"__",
- \\ @"___",
- \\ @"____",
- \\};
- \\const C = struct {
- \\ @"_": u8,
- \\ @"__": u8,
- \\ @"___": u8,
- \\ @"____": u8,
- \\};
- \\const D = union {
- \\ @"_": u8,
- \\ @"__": u8,
- \\ @"___": u8,
- \\ @"____": u8,
- \\};
- \\
- ,
- \\const A = enum {
- \\ first,
- \\ second,
- \\ third,
- \\ _,
- \\};
- \\const B = enum {
- \\ @"_",
- \\ __,
- \\ ___,
- \\ ____,
- \\};
- \\const C = struct {
- \\ _: u8,
- \\ __: u8,
- \\ ___: u8,
- \\ ____: u8,
- \\};
- \\const D = union {
- \\ _: u8,
- \\ __: u8,
- \\ ___: u8,
- \\ ____: u8,
- \\};
- \\
- );
-}
-
-test "zig fmt: pointer type syntax to index" {
- try testCanonical(
- \\test {
- \\ _ = .{}[*0];
- \\}
- \\
- );
-}
-
-test "zig fmt: binop indentation in if statement" {
- try testCanonical(
- \\test {
- \\ if (first_param_type.isGenericPoison() or
- \\ (first_param_type.zigTypeTag(zcu) == .pointer and
- \\ (first_param_type.ptrSize(zcu) == .One or
- \\ first_param_type.ptrSize(zcu) == .C) and
- \\ first_param_type.childType(zcu).eql(concrete_ty, zcu)))
- \\ {
- \\ f(x);
- \\ }
- \\}
- \\
- );
-}
-
-test "zig fmt: test indentation of if expressions" {
- try testCanonical(
- \\test {
- \\ const foo = 1 +
- \\ if (1 == 2)
- \\ 2
- \\ else
- \\ 0;
- \\
- \\ const foo = 1 + if (1 == 2)
- \\ 2
- \\ else
- \\ 0;
- \\
- \\ errval catch |e|
- \\ if (e == error.Meow)
- \\ return 0x1F408
- \\ else
- \\ unreachable;
- \\
- \\ errval catch |e| if (e == error.Meow)
- \\ return 0x1F408
- \\ else
- \\ unreachable;
- \\
- \\ return if (1 == 2)
- \\ 1
- \\ else if (3 > 4)
- \\ 2
- \\ else
- \\ 0;
- \\}
- \\
- );
-}
test "zig fmt: canonicalize symbols (simple)" {
try testTransform(
@@ -5334,6 +5476,37 @@ test "zig fmt: canonicalize symbols (simple)" {
+
+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;
+ \\}
+ \\
+ );
+}
+
+
test "zig fmt: canonicalize symbols (character escapes)" {
try testTransform(
\\const @"\x46\x6f\x6f\x64" = struct {
@@ -5377,6 +5550,7 @@ test "zig fmt: canonicalize symbols (character escapes)" {
}
+
test "zig fmt: canonicalize symbols (asm)" {
try testTransform(
\\test "asm" {
@@ -5426,6 +5600,128 @@ test "zig fmt: canonicalize symbols (asm)" {
}
+
+test "zig fmt: don't canonicalize _ in enums" {
+ try testTransform(
+ \\const A = enum {
+ \\ first,
+ \\ second,
+ \\ third,
+ \\ _,
+ \\};
+ \\const B = enum {
+ \\ @"_",
+ \\ @"__",
+ \\ @"___",
+ \\ @"____",
+ \\};
+ \\const C = struct {
+ \\ @"_": u8,
+ \\ @"__": u8,
+ \\ @"___": u8,
+ \\ @"____": u8,
+ \\};
+ \\const D = union {
+ \\ @"_": u8,
+ \\ @"__": u8,
+ \\ @"___": u8,
+ \\ @"____": u8,
+ \\};
+ \\
+ ,
+ \\const A = enum {
+ \\ first,
+ \\ second,
+ \\ third,
+ \\ _,
+ \\};
+ \\const B = enum {
+ \\ @"_",
+ \\ __,
+ \\ ___,
+ \\ ____,
+ \\};
+ \\const C = struct {
+ \\ _: u8,
+ \\ __: u8,
+ \\ ___: u8,
+ \\ ____: u8,
+ \\};
+ \\const D = union {
+ \\ _: u8,
+ \\ __: u8,
+ \\ ___: u8,
+ \\ ____: u8,
+ \\};
+ \\
+ );
+}
+
+
+test "zig fmt: pointer type syntax to index" {
+ try testCanonical(
+ \\test {
+ \\ _ = .{}[*0];
+ \\}
+ \\
+ );
+}
+
+
+test "zig fmt: binop indentation in if statement" {
+ try testCanonical(
+ \\test {
+ \\ if (first_param_type.isGenericPoison() or
+ \\ (first_param_type.zigTypeTag(zcu) == .pointer and
+ \\ (first_param_type.ptrSize(zcu) == .One or
+ \\ first_param_type.ptrSize(zcu) == .C) and
+ \\ first_param_type.childType(zcu).eql(concrete_ty, zcu)))
+ \\ {
+ \\ f(x);
+ \\ }
+ \\}
+ \\
+ );
+}
+
+
+test "zig fmt: test indentation of if expressions" {
+ try testCanonical(
+ \\test {
+ \\ const foo = 1 +
+ \\ if (1 == 2)
+ \\ 2
+ \\ else
+ \\ 0;
+ \\
+ \\ const foo = 1 + if (1 == 2)
+ \\ 2
+ \\ else
+ \\ 0;
+ \\
+ \\ errval catch |e|
+ \\ if (e == error.Meow)
+ \\ return 0x1F408
+ \\ else
+ \\ unreachable;
+ \\
+ \\ errval catch |e| if (e == error.Meow)
+ \\ return 0x1F408
+ \\ else
+ \\ unreachable;
+ \\
+ \\ return if (1 == 2)
+ \\ 1
+ \\ else if (3 > 4)
+ \\ 2
+ \\ else
+ \\ 0;
+ \\}
+ \\
+ );
+}
+
+
test "zig fmt: canonicalize cast builtins" {
try testTransform(
\\const foo = @alignCast(@ptrCast(bar));
@@ -5439,6 +5735,7 @@ test "zig fmt: canonicalize cast builtins" {
}
+
test "zig fmt: do not canonicalize invalid cast builtins" {
try testCanonical(
\\const foo = @alignCast(@volatileCast(@ptrCast(@alignCast(bar))));
@@ -5446,6 +5743,7 @@ test "zig fmt: do not canonicalize invalid cast builtins" {
);
}
+
test "Ast header smoke test" {
try std.testing.expectEqual(zigNode(c.AST_NODE_IF), Ast.Node.Tag.@"if");
}
@@ -6000,3 +6298,4 @@ fn zigAst(gpa: Allocator, c_ast: c.Ast) !Ast {
.errors = errors,
};
}
+