Normalized tests
This commit is contained in:
parent
c4fd99fa45
commit
26bd6fe4b2
|
@ -1207,90 +1207,91 @@ mod test {
|
|||
#[test]
|
||||
fn parse_formatting() {
|
||||
assert_eq!(
|
||||
parse_full(r#"~~stikethrough~~"#),
|
||||
Token::Strikethrough(Box::new(Token::PlainText("stikethrough".into()))),
|
||||
parse_full(r#"~~stikethrough~~"#)
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
parse_full(r#"**bold**"#),
|
||||
Token::Bold(Box::new(Token::PlainText("bold".into()))),
|
||||
parse_full(r#"**bold**"#)
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
parse_full(r#"*italic*"#),
|
||||
Token::Italic(Box::new(Token::PlainText("italic".into()))),
|
||||
parse_full(r#"*italic*"#)
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
parse_full(r#"not code `code` also not code"#),
|
||||
Token::Sequence(vec![
|
||||
Token::PlainText("not code ".into()),
|
||||
Token::InlineCode("code".into()),
|
||||
Token::PlainText(" also not code".into())
|
||||
]),
|
||||
parse_full(r#"not code `code` also not code"#)
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
parse_full(r#"not code `code` also `not code"#),
|
||||
Token::Sequence(vec![
|
||||
Token::PlainText("not code ".into()),
|
||||
Token::InlineCode("code".into()),
|
||||
Token::PlainText(" also `not code".into())
|
||||
]),
|
||||
parse_full(r#"not code `code` also `not code"#)
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
parse_full(r#"not code `*not bold*` also not code"#),
|
||||
Token::Sequence(vec![
|
||||
Token::PlainText("not code ".into()),
|
||||
Token::InlineCode("*not bold*".into()),
|
||||
Token::PlainText(" also not code".into())
|
||||
]),
|
||||
parse_full(r#"not code `*not bold*` also not code"#)
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
Token::BoldItalic(Box::new(Token::PlainText("bold italic".into()))),
|
||||
parse_full(r#"***bold italic***"#)
|
||||
parse_full(r#"***bold italic***"#),
|
||||
Token::BoldItalic(Box::new(Token::PlainText("bold italic".into())))
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
parse_full(r#"<b><i>bold italic</i></b>"#),
|
||||
Token::Bold(Box::new(Token::Italic(Box::new(Token::PlainText(
|
||||
"bold italic".into()
|
||||
))))),
|
||||
parse_full(r#"<b><i>bold italic</i></b>"#)
|
||||
)))))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_complex() {
|
||||
assert_eq!(
|
||||
parse_full(
|
||||
r#"<center>centered
|
||||
🦋🏳️⚧️
|
||||
text</center>"#
|
||||
),
|
||||
Token::Center(Box::new(Token::Sequence(vec![
|
||||
Token::PlainText("centered\n".into()),
|
||||
Token::UnicodeEmoji("🦋".into()),
|
||||
Token::UnicodeEmoji("🏳️⚧️".into()),
|
||||
Token::PlainText("\ntext".into())
|
||||
]))),
|
||||
parse_full(
|
||||
r#"<center>centered
|
||||
🦋🏳️⚧️
|
||||
text</center>"#
|
||||
)
|
||||
])))
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
parse_full(
|
||||
r#"> <center>centered
|
||||
> 👩🏽🤝👩🏼
|
||||
> text</center>"#
|
||||
),
|
||||
Token::Quote(Box::new(Token::Center(Box::new(Token::Sequence(vec![
|
||||
Token::PlainText("centered\n".into()),
|
||||
Token::UnicodeEmoji("👩🏽🤝👩🏼".into()),
|
||||
Token::PlainText("\ntext".into())
|
||||
]))))),
|
||||
parse_full(
|
||||
r#"> <center>centered
|
||||
> 👩🏽🤝👩🏼
|
||||
> text</center>"#
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
parse_full(r#"$[x2 $[sparkle 🥺]💜$[spin.y,speed=5s ❤️]🦊]"#),
|
||||
Token::Function {
|
||||
name: "x2".into(),
|
||||
params: HashMap::new(),
|
||||
|
@ -1314,10 +1315,10 @@ text</center>"#
|
|||
Token::UnicodeEmoji("🦊".into()),
|
||||
]))
|
||||
},
|
||||
parse_full(r#"$[x2 $[sparkle 🥺]💜$[spin.y,speed=5s ❤️]🦊]"#)
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
parse_full(r#"<b>bold @tag1 <i> @tag2 </b>italic</i>"#),
|
||||
Token::Sequence(vec![
|
||||
Token::PlainText("<b>bold ".into()),
|
||||
Token::Mention {
|
||||
|
@ -1333,19 +1334,9 @@ text</center>"#
|
|||
},
|
||||
Token::PlainText(" </b>italic</i>".into())
|
||||
]),
|
||||
Context
|
||||
.full(Span::new(r#"<b>bold @tag1 <i> @tag2 </b>italic</i>"#))
|
||||
.unwrap()
|
||||
.1
|
||||
.merged()
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
Token::Quote(Box::new(Token::Sequence(vec![
|
||||
Token::PlainText("test\n".into()),
|
||||
Token::Italic(Box::new(Token::PlainText("\nitalic\n".into()))),
|
||||
Token::Quote(Box::new(Token::PlainText("Nested quote".into())))
|
||||
]))),
|
||||
parse_full(
|
||||
r#"
|
||||
> test
|
||||
|
@ -1354,7 +1345,12 @@ text</center>"#
|
|||
> </i>
|
||||
>> Nested quote
|
||||
"#
|
||||
)
|
||||
),
|
||||
Token::Quote(Box::new(Token::Sequence(vec![
|
||||
Token::PlainText("test\n".into()),
|
||||
Token::Italic(Box::new(Token::PlainText("\nitalic\n".into()))),
|
||||
Token::Quote(Box::new(Token::PlainText("Nested quote".into())))
|
||||
]))),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1539,46 +1535,46 @@ text</center>"#
|
|||
#[test]
|
||||
fn parse_emoji() {
|
||||
assert_eq!(
|
||||
parse_full("🥺💜❤️🦊"),
|
||||
Token::Sequence(
|
||||
vec!["🥺", "💜", "❤️", "🦊"]
|
||||
.into_iter()
|
||||
.map(<&str as Into<Cow<_>>>::into)
|
||||
.map(Token::UnicodeEmoji)
|
||||
.collect::<Vec<_>>()
|
||||
),
|
||||
parse_full("🥺💜❤️🦊")
|
||||
)
|
||||
);
|
||||
|
||||
// Trans flag, ZWJ
|
||||
assert_eq!(
|
||||
Token::UnicodeEmoji("\u{1f3f3}\u{0fe0f}\u{0200d}\u{026a7}\u{0fe0f}".into()),
|
||||
parse_full("\u{1f3f3}\u{0fe0f}\u{0200d}\u{026a7}\u{0fe0f}")
|
||||
parse_full("\u{1f3f3}\u{0fe0f}\u{0200d}\u{026a7}\u{0fe0f}"),
|
||||
Token::UnicodeEmoji("\u{1f3f3}\u{0fe0f}\u{0200d}\u{026a7}\u{0fe0f}".into())
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
parse_full("\u{0200d}\u{1f3f3}\u{0fe0f}"),
|
||||
Token::Sequence(vec![
|
||||
Token::PlainText("\u{0200d}".into()), // ZWJ
|
||||
Token::UnicodeEmoji("\u{1f3f3}\u{0fe0f}".into()), // White flag
|
||||
]),
|
||||
parse_full("\u{0200d}\u{1f3f3}\u{0fe0f}")
|
||||
])
|
||||
);
|
||||
|
||||
// Trans flag, ZWNJ
|
||||
assert_eq!(
|
||||
parse_full("\u{1f3f3}\u{0fe0f}\u{0200c}\u{026a7}\u{0fe0f}"),
|
||||
Token::Sequence(vec![
|
||||
Token::UnicodeEmoji("\u{1f3f3}\u{0fe0f}".into()), // White flag
|
||||
Token::PlainText("\u{0200c}".into()), // ZWNJ
|
||||
Token::UnicodeEmoji("\u{026a7}\u{0fe0f}".into()) // Trans symbol
|
||||
]),
|
||||
parse_full("\u{1f3f3}\u{0fe0f}\u{0200c}\u{026a7}\u{0fe0f}")
|
||||
])
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
parse_full("\u{1f3f3}\u{0fe0f}\u{0200d}\u{0200d}\u{0200d}"),
|
||||
Token::Sequence(vec![
|
||||
Token::UnicodeEmoji("\u{1f3f3}\u{0fe0f}".into()), // White flag
|
||||
Token::PlainText("\u{0200d}\u{0200d}\u{0200d}".into()), // ZWJ
|
||||
]),
|
||||
parse_full("\u{1f3f3}\u{0fe0f}\u{0200d}\u{0200d}\u{0200d}")
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue