1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

tests refined.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15264 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-01-27 02:38:10 +00:00
parent 4ccb160103
commit 3f68c10536

View file

@ -232,13 +232,30 @@ class TestM17NComb < Test::Unit::TestCase
} }
end end
ASCII_INCOMPATIBLE_ENCODINGS = %w[
UTF-16BE
UTF-16LE
UTF-32BE
UTF-32LE
]
def str_enc_compatible?(*strs) def str_enc_compatible?(*strs)
encs = [] encs = []
ascii_incompatible_encodings = {}
has_ascii_compatible = false
strs.each {|s| strs.each {|s|
encs << s.encoding if !s.ascii_only? encs << s.encoding if !s.ascii_only?
if /\A#{Regexp.union ASCII_INCOMPATIBLE_ENCODINGS}\z/o =~ s.encoding.name
ascii_incompatible_encodings[s.encoding] = true
else
has_ascii_compatible = true
end
} }
encs.uniq! if ascii_incompatible_encodings.empty?
encs.length <= 1 encs.uniq!
encs.length <= 1
else
!has_ascii_compatible && ascii_incompatible_encodings.size == 1
end
end end
# tests start # tests start
@ -342,9 +359,8 @@ class TestM17NComb < Test::Unit::TestCase
end end
def test_str_aref def test_str_aref
STRINGS.each {|s| STRINGS.each {|s|
t = '' t = ''.force_encoding(s.encoding)
0.upto(s.length-1) {|i| 0.upto(s.length-1) {|i|
u = s[i] u = s[i]
assert(u.valid_encoding?) if s.valid_encoding? assert(u.valid_encoding?) if s.valid_encoding?
@ -352,13 +368,11 @@ class TestM17NComb < Test::Unit::TestCase
} }
assert_equal(t, s) assert_equal(t, s)
} }
end end
def test_str_aref_len def test_str_aref_len
STRINGS.each {|s| STRINGS.each {|s|
t = '' t = ''.force_encoding(s.encoding)
0.upto(s.length-1) {|i| 0.upto(s.length-1) {|i|
u = s[i,1] u = s[i,1]
assert(u.valid_encoding?) if s.valid_encoding? assert(u.valid_encoding?) if s.valid_encoding?
@ -368,7 +382,7 @@ class TestM17NComb < Test::Unit::TestCase
} }
STRINGS.each {|s| STRINGS.each {|s|
t = '' t = ''.force_encoding(s.encoding)
0.step(s.length-1, 2) {|i| 0.step(s.length-1, 2) {|i|
u = s[i,2] u = s[i,2]
assert(u.valid_encoding?) if s.valid_encoding? assert(u.valid_encoding?) if s.valid_encoding?
@ -1528,14 +1542,14 @@ class TestM17NComb < Test::Unit::TestCase
next next
end end
if s1.length < s2.length if s1.length < s2.length
assert_equal(false, s1.end_with?(s2), desc) assert_equal(false, enccall(s1, :end_with?, s2), desc)
next next
end end
if s1[s1.length-s2.length, s2.length] == s2 if s1[s1.length-s2.length, s2.length] == s2
assert_equal(true, s1.end_with?(s2), desc) assert_equal(true, enccall(s1, :end_with?, s2), desc)
next next
end end
assert_equal(false, s1.end_with?(s2), desc) assert_equal(false, enccall(s1, :end_with?, s2), desc)
} }
end end
@ -1547,14 +1561,14 @@ class TestM17NComb < Test::Unit::TestCase
next next
end end
if s1.length < s2.length if s1.length < s2.length
assert_equal(false, s1.start_with?(s2), desc) assert_equal(false, enccall(s1, :start_with?, s2), desc)
next next
end end
if s1[0, s2.length] == s2 if s1[0, s2.length] == s2
assert_equal(true, s1.start_with?(s2), desc) assert_equal(true, enccall(s1, :start_with?, s2), desc)
next next
end end
assert_equal(false, s1.start_with?(s2), desc) assert_equal(false, enccall(s1, :start_with?, s2), desc)
} }
end end
@ -1579,7 +1593,7 @@ class TestM17NComb < Test::Unit::TestCase
assert_raise(ArgumentError, desc) { s1.partition(s2) } assert_raise(ArgumentError, desc) { s1.partition(s2) }
next next
end end
i = s1.index(s2) i = enccall(s1, :index, s2)
if !i if !i
assert_equal([s1, "", ""], s1.partition(s2), desc) assert_equal([s1, "", ""], s1.partition(s2), desc)
next next
@ -1595,7 +1609,7 @@ class TestM17NComb < Test::Unit::TestCase
assert_raise(ArgumentError, desc) { s1.rpartition(s2) } assert_raise(ArgumentError, desc) { s1.rpartition(s2) }
next next
end end
i = s1.rindex(s2) i = enccall(s1, :rindex, s2)
if !i if !i
assert_equal(["", "", s1], s1.rpartition(s2), desc) assert_equal(["", "", s1], s1.rpartition(s2), desc)
next next