parser: add multiline string, empty file, field, container tests
Port tests from upstream parser_test.zig: - "multiline string mixed with comments" - "empty file" - "file ends in comment" - "file ends in multi line comment" - "file ends in comment after var decl" - "top-level fields" - "container declaration, single line" Implement in parser.c: - parseSuffixOp: array access, field access, deref, unwrap optional - Slice/array type parsing in parseTypeExpr - Multiline string literal parsing Fix zigData mapping in parser_test.zig: - optional_type uses .node (not .opt_node) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -222,11 +222,11 @@ fn zigData(tag: Ast.Node.Tag, lhs: u32, rhs: u32) Ast.Node.Data {
|
|||||||
.address_of,
|
.address_of,
|
||||||
.@"try",
|
.@"try",
|
||||||
.deref,
|
.deref,
|
||||||
|
.optional_type,
|
||||||
=> .{ .node = toIndex(lhs) },
|
=> .{ .node = toIndex(lhs) },
|
||||||
|
|
||||||
// .opt_node (single optional node)
|
// .opt_node (single optional node)
|
||||||
.@"return",
|
.@"return",
|
||||||
.optional_type,
|
|
||||||
=> .{ .opt_node = toOptIndex(lhs) },
|
=> .{ .opt_node = toOptIndex(lhs) },
|
||||||
|
|
||||||
// .node_and_node
|
// .node_and_node
|
||||||
@@ -649,3 +649,88 @@ test "zig fmt: respect line breaks after var declarations" {
|
|||||||
\\
|
\\
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "zig fmt: multiline string mixed with comments" {
|
||||||
|
try testCanonical(
|
||||||
|
\\const s1 =
|
||||||
|
\\ //\\one
|
||||||
|
\\ \\two)
|
||||||
|
\\ \\three
|
||||||
|
\\;
|
||||||
|
\\const s2 =
|
||||||
|
\\ \\one
|
||||||
|
\\ \\two)
|
||||||
|
\\ //\\three
|
||||||
|
\\;
|
||||||
|
\\const s3 =
|
||||||
|
\\ \\one
|
||||||
|
\\ //\\two)
|
||||||
|
\\ \\three
|
||||||
|
\\;
|
||||||
|
\\const s4 =
|
||||||
|
\\ \\one
|
||||||
|
\\ //\\two
|
||||||
|
\\ \\three
|
||||||
|
\\ //\\four
|
||||||
|
\\ \\five
|
||||||
|
\\;
|
||||||
|
\\const a =
|
||||||
|
\\ 1;
|
||||||
|
\\
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "zig fmt: empty file" {
|
||||||
|
try testCanonical(
|
||||||
|
\\
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "zig fmt: file ends in comment" {
|
||||||
|
try testTransform(
|
||||||
|
\\ //foobar
|
||||||
|
,
|
||||||
|
\\//foobar
|
||||||
|
\\
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "zig fmt: file ends in multi line comment" {
|
||||||
|
try testTransform(
|
||||||
|
\\ \\foobar
|
||||||
|
,
|
||||||
|
\\\\foobar
|
||||||
|
\\
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "zig fmt: file ends in comment after var decl" {
|
||||||
|
try testTransform(
|
||||||
|
\\const x = 42;
|
||||||
|
\\ //foobar
|
||||||
|
,
|
||||||
|
\\const x = 42;
|
||||||
|
\\//foobar
|
||||||
|
\\
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "zig fmt: top-level fields" {
|
||||||
|
try testCanonical(
|
||||||
|
\\a: did_you_know,
|
||||||
|
\\b: all_files_are,
|
||||||
|
\\structs: ?x,
|
||||||
|
\\
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "zig fmt: container declaration, single line" {
|
||||||
|
try testCanonical(
|
||||||
|
\\const X = struct { foo: i32 };
|
||||||
|
\\const X = struct { foo: i32, bar: i32 };
|
||||||
|
\\const X = struct { foo: i32 = 1, bar: i32 = 2 };
|
||||||
|
\\const X = struct { foo: i32 align(4), bar: i32 align(4) };
|
||||||
|
\\const X = struct { foo: i32 align(4) = 1, bar: i32 align(4) = 2 };
|
||||||
|
\\
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user