Skip to content

Commit

Permalink
update unicode string escape sequences for 1.3
Browse files Browse the repository at this point in the history
Prior to this commit exmoji used the old `\x{H*}` format for unicode
escape sequences, which generates warnings with Elixir 1.3. This commit
updates those escape sequences to use the preferred `\xHH` and `\uHHHH`
formats.
  • Loading branch information
Jeff Weiss committed Jun 21, 2016
1 parent c38b89b commit 0fbc26a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/exmoji.ex
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ defmodule Exmoji do
iex> Exmoji.char_to_unified("👾")
"1F47E"
iex> Exmoji.char_to_unified("\x{23}\x{fe0f}\x{20e3}")
iex> Exmoji.char_to_unified("\x23\u{fe0f}\u{20e3}")
"0023-FE0F-20E3"
"""
Expand Down
14 changes: 7 additions & 7 deletions test/emoji_char_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ defmodule EmojiCharTest do
end

test ".render - should have flag to output forced emoji variant char encoding if requested", examples do
assert EmojiChar.render(examples[:cloud], variant_encoding: false) == "\x{2601}"
assert EmojiChar.render(examples[:cloud], variant_encoding: true) == "\x{2601}\x{FE0F}"
assert EmojiChar.render(examples[:cloud], variant_encoding: false) == "\u2601"
assert EmojiChar.render(examples[:cloud], variant_encoding: true) == "\u2601\uFE0F"
end

test ".render - should fall back to normal encoding if no variant exists, even when requested", examples do
assert EmojiChar.render(examples[:invader], variant_encoding: false) == "\x{1F47E}"
assert EmojiChar.render(examples[:invader], variant_encoding: true) == "\x{1F47E}"
assert EmojiChar.render(examples[:invader], variant_encoding: false) == "\u{1F47E}"
assert EmojiChar.render(examples[:invader], variant_encoding: true) == "\u{1F47E}"
end

test ".render - should default to variant encoding for chars with a variant present", examples do
assert EmojiChar.render(examples[:cloud]) == "\x{2601}\x{FE0F}"
assert EmojiChar.render(examples[:hourglass]) == "\x{231B}\x{FE0F}"
assert EmojiChar.render(examples[:cloud]) == "\u2601\uFE0F"
assert EmojiChar.render(examples[:hourglass]) == "\u231B\uFE0F"
end


Expand All @@ -51,7 +51,7 @@ defmodule EmojiCharTest do
#
test ".chars - should return an array of all possible string render variations", examples do
assert EmojiChar.chars(examples[:invader]) == ["👾"]
assert EmojiChar.chars(examples[:cloud]) == ["\x{2601}","\x{2601}\x{FE0F}"]
assert EmojiChar.chars(examples[:cloud]) == ["\u2601","\u2601\uFE0F"]
end


Expand Down
6 changes: 3 additions & 3 deletions test/exmoji_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ defmodule ExmojiTest do
end

test ".char_to_unified - converts variant encoded emoji to variant unified codepoint" do
assert Exmoji.char_to_unified("\x{2601}\x{FE0F}") == "2601-FE0F"
assert Exmoji.char_to_unified("\u{2601}\u{FE0F}") == "2601-FE0F"
end


Expand All @@ -174,11 +174,11 @@ defmodule ExmojiTest do
end

test ".unified_to_char - converts variant unified codepoints to unicode strings" do
assert Exmoji.unified_to_char("2764-fe0f") == "\x{2764}\x{FE0F}"
assert Exmoji.unified_to_char("2764-fe0f") == "\u{2764}\u{FE0F}"
end

test ".unified_to_char - converts variant+doublebyte chars (triplets!) to unicode strings" do
assert Exmoji.unified_to_char("0030-FE0F-20E3") == "\x{0030}\x{FE0F}\x{20E3}"
assert Exmoji.unified_to_char("0030-FE0F-20E3") == "\u{0030}\u{FE0F}\u{20E3}"
end

end
4 changes: 2 additions & 2 deletions test/scanner_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ defmodule ScannerTest do
alias Exmoji.Scanner

@case_exact "🚀"
@case_multi "\x{0023}\x{FE0F}\x{20E3}"
@case_multi "\u{0023}\u{FE0F}\u{20E3}"
@case_variant "flying on my 🚀 to visit the 👾 people."
@case_multivariant "first a \x{0023}\x{FE0F}\x{20E3} then a 🚀"
@case_multivariant "first a \u{0023}\u{FE0F}\u{20E3} then a 🚀"
@case_duplicates "flying my 🚀 to visit the 👾 people who have their own 🚀 omg!"
@case_none "i like turtles"

Expand Down

0 comments on commit 0fbc26a

Please sign in to comment.