use std::collections::HashMap;
mod emoticons;
mod gemoji;
mod bn_emojis;
mod emoji;
#[cfg(feature = "internal")]
pub mod internal {
pub use crate::gemoji::gemojis;
pub use crate::emoticons::emoticons;
#[cfg(feature = "custom")]
pub use crate::emoji::emojis;
pub use crate::bn_emojis::emojis as bn_emojis;
}
pub struct Emojicon {
emoticons: HashMap<&'static str, &'static str>,
emojis: HashMap<&'static str, &'static [&'static str]>,
}
impl Emojicon {
pub fn new() -> Self {
let emojis = if cfg!(feature = "custom") {
emoji::emojis()
} else {
gemoji::gemojis()
};
Self {
emoticons: emoticons::emoticons(),
emojis
}
}
pub fn get_by_emoticon(&self, emoticon: &str) -> Option<&str> {
self.emoticons.get(emoticon).map(|i| *i)
}
pub fn get_by_name(&self, name: &str) -> Option<impl Iterator<Item = &str>> {
self.emojis.get(name).map(|v| v.iter().map(|s| *s))
}
}
pub struct BengaliEmoji {
emojis: HashMap<&'static str, &'static [&'static str]>,
}
impl BengaliEmoji {
pub fn new() -> Self {
Self { emojis: bn_emojis::emojis() }
}
pub fn get(&self, name: &str) -> Option<impl Iterator<Item = &str>> {
self.emojis.get(name).map(|v| v.iter().map(|s| *s))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_by_emoticon() {
let emoji = Emojicon::new();
assert_eq!(emoji.get_by_emoticon(":)").unwrap(), "๐");
assert_eq!(emoji.get_by_emoticon(":Z").unwrap(), "๐");
assert_eq!(emoji.get_by_emoticon(",:-[").unwrap(), "๐");
assert_eq!(emoji.get_by_emoticon("smile"), None);
}
#[test]
fn test_by_name() {
let emoji = Emojicon::new();
assert_eq!(emoji.get_by_name("happy").unwrap().collect::<Vec<_>>(), ["๐", "๐", "๐", "๐"]);
assert!(!emoji.get_by_name("none").is_some());
}
#[test]
#[cfg(feature = "custom")]
fn test_by_name_custom() {
let emoji = Emojicon::new();
assert_eq!(emoji.get_by_name("chup").unwrap().collect::<Vec<_>>(), ["๐ซข"]);
}
#[test]
fn test_bengali_emoji() {
let emojis = BengaliEmoji::new();
assert_eq!(emojis.get("เฆเฆทเงเฆ").unwrap().collect::<Vec<_>>(), ["๐ฃ"]);
assert_eq!(emojis.get("เฆจเฆฟเฆฐเฆพเฆถ").unwrap().collect::<Vec<_>>(), ["๐", "๐", "๐ฆ", "๐"]);
}
}