-
Notifications
You must be signed in to change notification settings - Fork 14
/
emoji_test_txt_spec.rb
181 lines (165 loc) · 5.6 KB
/
emoji_test_txt_spec.rb
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
require_relative "../lib/unicode/emoji"
require "minitest/autorun"
require "open-uri"
def iterate_emoji
EMOJI_TEST_FILE.scan(/^(?:# (?<sub>sub)?group: (?<group_name>.*)$)|(?:(?<codepoints>.+?)\s*; (?<qual_status>.+?)-?qualified )/) do
if $~[:codepoints]
yield $~[:codepoints].split.map{|e| e.to_i(16)}.pack("U*"), $~[:qual_status]
end
end
end
describe "emoji-test.txt" do
EMOJI_TEST_FILE = begin
emoji_test_path = File.join(__dir__, "data/emoji-test.txt")
if File.exist? emoji_test_path
file = File.read(emoji_test_path)
else
puts "Downloading emoji-test.txt from the consortium"
URI.open "https://www.unicode.org/Public/emoji/#{Unicode::Emoji::EMOJI_VERSION}/emoji-test.txt" do |f|
file = f.read
File.write(File.join(__dir__, "data/emoji-test.txt"), @file)
end
end
file
end
# qual_status:
# - fully - fully-qualified emoji sequences
# - minimally - minimallyq-ualified emoji sequences (some VS16 missing, but not first one)
# - un - unqualified emoji sequences (some VS16 missing)
describe "REGEX" do
describe "detects fully-qualified emoji" do
iterate_emoji do |emoji, qual_status|
it(emoji) do
if qual_status == "fully"
assert_equal emoji, emoji[Unicode::Emoji::REGEX]
else
refute_equal emoji, emoji[Unicode::Emoji::REGEX]
end
end
end
end
end
describe "REGEX_INCLUDE_TEXT" do
describe "detects fully-qualified emoji and (unqualified) singleton text emoji" do
iterate_emoji do |emoji, qual_status|
it(emoji) do
if qual_status == "fully" || qual_status == "un" && emoji.size <= 2
assert_equal emoji, emoji[Unicode::Emoji::REGEX_INCLUDE_TEXT]
else
refute_equal emoji, emoji[Unicode::Emoji::REGEX_INCLUDE_TEXT]
end
end
end
end
end
describe "REGEX_INCLUDE_MQE" do
describe "detects fully-qualified emoji and minimally-qualified emoji" do
iterate_emoji do |emoji, qual_status|
it(emoji) do
if qual_status == "fully" || qual_status == "minimally"
assert_equal emoji, emoji[Unicode::Emoji::REGEX_INCLUDE_MQE]
else
refute_equal emoji, emoji[Unicode::Emoji::REGEX_INCLUDE_MQE]
end
end
end
end
end
describe "REGEX_INCLUDE_MQE_UQE" do
describe "detects all emoji" do
iterate_emoji do |emoji, qual_status|
it(emoji) do
assert_equal emoji, emoji[Unicode::Emoji::REGEX_INCLUDE_MQE_UQE]
end
end
end
end
describe "REGEX_VALID" do
describe "detects fully-qualified, minimally-qualified emoji, and unqualified emoji with ZWJ" do
iterate_emoji do |emoji, qual_status|
it(emoji) do
if qual_status == "fully" || qual_status == "minimally" || qual_status == "un" && emoji.size >= 3
assert_equal emoji, emoji[Unicode::Emoji::REGEX_VALID]
else
refute_equal emoji, emoji[Unicode::Emoji::REGEX_VALID]
end
end
end
end
end
describe "REGEX_VALID_INCLUDE_TEXT" do
describe "detects all emoji" do
iterate_emoji do |emoji, qual_status|
it(emoji) do
assert_equal emoji, emoji[Unicode::Emoji::REGEX_VALID_INCLUDE_TEXT]
end
end
end
end
describe "REGEX_WELL_FORMED" do
describe "detects fully-qualified, minimally-qualified emoji, and unqualified emoji with ZWJ" do
iterate_emoji do |emoji, qual_status|
it(emoji) do
if qual_status == "fully" || qual_status == "minimally" || qual_status == "un" && emoji.size >= 3
assert_equal emoji, emoji[Unicode::Emoji::REGEX_WELL_FORMED]
else
refute_equal emoji, emoji[Unicode::Emoji::REGEX_WELL_FORMED]
end
end
end
end
end
describe "REGEX_WELL_FORMED_INCLUDE_TEXT" do
describe "detects all emoji" do
iterate_emoji do |emoji, qual_status|
it(emoji) do
assert_equal emoji, emoji[Unicode::Emoji::REGEX_WELL_FORMED_INCLUDE_TEXT]
end
end
end
end
describe "REGEX_POSSIBLE" do
describe "detects all emoji, except unqualified keycap sequences" do
# fixing test not regex, since implementation of this regex should match the one in the standard
unqualified_keycaps = Unicode::Emoji::EMOJI_KEYCAPS.map{|keycap|
[keycap, Unicode::Emoji::EMOJI_KEYCAP_SUFFIX].pack("U*")
}
iterate_emoji do |emoji, qual_status|
it(emoji) do
if !unqualified_keycaps.include?(emoji)
assert_equal emoji, emoji[Unicode::Emoji::REGEX_POSSIBLE]
else
refute_equal emoji, emoji[Unicode::Emoji::REGEX_POSSIBLE]
end
end
end
end
end
describe "REGEX_TEXT" do
describe "detects (unqualified) singleton text emoji" do
iterate_emoji do |emoji, qual_status|
it(emoji) do
# if qual_status == "un" && emoji =~ /^.[\u{FE0E 20E3}]?$/
if qual_status == "un" && emoji.size <= 2
assert_equal emoji, emoji[Unicode::Emoji::REGEX_TEXT]
else
refute_equal emoji, emoji[Unicode::Emoji::REGEX_TEXT]
end
end
end
end
end
describe "REGEX_BASIC" do
describe "detects (fully-qualified) singleton emoji" do
iterate_emoji do |emoji, qual_status|
it(emoji) do
if qual_status == "fully" && emoji =~ /^.\u{FE0F}?$/
assert_equal emoji, emoji[Unicode::Emoji::REGEX_BASIC]
else
refute_equal emoji, emoji[Unicode::Emoji::REGEX_BASIC]
end
end
end
end
end
end