Skip to content
Snippets Groups Projects
Commit e26557d8 authored by Brett Walker's avatar Brett Walker
Browse files

Ensure no Unicode aliases collide with gemojione

Changelog: fixed
parent 69b21977
No related branches found
No related tags found
1 merge request!75Ensure no Unicode aliases collide with gemojione
Pipeline #1511094596 passed
# frozen_string_literal: true
require "bundler/setup"
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "rubocop/rake_task"
......
......@@ -143,7 +143,9 @@ module TanukiEmoji
end
def inspect
"#<#{self.class.name}: #{codepoints} (#{hex}) #{alpha_code} aliases: #{aliases}>"
# rubocop:disable Layout/LineLength
%(#<#{self.class.name}: #{codepoints} (#{hex}), alpha_code: "#{alpha_code}", aliases: #{aliases}, name: "#{name}", description: "#{description}">)
# rubocop:enable Layout/LineLength
end
def ==(other)
......
......@@ -50,10 +50,17 @@ module TanukiEmoji
if emoji.alpha_code != emoji_data[:shortname]
org_alpha_code = emoji.alpha_code
org_alpha_code_sym = TanukiEmoji::Character.format_name(org_alpha_code).to_sym
emoji.replace_alpha_code(emoji_data[:shortname])
# add the unicode alias back only if it's not a different emoji
emoji.add_alias(org_alpha_code) unless EMOJI_DIFFERENCES[:unicode].include?(emoji.codepoints)
# rubocop:disable Style/AsciiComments
# Ensure that we're not adding an alias that is part of the gemonione data.
# For example, Unicode uses `sunglasses` for 🕶️, which is `dark_sunglasses` in gemojione.
# `sunglasses` is 😎 which is `smiling_face_with_sunglasses` in Unicode.
# We don't want `sunglasses` to be added as an alias of `dark_sunglasses`, because that
# would interfere with `sunglasses` being the primary code for `smiling_face_with_sunglasses`
# rubocop:enable Style/AsciiComments
emoji.add_alias(org_alpha_code) unless db.key?(org_alpha_code_sym) || EMOJI_DIFFERENCES[:unicode].include?(emoji.codepoints)
end
add_emoji_data(emoji, emoji_data)
......
......@@ -65,7 +65,8 @@ RSpec.describe TanukiEmoji::Character do
describe '#inspect' do
it 'returns a formatted string' do
expect(character.inspect).to eq('#<TanukiEmoji::Character: 🐴 (1f434) :horse: aliases: []>')
expect(character.inspect)
.to eq('#<TanukiEmoji::Character: 🐴 (1f434), alpha_code: ":horse:", aliases: [], name: "horse", description: "horse face">')
end
end
......
......@@ -15,16 +15,18 @@ RSpec.describe TanukiEmoji::Db::Gemojione do
}
end
let(:gemoji_db) do
File.open(TanukiEmoji::Db::Gemojione::DATA_FILE, 'r:UTF-8') do |file|
JSON.parse(file.read, symbolize_names: true)
end
end
before do
TanukiEmoji::Index.instance.reset!
end
it 'contains all codepoints', :aggregate_failures do
db = File.open(TanukiEmoji::Db::Gemojione::DATA_FILE, 'r:UTF-8') do |file|
JSON.parse(file.read, symbolize_names: true)
end
db.each_value do |emoji_data|
gemoji_db.each_value do |emoji_data|
next if emoji_exceptions.key?(emoji_data[:moji])
emoji = TanukiEmoji.find_by_codepoints(emoji_data[:moji])
......@@ -34,11 +36,7 @@ RSpec.describe TanukiEmoji::Db::Gemojione do
end
it 'alpha_codes correspond to correct emojis', :aggregate_failures do
db = File.open(TanukiEmoji::Db::Gemojione::DATA_FILE, 'r:UTF-8') do |file|
JSON.parse(file.read, symbolize_names: true)
end
db.each_value do |emoji_data|
gemoji_db.each_value do |emoji_data|
next if emoji_exceptions.key?(emoji_data[:moji])
emoji = TanukiEmoji.find_by_alpha_code(emoji_data[:shortname])
......@@ -47,6 +45,14 @@ RSpec.describe TanukiEmoji::Db::Gemojione do
end
end
it 'ensures a gemojione code is not used as an alias', :aggregate_failures do
db_shortnames = gemoji_db.values.map { |value| value[:shortname] }
TanukiEmoji.index.all.each do |emoji|
expect(emoji.aliases & db_shortnames).to be_empty
end
end
it 'verify emoji differences resolve correctly' do
TanukiEmoji::Db::Gemojione::EMOJI_DIFFERENCES[:gemojione].each do |glyph|
emoji = TanukiEmoji.find_by_codepoints(glyph)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment