test/test-unicode_normalize.rb: Removed explicit require, changed method names, adjusted copyright.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
duerst 2014-10-22 09:06:49 +00:00
Родитель 15bfe2793a
Коммит 30b837b47c
2 изменённых файлов: 21 добавлений и 19 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Wed Oct 22 18:07:07 2014 Martin Duerst <duerst@it.aoyama.ac.jp>
* test/test-unicode_normalize.rb: Removed explicit require,
changed method names, adjusted copyright.
Wed Oct 22 18:00:00 2014 Martin Duerst <duerst@it.aoyama.ac.jp> Wed Oct 22 18:00:00 2014 Martin Duerst <duerst@it.aoyama.ac.jp>
* test/test-unicode_normalize.rb: Importing from * test/test-unicode_normalize.rb: Importing from

Просмотреть файл

@ -1,12 +1,9 @@
# coding: utf-8 # coding: utf-8
# Copyright 2010-2013 Ayumu Nojima (野島 歩) and Martin J. Dürst (duerst@it.aoyama.ac.jp) # Copyright Ayumu Nojima (野島 歩) and Martin J. Dürst (duerst@it.aoyama.ac.jp)
# available under the same licence as Ruby itself
# (see http://www.ruby-lang.org/en/LICENSE.txt)
Encoding.default_external = 'utf-8' Encoding.default_external = 'utf-8'
Encoding.default_internal = 'utf-8' Encoding.default_internal = 'utf-8'
require '../lib/string_normalize'
require 'test/unit' require 'test/unit'
NormTest = Struct.new :source, :NFC, :NFD, :NFKC, :NFKD, :line NormTest = Struct.new :source, :NFC, :NFD, :NFKC, :NFKD, :line
@ -25,7 +22,7 @@ class TestNormalize < Test::Unit::TestCase
end end
end end
def to_codepoints(string) # this could be defined as a refinement on String def to_codepoints(string)
string.codepoints.collect { |cp| cp.to_s(16).upcase.rjust(4, '0') } string.codepoints.collect { |cp| cp.to_s(16).upcase.rjust(4, '0') }
end end
@ -38,7 +35,7 @@ class TestNormalize < Test::Unit::TestCase
@@tests.each do |test| @@tests.each do |test|
if not prechecked or test[source]==test[prechecked] if not prechecked or test[source]==test[prechecked]
expected = test[target] expected = test[target]
actual = test[source].normalize(normalization) actual = test[source].unicode_normalize(normalization)
if @@debug if @@debug
assert_equal expected, actual, assert_equal expected, actual,
"#{to_codepoints(expected)} expected but was #{to_codepoints(actual)} on line #{test[:line]} (#{normalization})" "#{to_codepoints(expected)} expected but was #{to_codepoints(actual)} on line #{test[:line]} (#{normalization})"
@ -88,7 +85,7 @@ class TestNormalize < Test::Unit::TestCase
def self.generate_test_check_true(source, normalization) def self.generate_test_check_true(source, normalization)
define_method "test_check_true_#{source}_as_#{normalization}" do define_method "test_check_true_#{source}_as_#{normalization}" do
@@tests.each do |test| @@tests.each do |test|
actual = test[source].normalized?(normalization) actual = test[source].unicode_normalized?(normalization)
if @@debug if @@debug
assert_equal true, actual, assert_equal true, actual,
"#{to_codepoints(test[source])} should check as #{normalization} but does not on line #{test[:line]}" "#{to_codepoints(test[source])} should check as #{normalization} but does not on line #{test[:line]}"
@ -101,7 +98,7 @@ class TestNormalize < Test::Unit::TestCase
def one_false_check_test(test, compare_column, check_column, test_form, line) def one_false_check_test(test, compare_column, check_column, test_form, line)
if test[check_column- 1] != test[compare_column- 1] if test[check_column- 1] != test[compare_column- 1]
actual = test[check_column- 1].normalized?(test_form) actual = test[check_column- 1].unicode_normalized?(test_form)
assert_equal false, actual, "failed on line #{line+1} (#{test_form})" assert_equal false, actual, "failed on line #{line+1} (#{test_form})"
end end
end end
@ -110,7 +107,7 @@ class TestNormalize < Test::Unit::TestCase
define_method "test_check_false_#{source}_as_#{normalization}" do define_method "test_check_false_#{source}_as_#{normalization}" do
@@tests.each do |test| @@tests.each do |test|
if test[source] != test[compare] if test[source] != test[compare]
actual = test[source].normalized?(normalization) actual = test[source].unicode_normalized?(normalization)
if @@debug if @@debug
assert_equal false, actual, assert_equal false, actual,
"#{to_codepoints(test[source])} should not check as #{normalization} but does on line #{test[:line]}" "#{to_codepoints(test[source])} should not check as #{normalization} but does on line #{test[:line]}"
@ -145,27 +142,27 @@ class TestNormalize < Test::Unit::TestCase
generate_test_check_false :NFKD, :NFKC, :nfkc generate_test_check_false :NFKD, :NFKC, :nfkc
def test_non_UTF_8 def test_non_UTF_8
assert_equal "\u1E0A".encode('UTF-16BE'), "D\u0307".encode('UTF-16BE').normalize(:nfc) assert_equal "\u1E0A".encode('UTF-16BE'), "D\u0307".encode('UTF-16BE').unicode_normalize(:nfc)
assert_equal true, "\u1E0A".encode('UTF-16BE').normalized?(:nfc) assert_equal true, "\u1E0A".encode('UTF-16BE').unicode_normalized?(:nfc)
assert_equal false, "D\u0307".encode('UTF-16BE').normalized?(:nfc) assert_equal false, "D\u0307".encode('UTF-16BE').unicode_normalized?(:nfc)
end end
def test_singleton_with_accents def test_singleton_with_accents
assert_equal "\u0136", "\u212A\u0327".normalize(:nfc) assert_equal "\u0136", "\u212A\u0327".unicode_normalize(:nfc)
end end
def test_partial_jamo_compose def test_partial_jamo_compose
assert_equal "\uAC01", "\uAC00\u11A8".normalize(:nfc) assert_equal "\uAC01", "\uAC00\u11A8".unicode_normalize(:nfc)
end end
def test_partial_jamo_decompose def test_partial_jamo_decompose
assert_equal "\u1100\u1161\u11A8", "\uAC00\u11A8".normalize(:nfd) assert_equal "\u1100\u1161\u11A8", "\uAC00\u11A8".unicode_normalize(:nfd)
end end
def test_hangul_plus_accents def test_hangul_plus_accents
assert_equal "\uAC00\u0323\u0300", "\uAC00\u0300\u0323".normalize(:nfc) assert_equal "\uAC00\u0323\u0300", "\uAC00\u0300\u0323".unicode_normalize(:nfc)
assert_equal "\uAC00\u0323\u0300", "\u1100\u1161\u0300\u0323".normalize(:nfc) assert_equal "\uAC00\u0323\u0300", "\u1100\u1161\u0300\u0323".unicode_normalize(:nfc)
assert_equal "\u1100\u1161\u0323\u0300", "\uAC00\u0300\u0323".normalize(:nfd) assert_equal "\u1100\u1161\u0323\u0300", "\uAC00\u0300\u0323".unicode_normalize(:nfd)
assert_equal "\u1100\u1161\u0323\u0300", "\u1100\u1161\u0300\u0323".normalize(:nfd) assert_equal "\u1100\u1161\u0323\u0300", "\u1100\u1161\u0300\u0323".unicode_normalize(:nfd)
end end
end end