1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Adapt test_emoji_breaks.rb to Unicode 13.0.0/Emoji 13.0

- Add UNICODE_VERSION,... to deal with new location of some
  of the emoji-related data files.
- Introduce class BreakFile to handle various file properties.
- Adapt main code to use BreakFile.
This commit is contained in:
Martin Dürst 2021-07-08 14:40:47 +09:00
parent 146a943d9a
commit 3b36e34b90

View file

@ -31,22 +31,41 @@ class TestEmojiBreaks::BreakTest
end
end
class TestEmojiBreaks < Test::Unit::TestCase
EMOJI_DATA_FILES = %w[emoji-sequences emoji-test emoji-variation-sequences emoji-zwj-sequences]
EMOJI_VERSION = RbConfig::CONFIG['UNICODE_EMOJI_VERSION']
EMOJI_DATA_PATH = File.expand_path("../../../enc/unicode/data/emoji/#{EMOJI_VERSION}", __dir__)
class TestEmojiBreaks::BreakFile
attr_reader :basename, :fullname
FILES = []
def self.expand_filename(basename)
File.expand_path("#{EMOJI_DATA_PATH}/#{basename}.txt", __dir__)
def initialize(basename, path)
@basename = basename
@fullname = "#{path}/#{basename}.txt" # File.expand_path(path + version, __dir__)
FILES << self
end
def self.files
FILES
end
end
class TestEmojiBreaks < Test::Unit::TestCase
UNICODE_VERSION = RbConfig::CONFIG['UNICODE_VERSION']
UNICODE_DATA_PATH = File.expand_path("../../../enc/unicode/data/#{UNICODE_VERSION}/ucd/emoji", __dir__)
EMOJI_VERSION = RbConfig::CONFIG['UNICODE_EMOJI_VERSION']
EMOJI_DATA_PATH = File.expand_path("../../../enc/unicode/data/emoji/#{EMOJI_VERSION}", __dir__)
EMOJI_DATA_FILES = %w[emoji-sequences emoji-test emoji-zwj-sequences].map do |basename|
BreakFile.new(basename, EMOJI_DATA_PATH)
end
UNICODE_DATA_FILE = BreakFile.new('emoji-variation-sequences', UNICODE_DATA_PATH)
EMOJI_DATA_FILES << UNICODE_DATA_FILE
def self.data_files_available?
EMOJI_DATA_FILES.all? do |f|
File.exist?(expand_filename(f))
File.exist?(f.fullname)
end
end
def test_data_files_available
assert_equal 4, EMOJI_DATA_FILES.size # debugging test
unless TestEmojiBreaks.data_files_available?
skip "Emoji data files not available in #{EMOJI_DATA_PATH}."
end
@ -56,15 +75,15 @@ end
TestEmojiBreaks.data_files_available? and class TestEmojiBreaks
def read_data
tests = []
EMOJI_DATA_FILES.each do |filename|
EMOJI_DATA_FILES.each do |file|
version_mismatch = true
file_tests = []
IO.foreach(TestEmojiBreaks.expand_filename(filename), encoding: Encoding::UTF_8) do |line|
IO.foreach(file.fullname, encoding: Encoding::UTF_8) do |line|
line.chomp!
raise "File Name Mismatch" if $.==1 and not line=="# #{filename}.txt"
raise "File Name Mismatch" if $.==1 and not line=="# #{file.basename}.txt"
version_mismatch = false if line=="# Version: #{EMOJI_VERSION}"
next if /\A(#|\z)/.match? line
file_tests << BreakTest.new(filename, $., *line.split('#')) rescue 'whatever'
file_tests << BreakTest.new(file.basename, $., *line.split('#')) rescue 'whatever'
end
raise "File Version Mismatch" if version_mismatch
tests += file_tests