This commit is contained in:
2026-04-14 21:31:44 +12:00
commit 8be321dee1
16 changed files with 7065 additions and 0 deletions

69
create_tests.py Normal file
View File

@@ -0,0 +1,69 @@
# test "parses-comment" {
# const input = "// this is a comment\n";
# const parsed = [_]Token{
# Token{
# .type = .comment,
# .data = comment_id,
# },
# Token{
# .type = .raw_text,
# .data = "this is a comment",
# },
# Token{ .type = .newline, .data = "\n" },
# };
# var parsing = try tokenize(input, std.testing.allocator);
# for (parsed, parsing.items[0..parsed.len]) |expected_token, actual_token| {
# try expect(expected_token.type == actual_token.type);
# try expect(std.mem.eql(u8, expected_token.data, actual_token.data));
# }
# parsing.deinit(std.testing.allocator);
# }
import json
from pprint import pprint
with open("tests/test.json", "r") as txt:
tests : dict = json.loads(txt.read())
for test_name, test_value in tests["basic_unit_tests"].items():
tokens = ""
for token in test_value["parsed"]:
token_type = list(token.keys())[0]
tokens += f"""
Token{{
.type = .{token_type},
.data = "{token[token_type].encode("unicode_escape").decode("utf-8")}",
}},"""
print(f"""
test "{test_name}" {{
const input = "{test_value["input"].encode("unicode_escape").decode("utf-8")}";
const parsed = [_]Token{{{tokens}
}};
var parsing = try tokenize(input, std.testing.allocator);
try expect(parsing.items.len >= parsed.len);
for (parsed, parsing.items[0..parsed.len]) |expected_token, actual_token| {{
try expect(expected_token.type == actual_token.type);
try expect(std.mem.eql(u8, expected_token.data, actual_token.data));
}}
parsing.deinit(std.testing.allocator);
}}
""")
# pprint(test_value["parsed"])