wip
This commit is contained in:
@@ -30,7 +30,10 @@ with open("tests/test.json", "r") as txt:
|
||||
const Document = @import("attempt_2.zig").Document;
|
||||
const std = @import("std");
|
||||
const Token = @import("Token.zig");
|
||||
const expect = std.testing.expect;
|
||||
const expect = std.testing.expect;
|
||||
|
||||
const print_output: bool = true;
|
||||
|
||||
""")
|
||||
tests : dict = json.loads(txt.read())
|
||||
for test_name, test_value in tests["basic_unit_tests"].items():
|
||||
@@ -41,33 +44,37 @@ const expect = std.testing.expect;
|
||||
token_type = list(token.keys())[0]
|
||||
|
||||
tokens += f"""
|
||||
Token{{
|
||||
.type = .{token_type},
|
||||
.data = "{token[token_type].encode("unicode_escape").decode("utf-8")}",
|
||||
}},"""
|
||||
// Token{{
|
||||
// .type = .{token_type},
|
||||
// .data = "{token[token_type].encode("unicode_escape").decode("utf-8")}",
|
||||
// }},"""
|
||||
|
||||
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}
|
||||
}};
|
||||
|
||||
|
||||
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));
|
||||
}}
|
||||
|
||||
doc.deinit(std.testing.allocator);
|
||||
}}
|
||||
// test "{test_name}" {{
|
||||
// std.testing.refAllDecls(@This());
|
||||
//
|
||||
// var doc = try Document.initDefault(std.testing.allocator);
|
||||
//
|
||||
// const input = "{test_value["input"].encode("unicode_escape").decode("utf-8")}";
|
||||
// const parsed = [_]Token{{{tokens}
|
||||
// }};
|
||||
//
|
||||
//
|
||||
// try doc.parse(std.testing.allocator, input);
|
||||
//
|
||||
// if (!print_output) try expect(doc.tokens.items.len >= parsed.len);
|
||||
//
|
||||
// for (parsed, doc.tokens.items[0..parsed.len]) |expected_token, actual_token| {{
|
||||
// if (print_output) {{
|
||||
// std.debug.print("expected_token : {{f}} | actual_token : {{f}}\\n", .{{ expected_token, actual_token }});
|
||||
// }} else {{
|
||||
// try expect(expected_token.type == actual_token.type);
|
||||
// try expect(std.mem.eql(u8, expected_token.data, actual_token.data));
|
||||
// }}
|
||||
// }}
|
||||
//
|
||||
// doc.deinit(std.testing.allocator);
|
||||
// }}
|
||||
""")
|
||||
# pprint(test_value["parsed"])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user