forked from tdlib/td
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemoji.cpp
148 lines (141 loc) · 6.85 KB
/
emoji.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//
// Copyright Aliaksei Levin ([email protected]), Arseny Smirnov ([email protected]) 2014-2024
//
// 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/common.h"
#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("👩🏼❤💋👩🏻️")); // not in RGI emoji ZWJ sequence set
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("🕵♂️")); // not in RGI emoji ZWJ sequence set
ASSERT_TRUE(td::is_emoji("🕵️♂")); // not in RGI emoji ZWJ sequence set
ASSERT_TRUE(td::is_emoji("🕵♂"));
ASSERT_TRUE(td::is_emoji("🏌️♂️"));
ASSERT_TRUE(td::is_emoji("🏋️♂️"));
ASSERT_TRUE(td::is_emoji("🏌♂️")); // not in RGI emoji ZWJ sequence set
ASSERT_TRUE(td::is_emoji("🏋♂️")); // not in RGI emoji ZWJ sequence set
ASSERT_TRUE(!td::is_emoji("a🤝👨"));
ASSERT_TRUE(!td::is_emoji("👩a👨"));
ASSERT_TRUE(!td::is_emoji("👩🤝a"));
ASSERT_TRUE(td::is_emoji("👩🤝👨")); // not in RGI emoji ZWJ sequence set
}
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, bool remove_selectors = true) {
ASSERT_STREQ(result, td::remove_emoji_modifiers(emoji, remove_selectors));
td::remove_emoji_modifiers_in_place(emoji, remove_selectors);
ASSERT_STREQ(result, emoji);
ASSERT_STREQ(emoji, td::remove_emoji_modifiers(emoji, remove_selectors));
}
TEST(Emoji, remove_emoji_modifiers) {
test_remove_emoji_modifiers("", "");
test_remove_emoji_modifiers("👩🏼❤💋👩🏻", "👩❤💋👩");
test_remove_emoji_modifiers("👩🏼❤️💋👩🏻", "👩❤💋👩");
test_remove_emoji_modifiers("👩🏼❤️💋👩🏻", "👩❤️💋👩", false);
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("🧑🎄", "🧑🎄");
}