add test for emoji validator
This commit is contained in:
parent
37bbfffe26
commit
d2f8bc44ff
1 changed files with 32 additions and 1 deletions
|
@ -172,7 +172,10 @@ fn validate_emoji(value: &str) -> Result<(), ValidationError> {
|
|||
// check if `value` is a custom emoji
|
||||
// "+", "-", "_" are allowed in emoji shortcodes in Misskey variants
|
||||
// ref: <https://github.com/misskey-dev/mfm.js/blob/6aaf68089023c6adebe44123eebbc4dcd75955e0/docs/syntax.md?plain=1#L583>
|
||||
if value.len() > 2 {
|
||||
if value.is_ascii() && value.len() > 2 {
|
||||
if value.chars().nth(0).unwrap() != ':' || value.chars().last().unwrap() != ':' {
|
||||
return error;
|
||||
}
|
||||
if value[1..value.len() - 1]
|
||||
.chars()
|
||||
.all(|c| c.is_ascii_alphanumeric() || c == '+' || c == '-' || c == '_')
|
||||
|
@ -183,3 +186,31 @@ fn validate_emoji(value: &str) -> Result<(), ValidationError> {
|
|||
|
||||
error
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
#[test]
|
||||
fn validate_emoji() {
|
||||
super::validate_emoji("⭐").unwrap();
|
||||
super::validate_emoji("👍").unwrap();
|
||||
super::validate_emoji("❤️").unwrap();
|
||||
super::validate_emoji("💜").unwrap();
|
||||
super::validate_emoji("🧛🏽").unwrap();
|
||||
super::validate_emoji("🧑🤝🧑").unwrap();
|
||||
super::validate_emoji(":ameow_attention:").unwrap();
|
||||
super::validate_emoji(":meow_peek:").unwrap();
|
||||
super::validate_emoji(":ABlobcatLonglong:").unwrap();
|
||||
super::validate_emoji(":ABlobcat++Longlong:").unwrap();
|
||||
super::validate_emoji(":ABlobcat-Longlong:").unwrap();
|
||||
|
||||
super::validate_emoji("⭐⭐").unwrap_err();
|
||||
super::validate_emoji("::").unwrap_err();
|
||||
super::validate_emoji("?").unwrap_err();
|
||||
super::validate_emoji(":?:").unwrap_err();
|
||||
super::validate_emoji(":ameow_attention:").unwrap_err();
|
||||
super::validate_emoji("").unwrap_err();
|
||||
super::validate_emoji("ABlobcat-Longlong:").unwrap_err();
|
||||
super::validate_emoji("ABlobcat-Longlong").unwrap_err();
|
||||
super::validate_emoji(":雨:").unwrap_err();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue