add more comptime interpreter tests

This commit is contained in:
Techatrix 2023-01-20 19:29:03 +01:00
parent 1e73ac91e5
commit ea7fc74483

View File

@ -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),