diff options
author | duerst <duerst@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-06-12 05:48:04 +0000 |
---|---|---|
committer | duerst <duerst@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-06-12 05:48:04 +0000 |
commit | 898899ea3c283d62c6652e229b22fc4bfa4005e7 (patch) | |
tree | 3c543ed38bb4f885a926d5d5513850af8bb8c0ab /test | |
parent | 83136805cdbb45874348bc231672f46bc8f212e7 (diff) | |
download | ruby-898899ea3c283d62c6652e229b22fc4bfa4005e7.tar.gz |
* test/ruby/enc/test_case_comprehensive.rb: Add tests for ASCII-only
swapcase; store calculated values in hashes.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55389 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/enc/test_case_comprehensive.rb | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/test/ruby/enc/test_case_comprehensive.rb b/test/ruby/enc/test_case_comprehensive.rb index 6e1f894d79..85b1b31028 100644 --- a/test/ruby/enc/test_case_comprehensive.rb +++ b/test/ruby/enc/test_case_comprehensive.rb @@ -41,16 +41,17 @@ class TestComprehensiveCaseFold < Test::Unit::TestCase 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::Unit::TestCase 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 @@ -175,6 +177,18 @@ class TestComprehensiveCaseFold < Test::Unit::TestCase 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 end def check_file_available(filename) |