init
This commit is contained in:
69
create_tests.py
Normal file
69
create_tests.py
Normal 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"])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user