diff options
| author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-18 06:46:52 +0000 |
|---|---|---|
| committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-18 06:46:52 +0000 |
| commit | 53babbaa7bd9c42cd738b2a40c32601e340f4cb3 (patch) | |
| tree | 3a8cbe09a83728faa65c74a6ad12af5b66004bf0 | |
| parent | e1e7d2264ba2f0dc658af1875270d741d46d311a (diff) | |
| download | ruby-53babbaa7bd9c42cd738b2a40c32601e340f4cb3.tar.gz ruby-53babbaa7bd9c42cd738b2a40c32601e340f4cb3.tar.xz ruby-53babbaa7bd9c42cd738b2a40c32601e340f4cb3.zip | |
more tests.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14292 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | test/ruby/test_m17n.rb | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb index cf9df11b8..dedbaf5ec 100644 --- a/test/ruby/test_m17n.rb +++ b/test/ruby/test_m17n.rb @@ -714,6 +714,109 @@ class TestM17N < Test::Unit::TestCase assert_equal(nil, u("\xc2\xa1\xc2\xa2\xc2\xa3")[u("\xa1\xc2")]) assert_raise(ArgumentError) { u("\xc2\xa1\xc2\xa2\xc2\xa3")[a("\xa1\xc2")] } + STRINGS.each {|s1| + STRINGS.each {|s2| + if is_ascii_only?(s1) || is_ascii_only?(s2) || s1.encoding == s2.encoding + t = s1[s2] + if t != nil + assert_equal(s2, t) + assert_match(/#{Regexp.escape(s2)}/, s1) + end + else + assert_raise(ArgumentError) { s1[s2] } + end + + } + } + end + + def test_str_aref_range2 + STRINGS.each {|s| + (-2).upto(2) {|first| + (-2).upto(2) {|last| + t = s[first..last] + if first < 0 + first += s.length + if first < 0 + assert_nil(t, "#{s.inspect}[#{first}..#{last}]") + next + end + end + if s.length < first + assert_nil(t, "#{s.inspect}[#{first}..#{last}]") + next + end + if last < 0 + last += s.length + end + t2 = '' + first.upto(last) {|i| + c = s[i] + t2 << c if c + } + assert_equal(t2, t, "#{s.inspect}[#{first}..#{last}]") + } + } + } + end + + def test_str_aref_range3 + STRINGS.each {|s| + (-2).upto(2) {|first| + (-2).upto(2) {|last| + t = s[first...last] + if first < 0 + first += s.length + if first < 0 + assert_nil(t, "#{s.inspect}[#{first}..#{last}]") + next + end + end + if s.length < first + assert_nil(t, "#{s.inspect}[#{first}..#{last}]") + next + end + if last < 0 + last += s.length + end + t2 = '' + first.upto(last-1) {|i| + c = s[i] + t2 << c if c + } + assert_equal(t2, t, "#{s.inspect}[#{first}..#{last}]") + } + } + } + end + + def encinsp(str) + "#{str.inspect}.force_encoding(#{str.encoding.name.inspect})" + end + + def test_str_assign + STRINGS.each {|s1| + STRINGS.each {|s2| + (-2).upto(2) {|i| + t = s1.dup + if is_ascii_only?(s1) || is_ascii_only?(s2) || s1.encoding == s2.encoding + if i < -s1.length || s1.length < i + assert_raise(IndexError) { t[i] = s2 } + else + t[i] = s2 + if i == s1.length && s2.empty? + assert_nil(t[i]) + else + assert_equal(s2, t[i], "t = #{encinsp(s1)}; t[#{i}] = #{encinsp(s2)}; t[#{i}]") + end + end + else + assert_raise(ArgumentError) { t[i] = s2 } + end + + } + } + } end def test_tr |
