Closed
Description
As a consequence of issue #169, I just wanted to suggest a technique of testing parsers and printers. Parsing and printing (serializers and deserializers) are mutually inverse functions: the result of print(parse(some_text))
should be some_text
itself – in case if some_text
is well-formatted. Thus, it is really easy to write parser+printer tests literally in declarative style:
let cases = [
("**some bold text**", "should support bold text"),
"plain text\n\nwith newlines", "should support text with newlines"),
...
...
];
#[test]
fn roundtrip() {
for (orig_md_text, error_message) in cases {
let ast = markdown::to_mdast(&orig_md_text, &markdown::ParseOptions::default()).unwrap();
let formatted_md_text = to(&ast).unwrap();
assert_eq!(formatted_md_text, orig_md_text, error_message)
}
}
Metadata
Metadata
Assignees
Labels
No labels