summary refs log tree commit diff
diff options
context:
space:
mode:
authorBaitinq <manuelpalenzuelamerino@gmail.com>2025-01-12 00:21:06 +0100
committerBaitinq <manuelpalenzuelamerino@gmail.com>2025-01-12 00:21:06 +0100
commita8ba80f7f710b7af22433764737c1c6bcb35ec61 (patch)
tree76379776aa937bc16298eee6a7aa5d8cef1c3ac2
parentMisc: Improve lsp errors (diff)
downloadinterpreter-a8ba80f7f710b7af22433764737c1c6bcb35ec61.tar.gz
interpreter-a8ba80f7f710b7af22433764737c1c6bcb35ec61.tar.bz2
interpreter-a8ba80f7f710b7af22433764737c1c6bcb35ec61.zip
Evaluator: Add simple test
-rw-r--r--src/evaluator.zig25
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);
+}