diff options
Diffstat (limited to 'test/ruby/enc/test_case_comprehensive.rb')
-rw-r--r-- | test/ruby/enc/test_case_comprehensive.rb | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/test/ruby/enc/test_case_comprehensive.rb b/test/ruby/enc/test_case_comprehensive.rb index aee4331aa6..6d561d6d33 100644 --- a/test/ruby/enc/test_case_comprehensive.rb +++ b/test/ruby/enc/test_case_comprehensive.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Copyright © 2016 Martin J. Dürst (duerst@it.aoyama.ac.jp) require "test/unit" @@ -36,7 +37,7 @@ class TestComprehensiveCaseFold < Test::Unit::TestCase end next if /\A(?:[\#@]|\s*\z)|Surrogate/.match?(line) data = line.chomp.split('#')[0].split(/;\s*/, 15) - code = data[0].to_i(16).chr('UTF-8') + code = data[0].to_i(16).chr(Encoding::UTF_8) yield code, data end end @@ -130,6 +131,22 @@ class TestComprehensiveCaseFold < Test::Unit::TestCase @@tests ||= [] end + def self.generate_unicode_case_mapping_tests (encoding) + all_tests.each do |test| + attributes = test.attributes.map(&:to_s).join '-' + attributes.prepend '_' unless attributes.empty? + define_method "test_#{encoding}_#{test.method_name}#{attributes}" do + @@codepoints.each do |code| + source = code.encode(encoding) * 5 + target = "#{test.first_data[code]}#{test.follow_data[code]*4}".encode(encoding) + result = source.__send__(test.method_name, *test.attributes) + assert_equal target, target, + proc{"from #{code*5} (#{source.dump}) expected #{target.dump} but was #{result.dump}"} + end + end + end + end + def self.generate_case_mapping_tests (encoding) all_tests # preselect codepoints to speed up testing for small encodings @@ -261,13 +278,13 @@ class TestComprehensiveCaseFold < Test::Unit::TestCase generate_case_mapping_tests 'ISO-8859-1' generate_case_mapping_tests 'US-ASCII' generate_case_mapping_tests 'ASCII-8BIT' - generate_case_mapping_tests 'UTF-8' - generate_case_mapping_tests 'UTF-16BE' - generate_case_mapping_tests 'UTF-16LE' - generate_case_mapping_tests 'UTF-32BE' - generate_case_mapping_tests 'UTF-32LE' generate_case_mapping_tests 'ISO-8859-11' generate_case_mapping_tests 'ISO-8859-8' generate_case_mapping_tests 'ISO-8859-6' generate_case_mapping_tests 'Windows-1255' + generate_unicode_case_mapping_tests 'UTF-8' + generate_unicode_case_mapping_tests 'UTF-16BE' + generate_unicode_case_mapping_tests 'UTF-16LE' + generate_unicode_case_mapping_tests 'UTF-32BE' + generate_unicode_case_mapping_tests 'UTF-32LE' end |