Optimize to speed up
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55475 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a8e5eaa4b9
commit
f79df8459a
@ -26,13 +26,16 @@ class TestComprehensiveCaseFold < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.read_data_file (filename)
|
def self.read_data_file (filename)
|
||||||
IO.readlines(expand_filename(filename), encoding: Encoding::ASCII_8BIT)
|
IO.foreach(expand_filename(filename), encoding: Encoding::ASCII_8BIT) do |line|
|
||||||
.tap do |lines|
|
if $. == 1
|
||||||
raise "File Version Mismatch" unless filename=='UnicodeData' or /#{filename}-#{UNICODE_VERSION}\.txt/ =~ lines[0]
|
if filename == 'UnicodeData'
|
||||||
|
elsif line.start_with?("# #{filename}-#{UNICODE_VERSION}.txt")
|
||||||
|
else
|
||||||
|
raise "File Version Mismatch"
|
||||||
end
|
end
|
||||||
.reject { |line| line =~ /^[\#@]/ or line =~ /^\s*$/ or line =~ /Surrogate/ }
|
end
|
||||||
.each do |line|
|
next if /\A(?:[\#@]|\s*\z)|Surrogate/.match?(line)
|
||||||
data = line.chomp.split('#')[0].split /;\s*/, 15
|
data = line.chomp.split('#')[0].split(/;\s*/, 15)
|
||||||
code = data[0].to_i(16).chr('UTF-8')
|
code = data[0].to_i(16).chr('UTF-8')
|
||||||
yield code, data
|
yield code, data
|
||||||
end
|
end
|
||||||
@ -50,10 +53,10 @@ class TestComprehensiveCaseFold < Test::Unit::TestCase
|
|||||||
turkic_downcase = Hash.new { |h, c| downcase[c] }
|
turkic_downcase = Hash.new { |h, c| downcase[c] }
|
||||||
turkic_titlecase = Hash.new { |h, c| titlecase[c] }
|
turkic_titlecase = Hash.new { |h, c| titlecase[c] }
|
||||||
turkic_swapcase = Hash.new { |h, c| swapcase[c] }
|
turkic_swapcase = Hash.new { |h, c| swapcase[c] }
|
||||||
ascii_upcase = Hash.new { |h, c| c =~ /\A[a-zA-Z]\z/ ? upcase[c] : c }
|
ascii_upcase = Hash.new { |h, c| /\A[a-zA-Z]\z/.match?(c) ? upcase[c] : c }
|
||||||
ascii_downcase = Hash.new { |h, c| c =~ /\A[a-zA-Z]\z/ ? downcase[c] : c }
|
ascii_downcase = Hash.new { |h, c| /\A[a-zA-Z]\z/.match?(c) ? downcase[c] : c }
|
||||||
ascii_titlecase = Hash.new { |h, c| c =~ /\A[a-zA-Z]\z/ ? titlecase[c] : c }
|
ascii_titlecase = Hash.new { |h, c| /\A[a-zA-Z]\z/.match?(c) ? titlecase[c] : c }
|
||||||
ascii_swapcase = Hash.new { |h, c| c=~/\A[a-z]\z/ ? upcase[c] : (c=~/\A[A-Z]\z/ ? downcase[c] : c) }
|
ascii_swapcase = Hash.new { |h, c| /\A[a-z]\z/.match?(c) ? upcase[c] : (/\A[A-Z]\z/.match?(c) ? downcase[c] : c) }
|
||||||
|
|
||||||
read_data_file('UnicodeData') do |code, data|
|
read_data_file('UnicodeData') do |code, data|
|
||||||
@@codepoints << code
|
@@codepoints << code
|
||||||
@ -71,7 +74,7 @@ class TestComprehensiveCaseFold < Test::Unit::TestCase
|
|||||||
upcase[code] = hex2utf8 data[3]
|
upcase[code] = hex2utf8 data[3]
|
||||||
downcase[code] = hex2utf8 data[1]
|
downcase[code] = hex2utf8 data[1]
|
||||||
titlecase[code] = hex2utf8 data[2]
|
titlecase[code] = hex2utf8 data[2]
|
||||||
when /^tr\s*/
|
when /\Atr\s*/
|
||||||
if data[4]!='tr After_I'
|
if data[4]!='tr After_I'
|
||||||
turkic_upcase[code] = hex2utf8 data[3]
|
turkic_upcase[code] = hex2utf8 data[3]
|
||||||
turkic_downcase[code] = hex2utf8 data[1]
|
turkic_downcase[code] = hex2utf8 data[1]
|
||||||
@ -104,7 +107,7 @@ class TestComprehensiveCaseFold < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
tests = [
|
[
|
||||||
CaseTest.new(:downcase, [], downcase),
|
CaseTest.new(:downcase, [], downcase),
|
||||||
CaseTest.new(:upcase, [], upcase),
|
CaseTest.new(:upcase, [], upcase),
|
||||||
CaseTest.new(:capitalize, [], titlecase, downcase),
|
CaseTest.new(:capitalize, [], titlecase, downcase),
|
||||||
@ -123,7 +126,7 @@ class TestComprehensiveCaseFold < Test::Unit::TestCase
|
|||||||
|
|
||||||
def self.all_tests
|
def self.all_tests
|
||||||
@@tests ||= read_data
|
@@tests ||= read_data
|
||||||
rescue Errno::ENOENT => e
|
rescue Errno::ENOENT
|
||||||
@@tests ||= []
|
@@tests ||= []
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -145,10 +148,10 @@ class TestComprehensiveCaseFold < Test::Unit::TestCase
|
|||||||
codepoints.each do |code|
|
codepoints.each do |code|
|
||||||
begin
|
begin
|
||||||
source = code.encode(encoding) * 5
|
source = code.encode(encoding) * 5
|
||||||
target = test.first_data[code].encode(encoding) + test.follow_data[code].encode(encoding) * 4
|
target = "#{test.first_data[code]}#{test.follow_data[code]*4}".encode(encoding)
|
||||||
result = source.send(test.method_name, *test.attributes)
|
result = source.send(test.method_name, *test.attributes)
|
||||||
assert_equal target, result,
|
assert_equal target, result,
|
||||||
"from #{code*5} (#{source.dump}) expected #{target.dump} but was #{result.dump}"
|
proc{"from #{code*5} (#{source.dump}) expected #{target.dump} but was #{result.dump}"}
|
||||||
rescue Encoding::UndefinedConversionError
|
rescue Encoding::UndefinedConversionError
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user