From 9a31d1aca3709bbd2c687b7dee4733decb16dfeb Mon Sep 17 00:00:00 2001 From: Fernando Araoz Date: Sat, 14 Dec 2024 06:31:23 -0500 Subject: [PATCH] test: add tests for statement parsing --- src/02_syntax/statement.zig | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/02_syntax/statement.zig b/src/02_syntax/statement.zig index ecb5a3a..a2cea08 100644 --- a/src/02_syntax/statement.zig +++ b/src/02_syntax/statement.zig @@ -52,5 +52,28 @@ test "should parse a variable declaration statement" { try statement.init(&tokens, 0, std.testing.allocator); defer statement.deinit(); - // try std.testing.expectEqual(true, statement.is_mutable); + switch (statement) { + .VariableBinding => |v| { + try std.testing.expectEqual(true, v.is_mutable); + }, + } +} + +test "should fail on other constructs" { + const input = "a_function_call(322)"; + const tokens = try lexic.tokenize(input, std.testing.allocator); + defer tokens.deinit(); + + var statement: Statement = undefined; + statement.init(&tokens, 0, std.testing.allocator) catch |e| switch (e) { + error.Unmatched => { + return; + }, + else => { + try std.testing.expect(false); + return; + }, + }; + + try std.testing.expect(false); }