From a8ba80f7f710b7af22433764737c1c6bcb35ec61 Mon Sep 17 00:00:00 2001 From: Baitinq Date: Sun, 12 Jan 2025 00:21:06 +0100 Subject: Evaluator: Add simple test --- src/evaluator.zig | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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); +} -- cgit 1.4.1