//! Tests for turning one paragraph's inline events into styled text.
use super::*;
/// Parses `markdown` as a single paragraph and renders its inline
/// content, the way `block.rs` does for a `Paragraph` block.
fn inline_text(markdown: &str) -> Text<'static> {
let mut events = Events::new(markdown);
assert_eq!(events.next(), Some(Event::Start(Tag::Paragraph)));
text(&mut events, TagEnd::Paragraph, Style::default())
}
#[test]
fn strong_text_is_bold() {
assert_eq!(
inline_text("**bold**"),
Text::from(Line::from(vec![Span::styled("bold", style::strong())]))
);
}
#[test]
fn emphasis_text_is_italic() {
assert_eq!(
inline_text("*em*"),
Text::from(Line::from(vec![Span::styled("em", style::emphasis())]))
);
}
#[test]
fn nested_strong_and_emphasis_combine() {
let both = style::strong().patch(style::emphasis());
assert_eq!(
inline_text("**_both_**"),
Text::from(Line::from(vec![Span::styled("both", both)]))
);
}
#[test]
fn strikethrough_text_is_crossed_out() {
assert_eq!(
inline_text("~~gone~~"),
Text::from(Line::from(vec![Span::styled(
"gone",
style::strikethrough()
)]))
);
}
#[test]
fn inline_code_keeps_its_literal_text() {
assert_eq!(
inline_text("`code`"),
Text::from(Line::from(vec![Span::styled("code", style::code())]))
);
}
#[test]
fn a_link_keeps_only_its_text() {
assert_eq!(
inline_text("[label](http://example.com)"),
Text::from(Line::from(vec![Span::styled("label", style::link())]))
);
}
#[test]
fn an_image_renders_as_its_plain_alt_text() {
assert_eq!(
inline_text(""),
Text::from(Line::from(vec![Span::raw("a map of Duskmere")]))
);
}
#[test]
fn a_wikilink_reduces_to_its_last_segment() {
assert_eq!(
inline_text("[[rules/spells/fireball]]"),
Text::from(Line::from(vec![Span::styled("fireball", style::wiki())]))
);
}
#[test]
fn a_piped_wikilink_shows_its_display_text() {
assert_eq!(
inline_text("[[a/b|shown]]"),
Text::from(Line::from(vec![Span::styled("shown", style::wiki())]))
);
}
#[test]
fn a_soft_break_becomes_a_space() {
assert_eq!(
inline_text("line one\nline two"),
Text::from(Line::from(vec![
Span::raw("line one"),
Span::raw(" "),
Span::raw("line two"),
]))
);
}
#[test]
fn a_hard_break_forces_a_new_row() {
assert_eq!(
inline_text("line one \nline two"),
Text::from(vec![
Line::from(vec![Span::raw("line one")]),
Line::from(vec![Span::raw("line two")]),
])
);
}
#[test]
fn inline_html_passes_through_verbatim() {
assert_eq!(
inline_text("some
text"),
Text::from(Line::from(vec![
Span::raw("some "),
Span::raw("
"),
Span::raw(" text"),
]))
);
}