diff options
author | Martin Dürst <duerst@it.aoyama.ac.jp> | 2021-07-08 14:40:47 +0900 |
---|---|---|
committer | Martin Dürst <duerst@it.aoyama.ac.jp> | 2021-07-08 14:45:03 +0900 |
commit | 3b36e34b9081fc0e43b2fde484f6d07f45ddb2b1 (patch) | |
tree | 76bdfd38207dc03fcdebee03de08ae597af03f73 /test | |
parent | 146a943d9aabb9dda3c5fa1fc3d493c1df969184 (diff) | |
download | ruby-3b36e34b9081fc0e43b2fde484f6d07f45ddb2b1.tar.gz |
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.
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/enc/test_emoji_breaks.rb | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/test/ruby/enc/test_emoji_breaks.rb b/test/ruby/enc/test_emoji_breaks.rb index 7048d8d59f..8f73a728d6 100644 --- a/test/ruby/enc/test_emoji_breaks.rb +++ b/test/ruby/enc/test_emoji_breaks.rb @@ -31,22 +31,41 @@ class TestEmojiBreaks::BreakTest end end +class TestEmojiBreaks::BreakFile + attr_reader :basename, :fullname + FILES = [] + + 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 - 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__) + 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__) - def self.expand_filename(basename) - File.expand_path("#{EMOJI_DATA_PATH}/#{basename}.txt", __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 |