2019-07-10 05:13:23 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 20:38:50 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2019-07-10 05:13:23 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-04-01 10:17:57 +00:00
|
|
|
defmodule Pleroma.EmojiTest do
|
2020-12-21 11:21:40 +00:00
|
|
|
use ExUnit.Case, async: true
|
2019-04-01 10:17:57 +00:00
|
|
|
alias Pleroma.Emoji
|
|
|
|
|
2024-01-26 21:55:08 +00:00
|
|
|
describe "unicode?/1" do
|
2019-09-13 00:11:02 +00:00
|
|
|
test "tells if a string is an unicode emoji" do
|
2024-01-26 21:55:08 +00:00
|
|
|
refute Emoji.unicode?("X")
|
|
|
|
refute Emoji.unicode?("ね")
|
2020-12-02 15:15:03 +00:00
|
|
|
|
2020-12-02 15:46:19 +00:00
|
|
|
# Only accept fully-qualified (RGI) emoji
|
|
|
|
# See http://www.unicode.org/reports/tr51/
|
2024-01-26 21:55:08 +00:00
|
|
|
refute Emoji.unicode?("❤")
|
|
|
|
refute Emoji.unicode?("☂")
|
2020-12-02 15:46:19 +00:00
|
|
|
|
2024-01-26 21:55:08 +00:00
|
|
|
assert Emoji.unicode?("🥺")
|
|
|
|
assert Emoji.unicode?("🤰")
|
|
|
|
assert Emoji.unicode?("❤️")
|
|
|
|
assert Emoji.unicode?("🏳️⚧️")
|
|
|
|
assert Emoji.unicode?("🫵")
|
2020-12-03 15:17:39 +00:00
|
|
|
|
|
|
|
# Additionally, we accept regional indicators.
|
2024-01-26 21:55:08 +00:00
|
|
|
assert Emoji.unicode?("🇵")
|
|
|
|
assert Emoji.unicode?("🇴")
|
|
|
|
assert Emoji.unicode?("🇬")
|
2019-09-13 00:11:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-01 10:17:57 +00:00
|
|
|
describe "get_all/0" do
|
|
|
|
setup do
|
|
|
|
emoji_list = Emoji.get_all()
|
|
|
|
{:ok, emoji_list: emoji_list}
|
|
|
|
end
|
2019-04-01 10:54:30 +00:00
|
|
|
|
2019-04-01 10:17:57 +00:00
|
|
|
test "first emoji", %{emoji_list: emoji_list} do
|
|
|
|
[emoji | _others] = emoji_list
|
2019-08-31 07:14:53 +00:00
|
|
|
{code, %Emoji{file: path, tags: tags}} = emoji
|
2019-04-01 10:17:57 +00:00
|
|
|
|
2019-08-31 07:14:53 +00:00
|
|
|
assert tuple_size(emoji) == 2
|
2019-04-01 10:17:57 +00:00
|
|
|
assert is_binary(code)
|
|
|
|
assert is_binary(path)
|
2019-04-18 18:17:52 +00:00
|
|
|
assert is_list(tags)
|
2019-04-01 10:17:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "random emoji", %{emoji_list: emoji_list} do
|
|
|
|
emoji = Enum.random(emoji_list)
|
2019-08-31 07:14:53 +00:00
|
|
|
{code, %Emoji{file: path, tags: tags}} = emoji
|
2019-04-01 10:17:57 +00:00
|
|
|
|
2019-08-31 07:14:53 +00:00
|
|
|
assert tuple_size(emoji) == 2
|
2019-04-01 10:17:57 +00:00
|
|
|
assert is_binary(code)
|
|
|
|
assert is_binary(path)
|
2019-04-18 18:17:52 +00:00
|
|
|
assert is_list(tags)
|
2019-04-01 10:17:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|