simplify example cases
This commit is contained in:
56
examples.py
56
examples.py
@@ -2,6 +2,7 @@ import parsel
|
|||||||
import httpx
|
import httpx
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from textwrap import indent
|
from textwrap import indent
|
||||||
|
from subprocess import Popen, PIPE
|
||||||
|
|
||||||
VERSION = '0.31.2'
|
VERSION = '0.31.2'
|
||||||
|
|
||||||
@@ -17,36 +18,41 @@ else:
|
|||||||
CACHE.write_text(response.text)
|
CACHE.write_text(response.text)
|
||||||
sel = parsel.Selector(response.text)
|
sel = parsel.Selector(response.text)
|
||||||
|
|
||||||
print(
|
|
||||||
'''const std = @import("std");
|
formatter = Popen(['zig', 'fmt', '--stdin'], stdin=PIPE, encoding='utf-8')
|
||||||
const convert = @import("main.zig").convert;
|
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'):
|
for example in sel.css('.example'):
|
||||||
name = example.css('.examplenum > a::text').get()
|
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
|
assert name is not None
|
||||||
|
|
||||||
print(f'''
|
write(f'''
|
||||||
test "{name}" {{
|
test "{name}" {{
|
||||||
const alloc = std.testing.allocator;
|
const output = try convert(std.testing.allocator,
|
||||||
|
{indent(md, r'\\', lambda _: True) if md else '""'}
|
||||||
|
);
|
||||||
|
defer std.testing.allocator.free(output);
|
||||||
|
|
||||||
const md = (
|
try std.testing.expectEqualStrings(
|
||||||
{indent(md, r' \\', lambda _: True) if md else '""'}
|
{indent(html, r'\\', lambda _: True) if html else '""'}
|
||||||
);
|
,
|
||||||
const html = (
|
output
|
||||||
{indent(html, r' \\', lambda _: True) if html else '""'}
|
);
|
||||||
);
|
}}
|
||||||
|
''')
|
||||||
const output = try convert(alloc, md);
|
|
||||||
defer alloc.free(output);
|
|
||||||
|
|
||||||
try std.testing.expectEqualStrings(html, output);
|
|
||||||
}}
|
|
||||||
''')
|
|
||||||
|
|
||||||
# mdtext = textwrap.indent("md", '\\')
|
|
||||||
|
|
||||||
|
formatter.stdin.close()
|
||||||
|
13713
src/examples.zig
13713
src/examples.zig
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user