mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
9f703785ec
commit
60095cecc7
2 changed files with 29 additions and 10 deletions
|
@ -1,3 +1,8 @@
|
|||
Sun Jun 12 14:48:00 2016 Martin Duerst <duerst@it.aoyama.ac.jp>
|
||||
|
||||
* 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@rhe.jp>
|
||||
|
||||
* ext/openssl/ossl_cipher.c (ossl_cipher_get_auth_tag,
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue