Gitlab: Run benchmark in CI.
[akkoma] / test / emoji_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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 "get_all/0" do
10 setup do
11 emoji_list = Emoji.get_all()
12 {:ok, emoji_list: emoji_list}
13 end
14
15 test "first emoji", %{emoji_list: emoji_list} do
16 [emoji | _others] = emoji_list
17 {code, path, tags} = emoji
18
19 assert tuple_size(emoji) == 3
20 assert is_binary(code)
21 assert is_binary(path)
22 assert is_list(tags)
23 end
24
25 test "random emoji", %{emoji_list: emoji_list} do
26 emoji = Enum.random(emoji_list)
27 {code, path, tags} = emoji
28
29 assert tuple_size(emoji) == 3
30 assert is_binary(code)
31 assert is_binary(path)
32 assert is_list(tags)
33 end
34 end
35
36 describe "match_extra/2" do
37 setup do
38 groups = [
39 "list of files": ["/emoji/custom/first_file.png", "/emoji/custom/second_file.png"],
40 "wildcard folder": "/emoji/custom/*/file.png",
41 "wildcard files": "/emoji/custom/folder/*.png",
42 "special file": "/emoji/custom/special.png"
43 ]
44
45 {:ok, groups: groups}
46 end
47
48 test "config for list of files", %{groups: groups} do
49 group =
50 groups
51 |> Emoji.match_extra("/emoji/custom/first_file.png")
52 |> to_string()
53
54 assert group == "list of files"
55 end
56
57 test "config with wildcard folder", %{groups: groups} do
58 group =
59 groups
60 |> Emoji.match_extra("/emoji/custom/some_folder/file.png")
61 |> to_string()
62
63 assert group == "wildcard folder"
64 end
65
66 test "config with wildcard folder and subfolders", %{groups: groups} do
67 group =
68 groups
69 |> Emoji.match_extra("/emoji/custom/some_folder/another_folder/file.png")
70 |> to_string()
71
72 assert group == "wildcard folder"
73 end
74
75 test "config with wildcard files", %{groups: groups} do
76 group =
77 groups
78 |> Emoji.match_extra("/emoji/custom/folder/some_file.png")
79 |> to_string()
80
81 assert group == "wildcard files"
82 end
83
84 test "config with wildcard files and subfolders", %{groups: groups} do
85 group =
86 groups
87 |> Emoji.match_extra("/emoji/custom/folder/another_folder/some_file.png")
88 |> to_string()
89
90 assert group == "wildcard files"
91 end
92
93 test "config for special file", %{groups: groups} do
94 group =
95 groups
96 |> Emoji.match_extra("/emoji/custom/special.png")
97 |> to_string()
98
99 assert group == "special file"
100 end
101
102 test "no mathing returns nil", %{groups: groups} do
103 group =
104 groups
105 |> Emoji.match_extra("/emoji/some_undefined.png")
106
107 refute group
108 end
109 end
110 end