add inbound language test
[akkoma] / test / pleroma / emoji_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.EmojiTest do
6 use ExUnit.Case, async: true
7 alias Pleroma.Emoji
8
9 describe "is_unicode_emoji?/1" do
10 test "tells if a string is an unicode emoji" do
11 refute Emoji.is_unicode_emoji?("X")
12 refute Emoji.is_unicode_emoji?("ね")
13
14 # Accept fully-qualified and unqualified emoji
15 # See http://www.unicode.org/reports/tr51/
16 refute Emoji.is_unicode_emoji?("❤")
17 refute Emoji.is_unicode_emoji?("☂")
18
19 assert Emoji.is_unicode_emoji?("🥺")
20 assert Emoji.is_unicode_emoji?("🤰")
21 assert Emoji.is_unicode_emoji?("❤️")
22 assert Emoji.is_unicode_emoji?("🏳️‍⚧️")
23 assert Emoji.is_unicode_emoji?("🫵")
24
25 # Additionally, we accept regional indicators.
26 assert Emoji.is_unicode_emoji?("🇵")
27 assert Emoji.is_unicode_emoji?("🇴")
28 assert Emoji.is_unicode_emoji?("🇬")
29 end
30 end
31
32 describe "get_all/0" do
33 setup do
34 emoji_list = Emoji.get_all()
35 {:ok, emoji_list: emoji_list}
36 end
37
38 test "first emoji", %{emoji_list: emoji_list} do
39 [emoji | _others] = emoji_list
40 {code, %Emoji{file: path, tags: tags}} = emoji
41
42 assert tuple_size(emoji) == 2
43 assert is_binary(code)
44 assert is_binary(path)
45 assert is_list(tags)
46 end
47
48 test "random emoji", %{emoji_list: emoji_list} do
49 emoji = Enum.random(emoji_list)
50 {code, %Emoji{file: path, tags: tags}} = emoji
51
52 assert tuple_size(emoji) == 2
53 assert is_binary(code)
54 assert is_binary(path)
55 assert is_list(tags)
56 end
57 end
58 end