summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorduerst <duerst@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-17 11:10:45 +0000
committerduerst <duerst@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-17 11:10:45 +0000
commitf307d1fe21371ee27436da79d240ad9ade285257 (patch)
treea0ce6d1776115ac0d8eaa7c1fdbb37dc3df7c595 /test
parent39f44f0113d3051f7d589414d0877d8dfda669b8 (diff)
* enc/unicode.c: Fixed a logical error and some comments.
* test/ruby/enc/test_case_mapping.rb: Made tests more general. (with Kimihito Matsui) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53564 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/enc/test_case_mapping.rb55
1 files changed, 43 insertions, 12 deletions
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