simplify example cases

This commit is contained in:
2024-11-11 16:17:23 -05:00
parent 5ac1a9b7b9
commit 7b568063ea
2 changed files with 5107 additions and 8554 deletions

View File

@@ -2,6 +2,7 @@ import parsel
import httpx
from pathlib import Path
from textwrap import indent
from subprocess import Popen, PIPE
VERSION = '0.31.2'
@@ -17,36 +18,41 @@ else:
CACHE.write_text(response.text)
sel = parsel.Selector(response.text)
print(
'''const std = @import("std");
formatter = Popen(['zig', 'fmt', '--stdin'], stdin=PIPE, encoding='utf-8')
assert formatter.stdin
write = formatter.stdin.write
write(f'''
//! Example cases from Commonmark spec {VERSION}
//! {URL}
const std = @import("std");
const convert = @import("main.zig").convert;
'''
)
''')
for example in sel.css('.example'):
name = example.css('.examplenum > a::text').get()
md = example.css('.language-markdown::text').get()
html = example.css('.language-html::text').get()
md = ''.join(example.css('.language-markdown *::text').getall())
html = ''.join(example.css('.language-html *::text').getall())
assert name is not None
print(f'''
write(f'''
test "{name}" {{
const alloc = std.testing.allocator;
const md = (
const output = try convert(std.testing.allocator,
{indent(md, r'\\', lambda _: True) if md else '""'}
);
const html = (
defer std.testing.allocator.free(output);
try std.testing.expectEqualStrings(
{indent(html, r'\\', lambda _: True) if html else '""'}
,
output
);
const output = try convert(alloc, md);
defer alloc.free(output);
try std.testing.expectEqualStrings(html, output);
}}
''')
# mdtext = textwrap.indent("md", '\\')
formatter.stdin.close()

File diff suppressed because it is too large Load Diff