wip
This commit is contained in:
@@ -26,6 +26,12 @@ import json
|
||||
from pprint import pprint
|
||||
|
||||
with open("tests/test.json", "r") as txt:
|
||||
print(f"""
|
||||
const Document = @import("attempt_2.zig").Document;
|
||||
const std = @import("std");
|
||||
const Token = @import("Token.zig");
|
||||
const expect = std.testing.expect;
|
||||
""")
|
||||
tests : dict = json.loads(txt.read())
|
||||
for test_name, test_value in tests["basic_unit_tests"].items():
|
||||
|
||||
@@ -42,19 +48,25 @@ with open("tests/test.json", "r") as txt:
|
||||
|
||||
print(f"""
|
||||
test "{test_name}" {{
|
||||
std.testing.refAllDecls(@This());
|
||||
|
||||
const doc = Document.initDefault(std.testing.allocator);
|
||||
|
||||
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 doc.parse(input, std.testing.allocator);
|
||||
|
||||
try expect(doc.tokens.items.len >= parsed.len);
|
||||
|
||||
for (parsed, doc.tokens.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);
|
||||
doc.deinit(std.testing.allocator);
|
||||
}}
|
||||
""")
|
||||
# pprint(test_value["parsed"])
|
||||
|
||||
Reference in New Issue
Block a user