139 lines
6.0 KiB
C++
139 lines
6.0 KiB
C++
//
|
||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
||
//
|
||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||
//
|
||
#include "td/utils/emoji.h"
|
||
#include "td/utils/tests.h"
|
||
|
||
TEST(Emoji, is_emoji) {
|
||
ASSERT_TRUE(!td::is_emoji(""));
|
||
ASSERT_TRUE(td::is_emoji("đŠđŧââ¤âđâđŠđģ"));
|
||
ASSERT_TRUE(!td::is_emoji("đŠđŧââ¤âđâđŠđģī¸"));
|
||
ASSERT_TRUE(td::is_emoji("đŠđŧââ¤ī¸âđâđŠđģ"));
|
||
ASSERT_TRUE(td::is_emoji("đŠđŧââ¤ī¸âđâđŠđģī¸"));
|
||
ASSERT_TRUE(!td::is_emoji("đŠđŧââ¤ī¸ī¸âđâđŠđģ"));
|
||
ASSERT_TRUE(td::is_emoji("â"));
|
||
ASSERT_TRUE(td::is_emoji("âī¸"));
|
||
ASSERT_TRUE(td::is_emoji("â"));
|
||
ASSERT_TRUE(td::is_emoji("đĒ"));
|
||
ASSERT_TRUE(td::is_emoji("2ī¸âŖ"));
|
||
ASSERT_TRUE(td::is_emoji("2âŖ"));
|
||
ASSERT_TRUE(!td::is_emoji(" 2âŖ"));
|
||
ASSERT_TRUE(!td::is_emoji("2âŖ "));
|
||
ASSERT_TRUE(!td::is_emoji(" "));
|
||
ASSERT_TRUE(!td::is_emoji(""));
|
||
ASSERT_TRUE(!td::is_emoji("1234567890123456789012345678901234567890123456789012345678901234567890"));
|
||
ASSERT_TRUE(td::is_emoji("â¤ī¸"));
|
||
ASSERT_TRUE(td::is_emoji("â¤"));
|
||
ASSERT_TRUE(td::is_emoji("â"));
|
||
ASSERT_TRUE(td::is_emoji("đ"));
|
||
ASSERT_TRUE(td::is_emoji("đ§âđ"));
|
||
ASSERT_TRUE(td::is_emoji("Šī¸"));
|
||
ASSERT_TRUE(td::is_emoji("Š"));
|
||
ASSERT_TRUE(!td::is_emoji("Šī¸ī¸"));
|
||
ASSERT_TRUE(td::is_emoji("đĩī¸ââī¸"));
|
||
ASSERT_TRUE(!td::is_emoji("đĩââī¸"));
|
||
ASSERT_TRUE(!td::is_emoji("đĩī¸ââ"));
|
||
ASSERT_TRUE(td::is_emoji("đĩââ"));
|
||
}
|
||
|
||
static void test_get_fitzpatrick_modifier(td::string emoji, int result) {
|
||
ASSERT_EQ(result, td::get_fitzpatrick_modifier(emoji));
|
||
}
|
||
|
||
TEST(Emoji, get_fitzpatrick_modifier) {
|
||
test_get_fitzpatrick_modifier("", 0);
|
||
test_get_fitzpatrick_modifier("đŠđŧââ¤âđâđŠđģ", 2);
|
||
test_get_fitzpatrick_modifier("đŠđŧââ¤ī¸âđâđŠđģ", 2);
|
||
test_get_fitzpatrick_modifier("đ", 0);
|
||
test_get_fitzpatrick_modifier("đđģ", 2);
|
||
test_get_fitzpatrick_modifier("đđŧ", 3);
|
||
test_get_fitzpatrick_modifier("đđŊ", 4);
|
||
test_get_fitzpatrick_modifier("đđž", 5);
|
||
test_get_fitzpatrick_modifier("đđŋ", 6);
|
||
test_get_fitzpatrick_modifier("đģ", 2);
|
||
test_get_fitzpatrick_modifier("đŧ", 3);
|
||
test_get_fitzpatrick_modifier("đŊ", 4);
|
||
test_get_fitzpatrick_modifier("đž", 5);
|
||
test_get_fitzpatrick_modifier("đŋ", 6);
|
||
test_get_fitzpatrick_modifier("â", 0);
|
||
test_get_fitzpatrick_modifier("â", 0);
|
||
test_get_fitzpatrick_modifier("đĒ", 0);
|
||
test_get_fitzpatrick_modifier("2ī¸âŖ", 0);
|
||
test_get_fitzpatrick_modifier("2âŖ", 0);
|
||
test_get_fitzpatrick_modifier("â¤ī¸", 0);
|
||
test_get_fitzpatrick_modifier("â¤", 0);
|
||
test_get_fitzpatrick_modifier("â", 0);
|
||
test_get_fitzpatrick_modifier("đ", 0);
|
||
test_get_fitzpatrick_modifier("đ§âđ", 0);
|
||
}
|
||
|
||
static void test_remove_emoji_modifiers(td::string emoji, const td::string &result) {
|
||
ASSERT_STREQ(result, td::remove_emoji_modifiers(emoji));
|
||
td::remove_emoji_modifiers_in_place(emoji);
|
||
ASSERT_STREQ(result, emoji);
|
||
ASSERT_STREQ(emoji, td::remove_emoji_modifiers(emoji));
|
||
}
|
||
|
||
TEST(Emoji, remove_emoji_modifiers) {
|
||
test_remove_emoji_modifiers("", "");
|
||
test_remove_emoji_modifiers("đŠđŧââ¤âđâđŠđģ", "đŠââ¤âđâđŠ");
|
||
test_remove_emoji_modifiers("đŠđŧââ¤ī¸âđâđŠđģ", "đŠââ¤âđâđŠ");
|
||
test_remove_emoji_modifiers("đđģ", "đ");
|
||
test_remove_emoji_modifiers("đđŧ", "đ");
|
||
test_remove_emoji_modifiers("đđŊ", "đ");
|
||
test_remove_emoji_modifiers("đđž", "đ");
|
||
test_remove_emoji_modifiers("đđŋ", "đ");
|
||
test_remove_emoji_modifiers("đģ", "đģ");
|
||
test_remove_emoji_modifiers("đŧ", "đŧ");
|
||
test_remove_emoji_modifiers("đŊ", "đŊ");
|
||
test_remove_emoji_modifiers("đž", "đž");
|
||
test_remove_emoji_modifiers("đŋ", "đŋ");
|
||
test_remove_emoji_modifiers("â", "â");
|
||
test_remove_emoji_modifiers("â", "â");
|
||
test_remove_emoji_modifiers("đĒ", "đĒ");
|
||
test_remove_emoji_modifiers("2ī¸âŖ", "2âŖ");
|
||
test_remove_emoji_modifiers("2âŖ", "2âŖ");
|
||
test_remove_emoji_modifiers("â¤ī¸", "â¤");
|
||
test_remove_emoji_modifiers("â¤", "â¤");
|
||
test_remove_emoji_modifiers("â", "â");
|
||
test_remove_emoji_modifiers("ī¸", "ī¸");
|
||
test_remove_emoji_modifiers("ī¸ī¸ī¸đģ", "ī¸ī¸ī¸đģ");
|
||
test_remove_emoji_modifiers("ī¸ī¸ī¸đģa", "a");
|
||
test_remove_emoji_modifiers("đ", "đ");
|
||
test_remove_emoji_modifiers("đ§âđ", "đ§âđ");
|
||
}
|
||
|
||
static void test_remove_emoji_selectors(td::string emoji, const td::string &result) {
|
||
ASSERT_STREQ(result, td::remove_emoji_selectors(result));
|
||
ASSERT_STREQ(result, td::remove_emoji_selectors(emoji));
|
||
}
|
||
|
||
TEST(Emoji, remove_emoji_selectors) {
|
||
test_remove_emoji_selectors("", "");
|
||
test_remove_emoji_selectors("đŠđŧââ¤âđâđŠđģ", "đŠđŧââ¤âđâđŠđģ");
|
||
test_remove_emoji_selectors("đŠđŧââ¤ī¸âđâđŠđģ", "đŠđŧââ¤âđâđŠđģ");
|
||
test_remove_emoji_selectors("đđģ", "đđģ");
|
||
test_remove_emoji_selectors("đđŧ", "đđŧ");
|
||
test_remove_emoji_selectors("đđŊ", "đđŊ");
|
||
test_remove_emoji_selectors("đđž", "đđž");
|
||
test_remove_emoji_selectors("đđŋ", "đđŋ");
|
||
test_remove_emoji_selectors("đģ", "đģ");
|
||
test_remove_emoji_selectors("đŧ", "đŧ");
|
||
test_remove_emoji_selectors("đŊ", "đŊ");
|
||
test_remove_emoji_selectors("đž", "đž");
|
||
test_remove_emoji_selectors("đŋ", "đŋ");
|
||
test_remove_emoji_selectors("â", "â");
|
||
test_remove_emoji_selectors("â", "â");
|
||
test_remove_emoji_selectors("đĒ", "đĒ");
|
||
test_remove_emoji_selectors("2ī¸âŖ", "2âŖ");
|
||
test_remove_emoji_selectors("2âŖ", "2âŖ");
|
||
test_remove_emoji_selectors("â¤ī¸", "â¤");
|
||
test_remove_emoji_selectors("â¤", "â¤");
|
||
test_remove_emoji_selectors("â", "â");
|
||
test_remove_emoji_selectors("đ", "đ");
|
||
test_remove_emoji_selectors("đ§âđ", "đ§âđ");
|
||
}
|