89 lines
2.4 KiB
Python
89 lines
2.4 KiB
Python
# 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:
|
|
print(f"""
|
|
const Document = @import("attempt_2.zig").Document;
|
|
const std = @import("std");
|
|
const Token = @import("Token.zig");
|
|
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():
|
|
|
|
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}" {{
|
|
// 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"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|