simplify example cases
This commit is contained in:
56
examples.py
56
examples.py
@@ -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");
|
||||
const convert = @import("main.zig").convert;
|
||||
'''
|
||||
)
|
||||
|
||||
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'''
|
||||
test "{name}" {{
|
||||
const alloc = std.testing.allocator;
|
||||
write(f'''
|
||||
test "{name}" {{
|
||||
const output = try convert(std.testing.allocator,
|
||||
{indent(md, r'\\', lambda _: True) if md else '""'}
|
||||
);
|
||||
defer std.testing.allocator.free(output);
|
||||
|
||||
const md = (
|
||||
{indent(md, r' \\', lambda _: True) if md else '""'}
|
||||
);
|
||||
const html = (
|
||||
{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", '\\')
|
||||
try std.testing.expectEqualStrings(
|
||||
{indent(html, r'\\', lambda _: True) if html else '""'}
|
||||
,
|
||||
output
|
||||
);
|
||||
}}
|
||||
''')
|
||||
|
||||
formatter.stdin.close()
|
||||
|
13605
src/examples.zig
13605
src/examples.zig
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user