authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-05-12 21:44:08+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-05-12 21:44:08+03:00
logfa57463bb9c09ee1e50012d7e50d120e1599fb81
tree1d168132cc0f647e3479045f849072f777aef148
parent80d0c2f166311c82ddb48c093df508c063973d02
signaturelock-open Commit is signed but in an unrecognized format.

make parser testError take a list of expected errors


1 files changed, 16 insertions(+), 4 deletions(-)

lib/std/zig/parser_test.zig+16-4
...@@ -19,7 +19,9 @@ test "zig fmt: decl between fields" {...@@ -19,7 +19,9 @@ test "zig fmt: decl between fields" {
19 \\ const baz1 = 2;19 \\ const baz1 = 2;
20 \\ b: usize,20 \\ b: usize,
21 \\};21 \\};
22 );22 , &[_]Error{
23 .DeclBetweenFields,
24 });
23}25}
2426
25test "zig fmt: errdefer with payload" {27test "zig fmt: errdefer with payload" {
...@@ -2828,7 +2830,9 @@ test "zig fmt: extern without container keyword returns error" {...@@ -2828,7 +2830,9 @@ test "zig fmt: extern without container keyword returns error" {
2828 try testError(2830 try testError(
2829 \\const container = extern {};2831 \\const container = extern {};
2830 \\2832 \\
2831 );2833 , &[_]Error{
2834 .ExpectedExpr,
2835 });
2832}2836}
28332837
2834test "zig fmt: integer literals with underscore separators" {2838test "zig fmt: integer literals with underscore separators" {
...@@ -3030,9 +3034,17 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {...@@ -3030,9 +3034,17 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
3030fn testCanonical(source: []const u8) !void {3034fn testCanonical(source: []const u8) !void {
3031 return testTransform(source, source);3035 return testTransform(source, source);
3032}3036}
3033fn testError(source: []const u8) !void {3037
3038const Error = @TagType(std.zig.ast.Error);
3039
3040fn testError(source: []const u8, expected_errors: []const Error) !void {
3034 const tree = try std.zig.parse(std.testing.allocator, source);3041 const tree = try std.zig.parse(std.testing.allocator, source);
3035 defer tree.deinit();3042 defer tree.deinit();
30363043
3037 std.testing.expect(tree.errors.len != 0);3044 std.testing.expect(tree.errors.len == expected_errors.len);
3045 for (expected_errors) |expected, i| {
3046 const err = tree.errors.at(i);
3047
3048 std.testing.expect(expected == err.*);
3049 }
3038}3050}