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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
|
require_relative "../lib/unicode/emoji"
require "minitest/autorun"
describe Unicode::Emoji do
describe ".properties" do
it "returns an Array of Emoji properties for given codepoint" do
assert_equal ["Emoji", "Emoji_Presentation", "Extended_Pictographic"], Unicode::Emoji.properties("π΄")
assert_equal ["Emoji", "Extended_Pictographic"], Unicode::Emoji.properties("β ")
end
it "returns nil if codepoint has no Emoji prop" do
assert_nil Unicode::Emoji.properties("A")
end
end
describe "REGEX" do
it "matches most singleton emoji codepoints" do
"π΄ sleeping face" =~ Unicode::Emoji::REGEX
assert_equal "π΄", $&
end
it "matches singleton emoji in combination with emoji variation selector" do
"π΄\u{FE0F} sleeping face" =~ Unicode::Emoji::REGEX
assert_equal "π΄\u{FE0F}", $&
end
it "does not match singleton emoji in combination with text variation selector" do
"π΄\u{FE0E} sleeping face" =~ Unicode::Emoji::REGEX
assert_nil $&
end
it "does not match textual singleton emoji" do
"βΆ play button" =~ Unicode::Emoji::REGEX
assert_nil $&
end
it "matches textual singleton emoji in combination with emoji variation selector" do
"βΆ\u{FE0F} play button" =~ Unicode::Emoji::REGEX
assert_equal "βΆ\u{FE0F}", $&
end
it "matches singleton skin tone modifiers and hair components" do
"π» light skin tone" =~ Unicode::Emoji::REGEX
assert_equal "π»", $&
"π¦° emoji component red hair" =~ Unicode::Emoji::REGEX
assert_equal "π¦°", $&
end
it "does not match singleton components that are not skin tone modifiers or hair components" do
"1 digit one" =~ Unicode::Emoji::REGEX
assert_nil $&
"π¦ regional indicator symbol letter a" =~ Unicode::Emoji::REGEX
assert_nil $&
end
it "matches modified emoji if modifier base emoji is used" do
"ππ½ person in bed: medium skin tone" =~ Unicode::Emoji::REGEX
assert_equal "ππ½", $&
end
it "does not match modified emoji if no modifier base emoji is used" do
"π΅π½ cactus" =~ Unicode::Emoji::REGEX
assert_equal "π΅", $&
end
it "matches valid region flags" do
"π΅πΉ Portugal" =~ Unicode::Emoji::REGEX
assert_equal "π΅πΉ", $&
end
it "does not match invalid region flags" do
"π΅π΅ PP Land" =~ Unicode::Emoji::REGEX
assert_nil $&
end
it "matches emoji keycap sequences" do
"2οΈβ£ keycap: 2" =~ Unicode::Emoji::REGEX
assert_equal "2οΈβ£", $&
end
it "does not match non-emoji keycap sequences" do
"8β£ text keycap: 8" =~ Unicode::Emoji::REGEX
assert_nil $&
"#β£ text keycap: #" =~ Unicode::Emoji::REGEX
assert_nil $&
end
it "matches recommended tag sequences" do
"π΄σ §σ ’σ ³σ £σ ΄σ Ώ Scotland" =~ Unicode::Emoji::REGEX
assert_equal "π΄σ §σ ’σ ³σ £σ ΄σ Ώ", $&
end
it "does not match valid tag sequences that are not recommended" do
"π΄σ §σ ’σ ‘σ §σ ’σ Ώ GB AGB" =~ Unicode::Emoji::REGEX
assert_equal "π΄", $& # only base flag is matched
end
it "matches recommended zwj sequences" do
"π€Ύπ½ββοΈ woman playing handball: medium skin tone" =~ Unicode::Emoji::REGEX
assert_equal "π€Ύπ½ββοΈ", $&
end
it "does not match MQE zwj sequences" do
"π€Ύπ½ββ woman playing handball: medium skin tone, missing VS16" =~ Unicode::Emoji::REGEX
refute_equal "π€Ύπ½ββ", $&
end
it "does not match UQE emoji" do
"πββοΈ man golfing, missing VS16" =~ Unicode::Emoji::REGEX
refute_equal "πββοΈ", $&
end
it "does not match valid zwj sequences that are not recommended" do
"π€ βπ€’ vomiting cowboy" =~ Unicode::Emoji::REGEX
assert_equal "π€ ", $&
end
it "matches 12.1 emoji" do
"π§β𦱠person: curly hair" =~ Unicode::Emoji::REGEX
assert_equal "π§βπ¦±", $&
end
it "matches 13.0 emoji" do
"π¨βπΌ man feeding baby" =~ Unicode::Emoji::REGEX
assert_equal "π¨βπΌ", $&
end
it "matches 13.1 emoji" do
"β€οΈβπ₯ heart on fire" =~ Unicode::Emoji::REGEX
assert_equal "β€οΈβπ₯", $&
end
it "matches 14.0 emoji" do
"πͺΊ nest with eggs" =~ Unicode::Emoji::REGEX
assert_equal "πͺΊ", $&
end
it "matches 15.0 emoji" do
"π¦ββ¬ black bird" =~ Unicode::Emoji::REGEX
assert_equal "π¦ββ¬", $&
end
it "matches 15.1 emoji" do
"πββοΈ head shaking horizontally" =~ Unicode::Emoji::REGEX
assert_equal "πββοΈ", $&
end
it "matches 16.0 emoji" do
"πͺΎ leafless tree" =~ Unicode::Emoji::REGEX
assert_equal "πͺΎ", $&
end
it "matches 17.0 emoji" do
"π«ͺ distorted face" =~ Unicode::Emoji::REGEX
assert_equal "π«ͺ", $&
end
# See gh#12 and https://github.com/matt17r/nw5k/commit/05a34d3c9211a23e5ae6853bb19fd2f224779ef4#diff-afb6f8bc3bae71b75743e00882a060863e2430cbe858ec9014e5956504dfc61cR2
it "matches family emoji correctly" do
["π¨βπ©βπ§βπ¦", "π¨βπ©βπ¦βπ¦", "π¨βπ©βπ§βπ§", "π¨βπ¨βπ§βπ¦", "π¨βπ¨βπ¦βπ¦", "π¨βπ¨βπ§βπ§", "π©βπ©βπ§βπ¦", "π©βπ©βπ¦βπ¦", "π©βπ©βπ§βπ§", "π¨βπ¦βπ¦", "π¨βπ§βπ¦", "π¨βπ§βπ§", "π©βπ¦βπ¦", "π©βπ§βπ¦", "π©βπ§βπ§"].each { |family|
assert_equal family, family[Unicode::Emoji::REGEX]
}
end
end
describe "REGEX_INCLUDE_MQE" do
it "matches MQE emoji" do
"π€Ύπ½ββ woman playing handball: medium skin tone, missing VS16" =~ Unicode::Emoji::REGEX_INCLUDE_MQE
assert_equal "π€Ύπ½ββ", $&
end
it "does not match UQE emoji" do
"πββοΈ man golfing, missing VS16" =~ Unicode::Emoji::REGEX_INCLUDE_MQE
refute_equal "πββοΈ", $&
end
end
describe "REGEX_INCLUDE_MQE_UQE" do
it "matches MQE emoji" do
"π€Ύπ½ββ woman playing handball: medium skin tone, missing VS16" =~ Unicode::Emoji::REGEX_INCLUDE_MQE_UQE
assert_equal "π€Ύπ½ββ", $&
end
it "matches UQE emoji" do
"πββοΈ man golfing, missing VS16" =~ Unicode::Emoji::REGEX_INCLUDE_MQE_UQE
assert_equal "πββοΈ", $&
end
end
describe "REGEX_VALID" do
it "matches most singleton emoji codepoints" do
"π΄ sleeping face" =~ Unicode::Emoji::REGEX_VALID
assert_equal "π΄", $&
end
it "matches singleton emoji in combination with emoji variation selector" do
"π΄\u{FE0F} sleeping face" =~ Unicode::Emoji::REGEX_VALID
assert_equal "π΄\u{FE0F}", $&
end
it "does not match singleton emoji when in combination with text variation selector" do
"π΄\u{FE0E} sleeping face" =~ Unicode::Emoji::REGEX_VALID
assert_nil $&
end
it "does not match textual singleton emoji" do
"βΆ play button" =~ Unicode::Emoji::REGEX_VALID
assert_nil $&
end
it "matches textual singleton emoji in combination with emoji variation selector" do
"βΆ\u{FE0F} play button" =~ Unicode::Emoji::REGEX_VALID
assert_equal "βΆ\u{FE0F}", $&
end
it "matches singleton skin tone modifiers and hair components" do
"π» light skin tone" =~ Unicode::Emoji::REGEX_VALID
assert_equal "π»", $&
"π¦° emoji component red hair" =~ Unicode::Emoji::REGEX_VALID
assert_equal "π¦°", $&
end
it "does not match singleton components that are not skin tone modifiers or hair components" do
"1 digit one" =~ Unicode::Emoji::REGEX_VALID
assert_nil $&
"π¦ regional indicator symbol letter a" =~ Unicode::Emoji::REGEX_VALID
assert_nil $&
end
it "matches modified emoji if modifier base emoji is used" do
"ππ½ person in bed: medium skin tone" =~ Unicode::Emoji::REGEX_VALID
assert_equal "ππ½", $&
end
it "does not match modified emoji if no modifier base emoji is used" do
"π΅π½ cactus" =~ Unicode::Emoji::REGEX_VALID
assert_equal "π΅", $&
end
it "matches valid region flags" do
"π΅πΉ Portugal" =~ Unicode::Emoji::REGEX_VALID
assert_equal "π΅πΉ", $&
end
it "does not match invalid region flags" do
"π΅π΅ PP Land" =~ Unicode::Emoji::REGEX_VALID
assert_nil $&
end
it "matches emoji keycap sequences" do
"2οΈβ£ keycap: 2" =~ Unicode::Emoji::REGEX_VALID
assert_equal "2οΈβ£", $&
end
it "does not match non-emoji keycap sequences" do
"8β£ text keycap: 8" =~ Unicode::Emoji::REGEX_VALID
assert_nil $&
"#β£ text keycap: #" =~ Unicode::Emoji::REGEX_VALID
assert_nil $&
end
it "matches recommended tag sequences" do
"π΄σ §σ ’σ ³σ £σ ΄σ Ώ Scotland" =~ Unicode::Emoji::REGEX_VALID
assert_equal "π΄σ §σ ’σ ³σ £σ ΄σ Ώ", $&
end
it "matches valid tag sequences, even though they are not recommended" do
"π΄σ §σ ’σ ‘σ §σ ’σ Ώ GB AGB" =~ Unicode::Emoji::REGEX_VALID
assert_equal "π΄σ §σ ’σ ‘σ §σ ’σ Ώ", $&
end
it "matches valid tag sequences (compressed one)" do
"π΄σ ¬σ Άσ °σ ΄σ ²σ Ώ lv042" =~ Unicode::Emoji::REGEX_VALID
assert_equal "π΄σ ¬σ Άσ °σ ΄σ ²σ Ώ", $&
end
it "does not match invalid tag sequences" do
"π΄σ §σ ’σ ‘σ ‘σ ‘σ Ώ GB AAA" =~ Unicode::Emoji::REGEX_VALID
assert_equal "π΄", $& # only base flag is matched
end
it "matches recommended zwj sequences" do
"π€Ύπ½ββοΈ woman playing handball: medium skin tone" =~ Unicode::Emoji::REGEX_VALID
assert_equal "π€Ύπ½ββοΈ", $&
end
it "matches valid zwj sequences, even though they are not recommended" do
"π€ βπ€’ vomiting cowboy" =~ Unicode::Emoji::REGEX_VALID
assert_equal "π€ βπ€’", $&
end
end
describe "REGEX_WELL_FORMED" do
it "matches most singleton emoji codepoints" do
"π΄ sleeping face" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_equal "π΄", $&
end
it "matches singleton emoji in combination with emoji variation selector" do
"π΄\u{FE0F} sleeping face" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_equal "π΄\u{FE0F}", $&
end
it "does not match singleton emoji when in combination with text variation selector" do
"π΄\u{FE0E} sleeping face" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_nil $&
end
it "does not match textual singleton emoji" do
"βΆ play button" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_nil $&
end
it "matches textual singleton emoji in combination with emoji variation selector" do
"βΆ\u{FE0F} play button" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_equal "βΆ\u{FE0F}", $&
end
it "matches singleton skin tone modifiers and hair components" do
"π» light skin tone" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_equal "π»", $&
"π¦° emoji component red hair" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_equal "π¦°", $&
end
it "does not match singleton components that are not skin tone modifiers or hair components" do
"1 digit one" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_nil $&
"π¦ regional indicator symbol letter a" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_nil $&
end
it "matches modified emoji if modifier base emoji is used" do
"ππ½ person in bed: medium skin tone" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_equal "ππ½", $&
end
it "does not match modified emoji if no modifier base emoji is used" do
"π΅π½ cactus" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_equal "π΅", $&
end
it "matches valid region flags" do
"π΅πΉ Portugal" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_equal "π΅πΉ", $&
end
it "does match invalid region flags" do
"π΅π΅ PP Land" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_equal "π΅π΅", $&
end
it "matches emoji keycap sequences" do
"2οΈβ£ keycap: 2" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_equal "2οΈβ£", $&
end
it "does not match non-emoji keycap sequences" do
"8β£ text keycap: 8" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_nil $&
"#β£ text keycap: #" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_nil $&
end
it "matches recommended tag sequences" do
"π΄σ §σ ’σ ³σ £σ ΄σ Ώ Scotland" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_equal "π΄σ §σ ’σ ³σ £σ ΄σ Ώ", $&
end
it "matches valid tag sequences, even though they are not recommended" do
"π΄σ §σ ’σ ‘σ §σ ’σ Ώ GB AGB" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_equal "π΄σ §σ ’σ ‘σ §σ ’σ Ώ", $&
end
it "matches invalid base tag sequences" do
"π΄σ §σ ’σ ‘σ ‘σ ‘σ Ώ GB AAA" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_equal "π΄σ §σ ’σ ‘σ ‘σ ‘σ Ώ", $&
end
it "does not match too long tag sequences (only black flag is matched)" do
"π΄σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ Ώ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_equal "π΄", $&
end
it "does not match invalid tag sequences (only black flag is matched)" do
"π΄σ €σ Ώ $" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_equal "π΄", $&
end
it "matches recommended zwj sequences" do
"π€Ύπ½ββοΈ woman playing handball: medium skin tone" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_equal "π€Ύπ½ββοΈ", $&
end
it "matches valid zwj sequences, even though they are not recommended" do
"π€ βπ€’ vomiting cowboy" =~ Unicode::Emoji::REGEX_WELL_FORMED
assert_equal "π€ βπ€’", $&
end
end
describe "REGEX_POSSIBLE" do
it "matches most singleton emoji codepoints" do
"π΄ sleeping face" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "π΄", $&
end
it "matches singleton emoji in combination with emoji variation selector" do
"π΄\u{FE0F} sleeping face" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "π΄\u{FE0F}", $&
end
it "matches singleton emoji (without VS) when in combination with text variation selector" do
"π΄\u{FE0E} sleeping face" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "π΄", $&
end
it "matches textual singleton emoji" do
"βΆ play button" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "βΆ", $&
end
it "matches textual singleton emoji in combination with emoji variation selector" do
"βΆ\u{FE0F} play button" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "βΆ\u{FE0F}", $&
end
it "matches singleton skin tone modifiers and hair components" do
"π» light skin tone" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "π»", $&
"π¦° emoji component red hair" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "π¦°", $&
end
it "matches singleton components that are not skin tone modifiers or hair components" do
"1 digit one" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "1", $&
"π¦ regional indicator symbol letter a" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "π¦", $&
end
it "matches modified emoji if modifier base emoji is used" do
"ππ½ person in bed: medium skin tone" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "ππ½", $&
end
it "matches modified emoji even if no modifier base emoji is used" do
"π΅π½ cactus" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "π΅π½", $&
end
it "matches valid region flags" do
"π΅πΉ Portugal" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "π΅πΉ", $&
end
it "does match invalid region flags" do
"π΅π΅ PP Land" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "π΅π΅", $&
end
it "matches emoji keycap sequences" do
"2οΈβ£ keycap: 2" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "2οΈβ£", $&
end
it "matches only digit of non-emoji keycap sequences" do
"8β£ text keycap: 8" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "8", $&
"#β£ text keycap: #" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "#", $&
end
it "matches recommended tag sequences" do
"π΄σ §σ ’σ ³σ £σ ΄σ Ώ Scotland" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "π΄σ §σ ’σ ³σ £σ ΄σ Ώ", $&
end
it "matches valid tag sequences, even though they are not recommended" do
"π΄σ §σ ’σ ‘σ §σ ’σ Ώ GB AGB" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "π΄σ §σ ’σ ‘σ §σ ’σ Ώ", $&
end
it "matches invalid base tag sequences" do
"π΄σ §σ ’σ ‘σ ‘σ ‘σ Ώ GB AAA" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "π΄σ §σ ’σ ‘σ ‘σ ‘σ Ώ", $&
end
it "matches too long tag sequences" do
"π΄σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ Ώ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "π΄σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ σ Ώ", $&
end
it "machtes invalid tag sequences (only black flag is matched)" do
"π΄σ €σ Ώ $" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "π΄σ €σ Ώ", $&
end
it "matches recommended zwj sequences" do
"π€Ύπ½ββοΈ woman playing handball: medium skin tone" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "π€Ύπ½ββοΈ", $&
end
it "matches valid zwj sequences, even though they are not recommended" do
"π€ βπ€’ vomiting cowboy" =~ Unicode::Emoji::REGEX_POSSIBLE
assert_equal "π€ βπ€’", $&
end
end
describe "REGEX_BASIC" do
it "matches most singleton emoji codepoints" do
"π΄ sleeping face" =~ Unicode::Emoji::REGEX_BASIC
assert_equal "π΄", $&
end
it "matches singleton emoji in combination with emoji variation selector" do
"π΄\u{FE0F} sleeping face" =~ Unicode::Emoji::REGEX_BASIC
assert_equal "π΄\u{FE0F}", $&
end
it "does not match singleton emoji when in combination with text variation selector" do
"π΄\u{FE0E} sleeping face" =~ Unicode::Emoji::REGEX_BASIC
assert_nil $&
end
it "does not match textual singleton emoji" do
"βΆ play button" =~ Unicode::Emoji::REGEX_BASIC
assert_nil $&
end
it "matches textual singleton emoji in combination with emoji variation selector" do
"βΆ\u{FE0F} play button" =~ Unicode::Emoji::REGEX_BASIC
assert_equal "βΆ\u{FE0F}", $&
end
it "matches singleton skin tone modifiers and hair components" do
"π» light skin tone" =~ Unicode::Emoji::REGEX_BASIC
assert_equal "π»", $&
"π¦° emoji component red hair" =~ Unicode::Emoji::REGEX_BASIC
assert_equal "π¦°", $&
end
it "does not match singleton components that are not skin tone modifiers or hair components" do
"1 digit one" =~ Unicode::Emoji::REGEX_BASIC
assert_nil $&
"π¦ regional indicator symbol letter a" =~ Unicode::Emoji::REGEX_BASIC
assert_nil $&
end
it "does not match modified emoji" do
"ππ½ person in bed: medium skin tone" =~ Unicode::Emoji::REGEX_BASIC
assert_equal "π", $&
end
it "does not match region flags" do
"π΅πΉ Portugal" =~ Unicode::Emoji::REGEX_BASIC
assert_nil $&
end
it "does not match emoji keycap sequences" do
"2οΈβ£ keycap: 2" =~ Unicode::Emoji::REGEX_BASIC
assert_nil $&
end
it "does not match tag sequences" do
"π΄σ §σ ’σ ³σ £σ ΄σ Ώ Scotland" =~ Unicode::Emoji::REGEX_BASIC
assert_equal "π΄", $& # only base flag is matched
end
it "does not match zwj sequences" do
"π€Ύπ½ββοΈ woman playing handball: medium skin tone" =~ Unicode::Emoji::REGEX_BASIC
assert_equal "π€Ύ", $&
end
end
describe "REGEX_TEXT" do
it "deos not match singleton emoji codepoints with emoji presentation and no variation selector" do
"π΄ sleeping face" =~ Unicode::Emoji::REGEX_TEXT
assert_nil $&
end
it "does not match singleton emoji in combination with emoji variation selector" do
"π΄\u{FE0F} sleeping face" =~ Unicode::Emoji::REGEX_TEXT
assert_nil $&
end
it "matches singleton emoji in combination with text variation selector" do
"π΄\u{FE0E} sleeping face" =~ Unicode::Emoji::REGEX_TEXT
assert_equal "π΄\u{FE0E}", $&
end
it "matches textual singleton emoji" do
"βΆ play button" =~ Unicode::Emoji::REGEX_TEXT
assert_equal "βΆ", $&
end
it "does not match textual singleton emoji in combination with emoji variation selector" do
"βΆ\u{FE0F} play button" =~ Unicode::Emoji::REGEX_TEXT
assert_nil $&
end
it "does not match textual singleton emoji in combination with emoji modifiers" do
"βπ» victory hand" =~ Unicode::Emoji::REGEX_TEXT
assert_nil $&
end
it "does not match singleton skin tone modifiers and hair components" do
"π» light skin tone" =~ Unicode::Emoji::REGEX_TEXT
assert_nil $&
"π¦° emoji component red hair" =~ Unicode::Emoji::REGEX_TEXT
assert_nil $&
end
it "does not match singleton components that are not skin tone modifiers or hair components" do
"1 digit one" =~ Unicode::Emoji::REGEX_TEXT
assert_nil $&
"π¦ regional indicator symbol letter a" =~ Unicode::Emoji::REGEX_TEXT
assert_nil $&
end
it "does not match modified emoji" do
"ππ½ person in bed: medium skin tone" =~ Unicode::Emoji::REGEX_TEXT
assert_nil $&
end
it "does not match region flags" do
"π΅πΉ Portugal" =~ Unicode::Emoji::REGEX_TEXT
assert_nil $&
end
it "does not match emoji keycap sequences" do
"2οΈβ£ keycap: 2" =~ Unicode::Emoji::REGEX_TEXT
assert_nil $&
end
it "matches non-emoji keycap sequences" do
"8β£ text keycap: 8" =~ Unicode::Emoji::REGEX_TEXT
assert_equal "8β£", $&
"#β£ text keycap: #" =~ Unicode::Emoji::REGEX_TEXT
assert_equal "#β£", $&
end
it "does not match tag sequences" do
"π΄σ §σ ’σ ³σ £σ ΄σ Ώ Scotland" =~ Unicode::Emoji::REGEX_TEXT
assert_nil $&
end
it "does not match zwj sequences" do
"π€Ύπ½ββοΈ woman playing handball: medium skin tone" =~ Unicode::Emoji::REGEX_TEXT
assert_nil $&
end
end
describe "REGEX_PROP_EMOJI" do
it "returns any emoji-related codepoint (but no variation selectors or tags)" do
matches = "1 string π΄\u{FE0F} sleeping face with π΅ and modifier πΎ, also π΄σ §σ ’σ ³σ £σ ΄σ Ώ Scotland".scan(Unicode::Emoji::REGEX_PROP_EMOJI)
assert_equal ["1", "π΄", "π΅", "πΎ", "π΄"], matches
end
end
describe "REGEX_EMOJI_KEYCAP" do
it "matches emoji keycap sequences" do
"2οΈβ£ keycap: 2" =~ Unicode::Emoji::REGEX_EMOJI_KEYCAP
assert_equal "2οΈβ£", $&
end
it "does not match non-emoji keycap sequences" do
"8β£ text keycap: 8" =~ Unicode::Emoji::REGEX_EMOJI_KEYCAP
assert_nil $&
"#β£ text keycap: #" =~ Unicode::Emoji::REGEX_EMOJI_KEYCAP
assert_nil $&
end
end
describe "REGEX_PICTO" do
it "matches codepoints with Extended_Pictograph property (almost all emoji are, but also others)" do
matches = "U+1F32D π HOT DOG, U+203C βΌ DOUBLE EXCLAMATION MARK, U+26E8 β¨ BLACK CROSS ON SHIELD".scan(Unicode::Emoji::REGEX_PICTO)
assert_equal ["π", "βΌ"], matches
end
end
describe "REGEX_PICTO_NO_EMOJI" do
it "matches codepoints with Extended_Pictograph property, but no Emoji property" do
matches = "U+1F32D π HOT DOG, U+203C βΌ DOUBLE EXCLAMATION MARK, U+26E8 β¨ BLACK CROSS ON SHIELD".scan(Unicode::Emoji::REGEX_PICTO_NO_EMOJI)
assert_equal [], matches
end
end
describe ".list" do
it "returns a grouped list of emoji" do
assert_includes Unicode::Emoji.list.keys, "Smileys & Emotion"
end
it "sub-groups the list of emoji" do
assert_includes Unicode::Emoji.list("Smileys & Emotion").keys, "face-glasses"
end
it "has emoji in sub-groups" do
assert_includes Unicode::Emoji.list("Smileys & Emotion", "face-glasses"), "π"
end
it "issues a warning if attempting to retrieve old category" do
assert_output nil, "Warning(unicode-emoji): The category of Smileys & People does not exist anymore\n" do
assert_nil Unicode::Emoji.list("Smileys & People", "face-positive")
end
end
end
end
|