ruby-changes:43315
From: duerst <ko1@a...>
Date: Sun, 12 Jun 2016 14:48:09 +0900 (JST)
Subject: [ruby-changes:43315] duerst:r55389 (trunk): * test/ruby/enc/test_case_comprehensive.rb: Add tests for ASCII-only
duerst 2016-06-12 14:48:04 +0900 (Sun, 12 Jun 2016) New Revision: 55389 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55389 Log: * test/ruby/enc/test_case_comprehensive.rb: Add tests for ASCII-only swapcase; store calculated values in hashes. Modified files: trunk/ChangeLog trunk/test/ruby/enc/test_case_comprehensive.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 55388) +++ ChangeLog (revision 55389) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun Jun 12 14:48:00 2016 Martin Duerst <duerst@i...> + + * test/ruby/enc/test_case_comprehensive.rb: Add tests for ASCII-only + swapcase; store calculated values in hashes. + Sun Jun 12 14:05:45 2016 Kazuki Yamaguchi <k@r...> * ext/openssl/ossl_cipher.c (ossl_cipher_get_auth_tag, Index: test/ruby/enc/test_case_comprehensive.rb =================================================================== --- test/ruby/enc/test_case_comprehensive.rb (revision 55388) +++ test/ruby/enc/test_case_comprehensive.rb (revision 55389) @@ -41,16 +41,17 @@ class TestComprehensiveCaseFold < Test:: https://github.com/ruby/ruby/blob/trunk/test/ruby/enc/test_case_comprehensive.rb#L41 def self.read_data @@codepoints = [] - downcase = Hash.new { |h, c| c } - upcase = Hash.new { |h, c| c } - titlecase = Hash.new { |h, c| c } - casefold = Hash.new { |h, c| c } - turkic_upcase = Hash.new { |h, c| upcase[c] } - turkic_downcase = Hash.new { |h, c| downcase[c] } - turkic_titlecase = Hash.new { |h, c| titlecase[c] } - ascii_upcase = Hash.new { |h, c| c =~ /^[a-zA-Z]$/ ? upcase[c] : c } - ascii_downcase = Hash.new { |h, c| c =~ /^[a-zA-Z]$/ ? downcase[c] : c } - ascii_titlecase = Hash.new { |h, c| c =~ /^[a-zA-Z]$/ ? titlecase[c] : c } + downcase = Hash.new { |h, c| h[c] = c } + upcase = Hash.new { |h, c| h[c] = c } + titlecase = Hash.new { |h, c| h[c] = c } + casefold = Hash.new { |h, c| h[c] = c } + turkic_upcase = Hash.new { |h, c| h[c] = upcase[c] } + turkic_downcase = Hash.new { |h, c| h[c] = downcase[c] } + turkic_titlecase = Hash.new { |h, c| h[c] = titlecase[c] } + ascii_upcase = Hash.new { |h, c| h[c] = c =~ /^[a-zA-Z]$/ ? upcase[c] : c } + ascii_downcase = Hash.new { |h, c| h[c] = c =~ /^[a-zA-Z]$/ ? downcase[c] : c } + ascii_titlecase = Hash.new { |h, c| h[c] = c =~ /^[a-zA-Z]$/ ? titlecase[c] : c } + ascii_swapcase = Hash.new { |h, c| h[c] = c=~/^[a-z]$/ ? upcase[c] : (c=~/^[A-Z]$/ ? downcase[c] : c) } read_data_file('UnicodeData') do |code, data| @@codepoints << code @@ -89,6 +90,7 @@ class TestComprehensiveCaseFold < Test:: https://github.com/ruby/ruby/blob/trunk/test/ruby/enc/test_case_comprehensive.rb#L90 CaseTest.new(:upcase, [:ascii], ascii_upcase), CaseTest.new(:downcase, [:ascii], ascii_downcase), CaseTest.new(:capitalize, [:ascii], ascii_titlecase, ascii_downcase), + CaseTest.new(:swapcase, [:ascii], ascii_swapcase), ] end @@ -172,6 +174,18 @@ class TestComprehensiveCaseFold < Test:: https://github.com/ruby/ruby/blob/trunk/test/ruby/enc/test_case_comprehensive.rb#L174 assert_equal target, result, "from #{code*5} (#{source.dump}) expected #{target.dump} but was #{result.dump}" rescue Encoding::UndefinedConversionError + end + end + end + define_method "test_#{encoding}_swapcase" do + codepoints.each do |code| + begin + source = code.encode(encoding) * 5 + target = source.tr('a-zA-Z', 'A-Za-z') + result = source.swapcase + assert_equal target, result, + "from #{code*5} (#{source.dump}) expected #{target.dump} but was #{result.dump}" + rescue Encoding::UndefinedConversionError end end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/