mod support;
use accent_proust::parse::{ParseOptions, PulldownTokenizer, parse, parse_with};
use support::{dedent, outline};
fn parse_comments(source: &str) -> accent_proust::ast::Node<'_> {
parse_with(
source,
&PulldownTokenizer::new(),
&ParseOptions::new().allow_comments(true),
)
}
const INLINE: &str = "\
document
paragraph
inline
text content=\"this is a test \"
comment content=\"example comment\"
text content=\" foo\"
";
#[test]
fn simple_inline_comment() {
let source = dedent("\nthis is a test <!-- example comment --> foo\n");
assert_eq!(outline(&parse_comments(&source)), INLINE);
}
#[test]
fn inline_comment_with_a_newline() {
let source = dedent("\nthis is a test <!-- \nexample comment\n--> foo\n");
assert_eq!(outline(&parse_comments(&source)), INLINE);
}
const BLOCK: &str = "\
document
paragraph
inline
text content=\"this is a test\"
comment content=\"example comment\"
paragraph
inline
text content=\"foo\"
";
#[test]
fn simple_block_comment_after_a_paragraph() {
let source = dedent("\nthis is a test\n\n<!--\nexample comment\n-->\n\nfoo\n");
assert_eq!(outline(&parse_comments(&source)), BLOCK);
}
#[test]
fn block_comment_ending_on_the_same_line_as_content() {
let source = dedent("\nthis is a test\n\n<!--\nexample comment -->\n\nfoo\n");
assert_eq!(outline(&parse_comments(&source)), BLOCK);
}
#[test]
fn block_comment_on_one_line() {
let source = dedent("\nthis is a test\n\n<!-- example comment -->\n\nfoo\n");
assert_eq!(outline(&parse_comments(&source)), BLOCK);
}
#[test]
fn block_comment_across_multiple_lines_with_blank_lines() {
let source = "foo <!-- example\n\ncomment --> bar\n";
assert_eq!(
outline(&parse_comments(source)),
"\
document
paragraph
inline
text content=\"foo <!-- example\"
paragraph
inline
text content=\"comment --> bar\"
"
);
}
#[test]
fn comments_are_text_when_the_option_is_off() {
let source = dedent("\nthis is a test <!-- example comment --> foo\n");
assert_eq!(
outline(&parse(&source)),
"\
document
paragraph
inline
text content=\"this is a test <!-- example comment --> foo\"
"
);
}