summaryrefslogtreecommitdiff
path: root/test/test_unicode_normalize.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-23 12:36:25 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-23 12:36:25 +0000
commitd8918fa6b5ecf660ebdb5530fa971e324f6847bb (patch)
tree67d13b56742441b76e55af25d697c39ce8275246 /test/test_unicode_normalize.rb
parent3d8641233582c27a34715411b94b2922641ed5da (diff)
test_unicode_normalize.rb: show error messages
* test/test_unicode_normalize.rb (generate_test_normalize): defer building explicit error messages until assertion failed. this is 3% slower than @@debug = false. (generate_test_check_true): ditto. (generate_test_check_false): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48113 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/test_unicode_normalize.rb')
-rw-r--r--test/test_unicode_normalize.rb38
1 files changed, 15 insertions, 23 deletions
diff --git a/test/test_unicode_normalize.rb b/test/test_unicode_normalize.rb
index 587ab18575..7eee7a033e 100644
--- a/test/test_unicode_normalize.rb
+++ b/test/test_unicode_normalize.rb
@@ -7,8 +7,6 @@ require 'test/unit'
NormTest = Struct.new :source, :NFC, :NFD, :NFKC, :NFKD, :line
class TestNormalize < Test::Unit::TestCase
- @@debug = false # if true, generation of explicit error messages is switched on
- # false is about two times faster than true
def read_tests
IO.readlines(File.expand_path('../enc/unicode/data/NormalizationTest.txt', __dir__), encoding: 'utf-8')
.collect.with_index { |linedata, linenumber| [linedata, linenumber]}
@@ -30,16 +28,14 @@ class TestNormalize < Test::Unit::TestCase
def self.generate_test_normalize(target, normalization, source, prechecked)
define_method "test_normalize_to_#{target}_from_#{source}_with_#{normalization}" do
- @@tests.each do |test|
+ expected = actual = test = nil
+ mesg = proc {"#{to_codepoints(expected)} expected but was #{to_codepoints(actual)} on line #{test[:line]} (#{normalization})"}
+ @@tests.each do |t|
+ test = t
if not prechecked or test[source]==test[prechecked]
expected = test[target]
actual = test[source].unicode_normalize(normalization)
- if @@debug
- assert_equal expected, actual,
- "#{to_codepoints(expected)} expected but was #{to_codepoints(actual)} on line #{test[:line]} (#{normalization})"
- else
- assert_equal expected, actual
- end
+ assert_equal expected, actual, mesg
end
end
end
@@ -82,14 +78,12 @@ class TestNormalize < Test::Unit::TestCase
def self.generate_test_check_true(source, normalization)
define_method "test_check_true_#{source}_as_#{normalization}" do
- @@tests.each do |test|
+ test = nil
+ mesg = proc {"#{to_codepoints(test[source])} should check as #{normalization} but does not on line #{test[:line]}"}
+ @@tests.each do |t|
+ test = t
actual = test[source].unicode_normalized?(normalization)
- if @@debug
- assert_equal true, actual,
- "#{to_codepoints(test[source])} should check as #{normalization} but does not on line #{test[:line]}"
- else
- assert_equal true, actual
- end
+ assert_equal true, actual, mesg
end
end
end
@@ -103,15 +97,13 @@ class TestNormalize < Test::Unit::TestCase
def self.generate_test_check_false(source, compare, normalization)
define_method "test_check_false_#{source}_as_#{normalization}" do
- @@tests.each do |test|
+ test = nil
+ mesg = proc {"#{to_codepoints(test[source])} should not check as #{normalization} but does on line #{test[:line]}"}
+ @@tests.each do |t|
+ test = t
if test[source] != test[compare]
actual = test[source].unicode_normalized?(normalization)
- if @@debug
- assert_equal false, actual,
- "#{to_codepoints(test[source])} should not check as #{normalization} but does on line #{test[:line]}"
- else
- assert_equal false, actual
- end
+ assert_equal false, actual, mesg
end
end
end