add nil clause for Formatter.get_emoji/1 to return an empty result
This commit is contained in:
parent
d31bbb1cfe
commit
a9c0f395cb
2 changed files with 12 additions and 0 deletions
|
@ -157,6 +157,8 @@ def emojify(text, emoji) do
|
|||
end)
|
||||
end
|
||||
|
||||
def get_emoji(nil), do: []
|
||||
|
||||
def get_emoji(text) do
|
||||
Enum.filter(@emoji, fn {emoji, _} -> String.contains?(text, ":#{emoji}:") end)
|
||||
end
|
||||
|
|
|
@ -199,4 +199,14 @@ test "it returns the emoji used in the text" do
|
|||
|
||||
assert Formatter.get_emoji(text) == [{"moominmamma", "/finmoji/128px/moominmamma-128.png"}]
|
||||
end
|
||||
|
||||
test "it returns a nice empty result when no emojis are present" do
|
||||
text = "I love moominamma"
|
||||
assert Formatter.get_emoji(text) == []
|
||||
end
|
||||
|
||||
test "it doesn't die when text is absent" do
|
||||
text = nil
|
||||
assert Formatter.get_emoji(text) == []
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue