2016-01-15 20:24:03 -05:00
|
|
|
|
# Copyright © 2016 Kimihito Matsui (松井 仁人) and Martin J. Dürst (duerst@it.aoyama.ac.jp)
|
|
|
|
|
|
|
|
|
|
require "test/unit"
|
|
|
|
|
|
|
|
|
|
# preliminary tests, using :lithuanian as a guard
|
|
|
|
|
# to test new implementation strategy
|
|
|
|
|
class TestCaseMappingPreliminary < Test::Unit::TestCase
|
2016-01-17 06:10:45 -05:00
|
|
|
|
# checks, including idempotence and non-modification; not always guaranteed
|
|
|
|
|
def check_upcase_properties(expected, start, *flags)
|
|
|
|
|
assert_equal expected, start.upcase(*flags)
|
2016-03-16 02:44:05 -04:00
|
|
|
|
temp = start.dup
|
2016-01-17 06:10:45 -05:00
|
|
|
|
assert_equal expected, temp.upcase!(*flags)
|
|
|
|
|
assert_equal expected, expected.upcase(*flags)
|
2016-03-16 02:44:05 -04:00
|
|
|
|
temp = expected.dup
|
2016-01-17 06:10:45 -05:00
|
|
|
|
assert_nil temp.upcase!(*flags)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def check_downcase_properties(expected, start, *flags)
|
|
|
|
|
assert_equal expected, start.downcase(*flags)
|
2016-03-16 02:44:05 -04:00
|
|
|
|
temp = start.dup
|
2016-01-17 06:10:45 -05:00
|
|
|
|
assert_equal expected, temp.downcase!(*flags)
|
|
|
|
|
assert_equal expected, expected.downcase(*flags)
|
2016-03-16 02:44:05 -04:00
|
|
|
|
temp = expected.dup
|
2016-01-17 06:10:45 -05:00
|
|
|
|
assert_nil temp.downcase!(*flags)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def check_capitalize_properties(expected, start, *flags)
|
|
|
|
|
assert_equal expected, start.capitalize(*flags)
|
2016-03-16 02:44:05 -04:00
|
|
|
|
temp = start.dup
|
2016-01-17 06:10:45 -05:00
|
|
|
|
assert_equal expected, temp.capitalize!(*flags)
|
|
|
|
|
assert_equal expected, expected.capitalize(*flags)
|
2016-03-16 02:44:05 -04:00
|
|
|
|
temp = expected.dup
|
2016-01-17 06:10:45 -05:00
|
|
|
|
assert_nil temp.capitalize!(*flags)
|
|
|
|
|
end
|
|
|
|
|
|
2016-03-16 02:44:05 -04:00
|
|
|
|
def check_capitalize_suffixes(lower, upper)
|
|
|
|
|
while not upper.length > 1
|
|
|
|
|
lower = lower[1..-1]
|
|
|
|
|
check_capitalize_properties upper[0]+lower, upper, :lithuanian
|
|
|
|
|
upper = upper[1..-1]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-01-17 06:10:45 -05:00
|
|
|
|
# different properties; careful: roundtrip isn't always guaranteed
|
|
|
|
|
def check_swapcase_properties(expected, start, *flags)
|
|
|
|
|
assert_equal expected, start.swapcase(*flags)
|
|
|
|
|
temp = start
|
|
|
|
|
assert_equal expected, temp.swapcase!(*flags)
|
|
|
|
|
assert_equal start, start.swapcase(*flags).swapcase(*flags)
|
|
|
|
|
assert_equal expected, expected.swapcase(*flags).swapcase(*flags)
|
|
|
|
|
end
|
|
|
|
|
|
2016-01-17 03:42:16 -05:00
|
|
|
|
def test_ascii
|
2016-01-17 06:10:45 -05:00
|
|
|
|
check_downcase_properties 'yukihiro matsumoto (matz)', 'Yukihiro MATSUMOTO (MATZ)', :lithuanian
|
|
|
|
|
check_upcase_properties 'YUKIHIRO MATSUMOTO (MATZ)', 'yukihiro matsumoto (matz)', :lithuanian
|
|
|
|
|
check_capitalize_properties 'Yukihiro matsumoto (matz)', 'yukihiro MATSUMOTO (MATZ)', :lithuanian
|
|
|
|
|
check_swapcase_properties 'yUKIHIRO matsumoto (MAtz)', 'Yukihiro MATSUMOTO (maTZ)', :lithuanian
|
2016-01-16 03:24:58 -05:00
|
|
|
|
end
|
|
|
|
|
|
2016-03-16 02:44:05 -04:00
|
|
|
|
def test_general
|
|
|
|
|
check_downcase_properties 'résumé dürst ĭñŧėřŋãţijňőńæłĩżàťïōņ', 'RÉSUMÉ DÜRST ĬÑŦĖŘŊÃŢIJŇŐŃÆŁĨŻÀŤÏŌŅ', :lithuanian
|
|
|
|
|
check_upcase_properties 'RÉSUMÉ DÜRST ĬÑŦĖŘŊÃŢIJŇŐŃÆŁĨŻÀŤÏŌŅ', 'résumé dürst ĭñŧėřŋãţijňőńæłĩżàťïōņ', :lithuanian
|
|
|
|
|
check_capitalize_suffixes 'résumé dürst ĭñŧėřŋãţijňőńæłĩżàťïōņ', 'RÉSUMÉ DÜRST ĬÑŦĖŘŊÃŢIJŇŐŃÆŁĨŻÀŤÏŌŅ'
|
|
|
|
|
check_swapcase_properties 'résumé DÜRST ĭñŧėřŊÃŢIJŇŐŃæłĩżàťïōņ', 'RÉSUMÉ dürst ĬÑŦĖŘŋãţijňőńÆŁĨŻÀŤÏŌŅ', :lithuanian
|
|
|
|
|
end
|
|
|
|
|
|
2016-03-16 04:57:34 -04:00
|
|
|
|
def test_cherokee
|
|
|
|
|
check_downcase_properties "\uab70\uab71\uab72\uab73\uab74\uab75\uab76\uab77\uab78\uab79", 'ᎠᎡᎢᎣᎤᎥᎦᎧᎨᎩ', :lithuanian
|
|
|
|
|
check_upcase_properties 'ᎠᎡᎢᎣᎤᎥᎦᎧᎨᎩ', "\uab70\uab71\uab72\uab73\uab74\uab75\uab76\uab77\uab78\uab79", :lithuanian
|
|
|
|
|
check_capitalize_suffixes "\uab70\uab71\uab72\uab73\uab74\uab75\uab76\uab77\uab78\uab79", 'ᎠᎡᎢᎣᎤᎥᎦᎧᎨᎩ'
|
|
|
|
|
assert_equal 'ᎠᎡᎢᎣᎤᎥᎦᎧᎨᎩ', 'ᎠᎡᎢᎣᎤᎥᎦᎧᎨᎩ', :fold
|
|
|
|
|
#assert_equal 'ᎠᎡᎢᎣᎤᎥᎦᎧᎨᎩ', "\uab70\uab71\uab72\uab73\uab74\uab75\uab76\uab77\uab78\uab79", :fold
|
|
|
|
|
end
|
|
|
|
|
|
2016-02-05 06:09:07 -05:00
|
|
|
|
def test_ascii_option
|
|
|
|
|
check_downcase_properties 'yukihiro matsumoto (matz)', 'Yukihiro MATSUMOTO (MATZ)', :ascii
|
|
|
|
|
check_upcase_properties 'YUKIHIRO MATSUMOTO (MATZ)', 'yukihiro matsumoto (matz)', :ascii
|
|
|
|
|
check_capitalize_properties 'Yukihiro matsumoto (matz)', 'yukihiro MATSUMOTO (MATZ)', :ascii
|
|
|
|
|
check_swapcase_properties 'yUKIHIRO matsumoto (MAtz)', 'Yukihiro MATSUMOTO (maTZ)', :ascii
|
|
|
|
|
check_downcase_properties 'yukİhİro matsumoto (matz)', 'YUKİHİRO MATSUMOTO (MATZ)', :ascii
|
|
|
|
|
check_downcase_properties 'rÉsumÉ dÜrst ĬÑŦĖŘŊÃŢIJŇŐŃÆŁĨŻÀŤĬŌŅ', 'RÉSUMÉ DÜRST ĬÑŦĖŘŊÃŢIJŇŐŃÆŁĨŻÀŤĬŌŅ', :ascii
|
|
|
|
|
check_swapcase_properties 'rÉsumÉ dÜrst ĬÑŦĖŘŊÃŢIJŇŐŃÆŁĨŻÀŤĬŌŅ', 'RÉSUMÉ DÜRST ĬÑŦĖŘŊÃŢIJŇŐŃÆŁĨŻÀŤĬŌŅ', :ascii
|
|
|
|
|
end
|
|
|
|
|
|
2016-02-06 00:37:29 -05:00
|
|
|
|
def test_fold_option
|
|
|
|
|
check_downcase_properties 'ss', 'ß', :fold
|
|
|
|
|
check_downcase_properties 'fifl', 'fifl', :fold
|
|
|
|
|
check_downcase_properties 'σ', 'ς', :fold
|
2016-02-06 01:18:38 -05:00
|
|
|
|
check_downcase_properties 'μ', 'µ', :fold # MICRO SIGN -> Greek mu
|
2016-02-06 00:37:29 -05:00
|
|
|
|
end
|
|
|
|
|
|
2016-01-17 03:42:16 -05:00
|
|
|
|
def test_turcic
|
2016-01-17 06:40:46 -05:00
|
|
|
|
check_downcase_properties 'yukihiro matsumoto (matz)', 'Yukihiro MATSUMOTO (MATZ)', :turkic
|
|
|
|
|
check_upcase_properties 'YUKİHİRO MATSUMOTO (MATZ)', 'Yukihiro Matsumoto (matz)', :turkic
|
|
|
|
|
check_downcase_properties "yuki\u0307hi\u0307ro matsumoto (matz)", 'YUKİHİRO MATSUMOTO (MATZ)', :lithuanian
|
2016-01-17 03:42:16 -05:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def no_longer_a_test_buffer_allocations
|
2016-01-16 03:24:58 -05:00
|
|
|
|
assert_equal 'TURKISH*ı'*10, ('I'*10).downcase(:turkic, :lithuanian)
|
|
|
|
|
assert_equal 'TURKISH*ı'*100, ('I'*100).downcase(:turkic, :lithuanian)
|
|
|
|
|
assert_equal 'TURKISH*ı'*1_000, ('I'*1_000).downcase(:turkic, :lithuanian)
|
|
|
|
|
assert_equal 'TURKISH*ı'*10_000, ('I'*10_000).downcase(:turkic, :lithuanian)
|
|
|
|
|
assert_equal 'TURKISH*ı'*100_000, ('I'*100_000).downcase(:turkic, :lithuanian)
|
|
|
|
|
assert_equal 'TURKISH*ı'*1_000_000, ('I'*1_000_000).downcase(:turkic, :lithuanian)
|
2016-01-15 20:24:03 -05:00
|
|
|
|
end
|
|
|
|
|
end
|