Tweak code generating code to produce rustmft compliant code when possible

pull/1/head
Marcus Klaas de Vries 5 years ago
parent 6de7a39d37
commit a622625624

@ -69,20 +69,22 @@ fn generate_tests_from_spec() {
spec_rs
.write(b"// Please, do not modify it manually\n")
.unwrap();
spec_rs.write(b"\nuse super::test_markdown_html;").unwrap();
spec_rs
.write(b"\nuse super::test_markdown_html;\n")
.unwrap();
for (i, testcase) in spec.enumerate() {
spec_rs
.write_fmt(format_args!(
r###"
#[test]
fn {}_test_{i}() {{
let original = r##"{original}"##;
let expected = r##"{expected}"##;
test_markdown_html(original, expected);
}}"###,
}}
"###,
spec_name,
i = i + 1,
original = testcase.original,

@ -3,10 +3,10 @@
pub use super::test_markdown_html;
mod regression;
mod footnotes;
mod gfm_strikethrough;
mod table;
mod spec;
mod gfm_table;
mod gfm_strikethrough;
mod gfm_tasklist;
mod regression;
mod spec;
mod table;

@ -405,8 +405,7 @@ fn regression_test_30() {
some text
"##;
let expected =
r##"<table><thead><tr><th>Markdown </th><th> Less </th><th> Pretty</th></tr></thead><tbody>
let expected = r##"<table><thead><tr><th>Markdown </th><th> Less </th><th> Pretty</th></tr></thead><tbody>
</tbody></table>
<p>some text</p>
"##;

@ -6889,8 +6889,7 @@ fn spec_test_511() {
fn spec_test_512() {
let original = r##"[link *foo **bar** `#`*](/uri)
"##;
let expected =
r##"<p><a href="/uri">link <em>foo <strong>bar</strong> <code>#</code></em></a></p>
let expected = r##"<p><a href="/uri">link <em>foo <strong>bar</strong> <code>#</code></em></a></p>
"##;
test_markdown_html(original, expected);
@ -7038,8 +7037,7 @@ fn spec_test_526() {
[ref]: /uri
"##;
let expected =
r##"<p><a href="/uri">link <em>foo <strong>bar</strong> <code>#</code></em></a></p>
let expected = r##"<p><a href="/uri">link <em>foo <strong>bar</strong> <code>#</code></em></a></p>
"##;
test_markdown_html(original, expected);
@ -7923,8 +7921,7 @@ fn spec_test_600() {
fn spec_test_601() {
let original = r##"<foo+special@Bar.baz-bar0.com>
"##;
let expected =
r##"<p><a href="mailto:foo+special@Bar.baz-bar0.com">foo+special@Bar.baz-bar0.com</a></p>
let expected = r##"<p><a href="mailto:foo+special@Bar.baz-bar0.com">foo+special@Bar.baz-bar0.com</a></p>
"##;
test_markdown_html(original, expected);

@ -140,8 +140,7 @@ fn table_test_8() {
#[test]
fn table_test_9() {
let original =
r##"| Target | std |rustc|cargo| notes |
let original = r##"| Target | std |rustc|cargo| notes |
|-------------------------------|-----|-----|-----|----------------------------|
| `x86_64-unknown-linux-musl` | | | | 64-bit Linux with MUSL |
| `arm-linux-androideabi` | | | | ARM Android |

@ -60,11 +60,14 @@ const ENTITIES: [(&[u8], &str); {len(entities)}] = [""")
for e in entities:
codepoints = jsondata['&' + e + ';']["codepoints"];
s = ''.join([r'\u{%04X}' % cp for cp in codepoints])
print(f" (b\"{e}\", \"{s}\"),")
print(""" ];
print(f" (b\"{e}\", \"{s}\"),")
print("""];
pub(crate) fn get_entity(bytes: &[u8]) -> Option<&'static str> {
ENTITIES.binary_search_by_key(&bytes, |&(key, _value)| key).ok().map(|i| ENTITIES[i].1)
ENTITIES
.binary_search_by_key(&bytes, |&(key, _value)| key)
.ok()
.map(|i| ENTITIES[i].1)
}
""")

@ -69,19 +69,19 @@ def main(args):
const PUNCT_MASKS_ASCII: [u16; 8] = ["""
for x in range(8):
y = get_bits(x, ascii_set)
print ' 0x%04x, // U+%04X...U+%04X' % (y, x * 16, x * 16 + 15)
print """ ];
print ' 0x%04x, // U+%04X...U+%04X' % (y, x * 16, x * 16 + 15)
print """];
const PUNCT_TAB: [u16; %i] = [""" % len(pshift)
for x in pshift:
print ' %d, // U+%04X...U+%04X' % (x, x * 16, x * 16 + 15)
print """ ];
print ' %d, // U+%04X...U+%04X' % (x, x * 16, x * 16 + 15)
print """];
const PUNCT_MASKS: [u16; %i] = [""" % len(pshift)
for i, y in enumerate(bits):
x = pshift[i]
print ' 0x%04x, // U+%04X...U+%04X' % (y, x * 16, x * 16 + 15)
print """ ];
print ' 0x%04x, // U+%04X...U+%04X' % (y, x * 16, x * 16 + 15)
print """];
pub fn is_ascii_punctuation(c: u8) -> bool {
c < 128 && (PUNCT_MASKS_ASCII[(c / 16) as usize] & (1 << (c & 15))) != 0

Loading…
Cancel
Save