27 lines
796 B
Zig
27 lines
796 B
Zig
const std = @import("std");
|
|
const zls = @import("zls");
|
|
|
|
const Ast = std.zig.Ast;
|
|
|
|
const ComptimeInterpreter = zls.ComptimeInterpreter;
|
|
|
|
const allocator: std.mem.Allocator = std.testing.allocator;
|
|
|
|
test "ComptimeInterpreter - basic test" {
|
|
var tree = try std.zig.parse(allocator,
|
|
\\pub fn ReturnMyType() type {
|
|
\\ if (1 == 1) return u69;
|
|
\\ return u8;
|
|
\\}
|
|
);
|
|
defer tree.deinit(allocator);
|
|
|
|
var interpreter = ComptimeInterpreter{ .tree = tree, .allocator = allocator };
|
|
defer interpreter.deinit();
|
|
|
|
const z = try interpreter.call(tree.rootDecls()[0], &.{}, .{});
|
|
defer z.scope.deinit();
|
|
|
|
try std.testing.expectFmt("u69", "{any}", .{interpreter.formatTypeInfo(interpreter.typeToTypeInfo(z.result.value.value_data.@"type"))});
|
|
}
|