Normalized tests

This commit is contained in:
Natty 2023-10-07 21:26:25 +02:00
parent c4fd99fa45
commit 26bd6fe4b2
Signed by: natty
GPG Key ID: BF6CB659ADEE60EC
1 changed files with 39 additions and 43 deletions

View File

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