summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-18 06:46:52 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-18 06:46:52 +0000
commit60abbb7ad77bd723afef16439e6fbf9f9967c947 (patch)
tree3a8cbe09a83728faa65c74a6ad12af5b66004bf0 /test
parent168b9e13ff4192d850bc2f46cf6debd6849a96a8 (diff)
more tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14292 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_m17n.rb103
1 files changed, 103 insertions, 0 deletions
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb
index cf9df11b8c..dedbaf5ec5 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