diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | enc/unicode.c | 8 | ||||
-rw-r--r-- | test/ruby/enc/test_case_mapping.rb | 55 |
3 files changed, 53 insertions, 16 deletions
@@ -1,3 +1,9 @@ +Sun Jan 17 20:10:10 2016 Martin Duerst <duerst@it.aoyama.ac.jp> + + * enc/unicode.c: Fixed a logical error and some comments. + * test/ruby/enc/test_case_mapping.rb: Made tests more general. + (with Kimihito Matsui) + Sun Jan 17 17:41:41 2016 Martin Duerst <duerst@it.aoyama.ac.jp> * enc/unicode.c: Removed artificial expansion for Turkic, diff --git a/enc/unicode.c b/enc/unicode.c index 9fd3fe10ba..086fe14494 100644 --- a/enc/unicode.c +++ b/enc/unicode.c @@ -643,10 +643,10 @@ onigenc_unicode_case_map(OnigCaseFoldType* flagP, } } else if (code>=0x00C0) { /* deal with non-ASCII; nothing relevant below U+00C0 */ - if (code==0x0130) { /* I WITH DOT ABOVE -> i */ - if (flags&ONIGENC_CASE_UPCASE) { + if (code==0x0130) { + if (flags&ONIGENC_CASE_DOWNCASE) { if (flags&ONIGENC_CASE_FOLD_TURKISH_AZERI) - code = 0x0069; + code = 0x0069; /* I WITH DOT ABOVE -> i */ else { /* make dot above explicit */ to += ONIGENC_CODE_TO_MBC(enc, 0x0069, to); code = 0x0307; /* dot above */ @@ -656,7 +656,7 @@ onigenc_unicode_case_map(OnigCaseFoldType* flagP, } /* the following case can be removed once we rely on data, * because the mapping is always the same */ - else if (code==0x0131 && flags&ONIGENC_CASE_UPCASE) { /* DOTLESS i -> I */ + else if (code==0x0131 && (flags&ONIGENC_CASE_UPCASE)) { /* DOTLESS i -> I */ code = 0x0049; MODIFIED; } } diff --git a/test/ruby/enc/test_case_mapping.rb b/test/ruby/enc/test_case_mapping.rb index eb36d7d665..6191883637 100644 --- a/test/ruby/enc/test_case_mapping.rb +++ b/test/ruby/enc/test_case_mapping.rb @@ -5,22 +5,53 @@ require "test/unit" # preliminary tests, using :lithuanian as a guard # to test new implementation strategy class TestCaseMappingPreliminary < Test::Unit::TestCase + # checks, including idempotence and non-modification; not always guaranteed + def check_upcase_properties(expected, start, *flags) + assert_equal expected, start.upcase(*flags) + temp = start + assert_equal expected, temp.upcase!(*flags) + assert_equal expected, expected.upcase(*flags) + temp = expected + assert_nil temp.upcase!(*flags) + end + + def check_downcase_properties(expected, start, *flags) + assert_equal expected, start.downcase(*flags) + temp = start + assert_equal expected, temp.downcase!(*flags) + assert_equal expected, expected.downcase(*flags) + temp = expected + assert_nil temp.downcase!(*flags) + end + + def check_capitalize_properties(expected, start, *flags) + assert_equal expected, start.capitalize(*flags) + temp = start + assert_equal expected, temp.capitalize!(*flags) + assert_equal expected, expected.capitalize(*flags) + temp = expected + assert_nil temp.capitalize!(*flags) + end + + # 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 + def test_ascii - assert_equal 'yukihiro matsumoto (matz)', - 'Yukihiro MATSUMOTO (MATZ)'.downcase(:lithuanian) - assert_equal 'YUKIHIRO MATSUMOTO (MATZ)', - 'yukihiro matsumoto (matz)'.upcase(:lithuanian) - assert_equal 'Yukihiro matsumoto (matz)', - 'yukihiro MATSUMOTO (MATZ)'.capitalize(:lithuanian) - assert_equal 'yUKIHIRO matsumoto (MAtz)', - 'Yukihiro MATSUMOTO (maTZ)'.swapcase(:lithuanian) + 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 end def test_turcic - assert_equal 'yukihiro matsumoto (matz)', - 'Yukihiro MATSUMOTO (MATZ)'.downcase(:turkic, :lithuanian) - assert_equal 'YUKİHİRO MATSUMOTO (MATZ)', - 'Yukihiro Matsumoto (matz)'.upcase(:turkic, :lithuanian) + check_downcase_properties 'yukihiro matsumoto (matz)', 'Yukihiro MATSUMOTO (MATZ)', :turkic, :lithuanian + check_upcase_properties 'YUKİHİRO MATSUMOTO (MATZ)', 'Yukihiro Matsumoto (matz)', :turkic, :lithuanian end def no_longer_a_test_buffer_allocations |