diff options
| author | Baitinq <[email protected]> | 2025-01-12 00:21:06 +0100 |
|---|---|---|
| committer | Baitinq <[email protected]> | 2025-01-12 00:21:06 +0100 |
| commit | 0c201652320a7999f21ad942e31e5255d33484bc (patch) | |
| tree | 76379776aa937bc16298eee6a7aa5d8cef1c3ac2 /src/evaluator.zig | |
| parent | Misc: Improve lsp errors (diff) | |
| download | interpreter-0c201652320a7999f21ad942e31e5255d33484bc.tar.gz interpreter-0c201652320a7999f21ad942e31e5255d33484bc.tar.bz2 interpreter-0c201652320a7999f21ad942e31e5255d33484bc.zip | |
Evaluator: Add simple test
Diffstat (limited to 'src/evaluator.zig')
| -rw-r--r-- | src/evaluator.zig | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/evaluator.zig b/src/evaluator.zig index ed31edd..fb129b5 100644 --- a/src/evaluator.zig +++ b/src/evaluator.zig @@ -80,3 +80,28 @@ pub const Evaluator = struct { }; } }; + +test "simple" { + const ast = &parser.Node{ .PROGRAM = .{ .statements = @constCast(&[_]*parser.Node{ @constCast(&parser.Node{ .STATEMENT = .{ .statement = @constCast(&parser.Node{ .VARIABLE_STATEMENT = .{ + .is_declaration = true, + .name = @constCast("i"), + .expression = @constCast(&parser.Node{ .EXPRESSION = .{ + .NUMBER = .{ .value = 2 }, + } }), + } }) } }), @constCast(&parser.Node{ .STATEMENT = .{ .statement = @constCast(&parser.Node{ + .VARIABLE_STATEMENT = .{ + .is_declaration = false, + .name = @constCast("i"), + .expression = @constCast(&parser.Node{ .EXPRESSION = .{ + .NUMBER = .{ .value = 2 }, + } }), + }, + }) } }) }) } }; + + var evaluator = try Evaluator.init(std.testing.allocator); + defer evaluator.deinit(); + + const evaluation_result = try evaluator.evaluate_ast(@constCast(ast)); + + try std.testing.expectEqual(0, evaluation_result); +} |