From ea7fc74483730f33588aad60aa570f5cab7eea17 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Fri, 20 Jan 2023 19:29:03 +0100 Subject: [PATCH] add more comptime interpreter tests --- .../comptime_interpreter.zig | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/language_features/comptime_interpreter.zig b/tests/language_features/comptime_interpreter.zig index da17b57..8f9c252 100644 --- a/tests/language_features/comptime_interpreter.zig +++ b/tests/language_features/comptime_interpreter.zig @@ -44,6 +44,43 @@ test "ComptimeInterpreter - builtins" { } }, .{ .int_u64_value = 3 }); } +test "ComptimeInterpreter - string literal" { + if (true) return error.SkipZigTest; // TODO + const source = + \\const foobarbaz = "hello world!"; + \\ + ; + + var result = try testInterpret(source, 1); + defer result.deinit(); + + try std.testing.expect(result.ty == .pointer_type); + try std.testing.expect(result.val == .bytes); + + try std.testing.expectEqualStrings("hello world!", result.val.bytes); +} + +test "ComptimeInterpreter - labeled block" { + try testExprCheck( + \\blk: { + \\ break :blk true; + \\} + , .{ .simple = .bool }, .{ .simple = .bool_true }); +} + +test "ComptimeInterpreter - if" { + try testExprCheck( + \\blk: { + \\ break :blk if (true) true else false; + \\} + , .{ .simple = .bool }, .{ .simple = .bool_true }); + try testExprCheck( + \\blk: { + \\ break :blk if (false) true else false; + \\} + , .{ .simple = .bool }, .{ .simple = .bool_false }); +} + test "ComptimeInterpreter - call return primitive type" { try testCallCheck( \\pub fn Foo() type { @@ -232,6 +269,9 @@ fn testInterpret(source: []const u8, node_idx: Ast.Node.Index) !Result { const result = try interpreter.interpret(node_idx, .none, .{}); + try std.testing.expect(result.value.ty != .none); + try std.testing.expect(result.value.val != .none); + return Result{ .interpreter = interpreter, .ty = interpreter.ip.indexToKey(result.value.ty),