Commit 44821e6c by Mark Wunsch

Handle emoji in a more OO, and use sets for lookup

parent 7efaed20
# -*- encoding: utf-8 -*-
require 'rumoji'
require 'minitest/spec'
require 'minitest/autorun'
describe Rumoji::Emoji do
let(:symbols) { [:hankey, :poop, :shit] }
let(:name) { "PILE OF POO" }
let(:poo_string) { "\u{1F4A9}" }
subject do
Rumoji::Emoji.new(poo_string, symbols, name)
end
it("has a name") { subject.name.must_equal name }
it("has a cheat sheet code") { symbols.must_include subject.code }
it("can test if it includes a cheat sheet code") { symbols.all?{|symbol| subject.include?(symbol) }.must_equal true }
it("converts to the emoji string") { subject.to_s.must_equal poo_string }
it("converts to a hex code") { subject.hex.must_equal "1F4A9" }
describe "with multiple codepoints" do
# From the Unicode 6.2.0 standard:
# The regional indicator symbols in the range
# U+1F1E6..U+1F1FF can be used in pairs to represent an ISO 3166 region code.
# This mechanism is not intended to supplant actual ISO 3166 region codes,
# which simply use Latin letters in the ASCII range; instead the main purpose
# of such pairs is to provide unambiguous roundtrip mappings to certain
# characters used in the emoji core sets. The representative glyph for
# region indicator symbols is simply a dotted box containing a letter. The
# Unicode Standard does not prescribe how the pairs of region indicator
# symbols should be rendered. In emoji contexts, where text is displayed
# as it would be on a Japanese mobile phone, a pair may be displayed using
# the glyph for a flag, as appropriate, but in other contexts the pair
# could be rendered differently
#
# http://www.unicode.org/versions/Unicode6.2.0/
let(:symbol) { :us }
let(:name) { "REGIONAL INDICATOR SYMBOL LETTERS US" }
let(:us_string) { "\xF0\x9F\x87\xBA\xF0\x9F\x87\xB8" }
subject do
Rumoji::Emoji.new(us_string, symbol, name)
end
it("has one code") { subject.code.must_equal symbol }
it("includes the symbol") { subject.must_include symbol }
it("transforms to the correct string") { subject.to_s.must_equal us_string }
end
describe "factory methods" do
subject { Rumoji::Emoji }
let(:smile_str) { "\u{1F604}" }
let(:smile_sym) { :smile }
it "finds an emoji from cheat sheet code" do
subject.find(smile_sym).to_s.must_equal smile_str
end
it "finds an emoji from a string" do
subject.find_by_string(smile_str).code.must_equal smile_sym
end
it "finds an emoji from a codepoint" do
smile_str.codepoints.map do |point|
subject.find_by_codepoint(point).code.must_equal smile_sym
end
end
end
end
...@@ -25,14 +25,14 @@ describe Rumoji do ...@@ -25,14 +25,14 @@ describe Rumoji do
describe "#encode_io" do describe "#encode_io" do
it "reads emoji from one stream and outputs a stream of cheat-sheet codes" do it "reads emoji from one stream and outputs a stream of cheat-sheet codes" do
io = StringIO.new("#{@smile}") io = StringIO.new("#{@smile}")
Rumoji.encode_io(io).read.must_equal ":smile:" Rumoji.encode_io(io).string.must_equal ":smile:"
end end
end end
describe "#decode_io" do describe "#decode_io" do
it "reads a cheat-sheet code from one stream and outputs a stream of emoji" do it "reads a cheat-sheet code from one stream and outputs a stream of emoji" do
io = StringIO.new(":poop:") io = StringIO.new(":poop:")
Rumoji.decode_io(io).read.must_equal @poop Rumoji.decode_io(io).string.must_equal @poop
end end
end end
end end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment