mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
test/ruby/test_string.rb: add tests to chomp substr
* test/ruby/test_string.rb (TestString#test_chomp): add tests to chomp substr * test/ruby/test_string.rb (TestString#test_chomp!): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
10082360b9
commit
0d03650599
1 changed files with 72 additions and 0 deletions
|
@ -383,6 +383,42 @@ CODE
|
|||
$/ = save
|
||||
|
||||
assert_equal(S("a").hash, S("a\u0101").chomp(S("\u0101")).hash, '[ruby-core:22414]')
|
||||
|
||||
s = S("hello")
|
||||
assert_equal("hel", s.chomp('lo'))
|
||||
assert_equal("hello", s)
|
||||
|
||||
s = S("hello")
|
||||
assert_equal("hello", s.chomp('he'))
|
||||
assert_equal("hello", s)
|
||||
|
||||
s = S("\u{3053 3093 306b 3061 306f}")
|
||||
assert_equal("\u{3053 3093 306b}", s.chomp("\u{3061 306f}"))
|
||||
assert_equal("\u{3053 3093 306b 3061 306f}", s)
|
||||
|
||||
s = S("\u{3053 3093 306b 3061 306f}")
|
||||
assert_equal("\u{3053 3093 306b 3061 306f}", s.chomp('lo'))
|
||||
assert_equal("\u{3053 3093 306b 3061 306f}", s)
|
||||
|
||||
s = S("hello")
|
||||
assert_equal("hello", s.chomp("\u{3061 306f}"))
|
||||
assert_equal("hello", s)
|
||||
|
||||
# skip if argument is a broken string
|
||||
s = S("\xe3\x81\x82")
|
||||
assert_equal("\xe3\x81\x82", s.chomp("\x82"))
|
||||
assert_equal("\xe3\x81\x82", s)
|
||||
|
||||
# clear coderange
|
||||
s = S("hello\u{3053 3093}")
|
||||
assert_not_predicate(s, :ascii_only?)
|
||||
assert_predicate(s.chomp("\u{3053 3093}"), :ascii_only?)
|
||||
|
||||
# argument should be converted to String
|
||||
klass = Class.new {|klass| def to_str; 'a'; end }
|
||||
s = S("abba")
|
||||
assert_equal("abb", s.chomp(klass.new))
|
||||
assert_equal("abba", s)
|
||||
ensure
|
||||
$/ = save
|
||||
end
|
||||
|
@ -452,6 +488,42 @@ CODE
|
|||
"x"
|
||||
end
|
||||
assert_raise_with_message(RuntimeError, /frozen/) {s.chomp!(o)}
|
||||
|
||||
s = S("hello")
|
||||
assert_equal("hel", s.chomp!('lo'))
|
||||
assert_equal("hel", s)
|
||||
|
||||
s = S("hello")
|
||||
assert_equal(nil, s.chomp!('he'))
|
||||
assert_equal("hello", s)
|
||||
|
||||
s = S("\u{3053 3093 306b 3061 306f}")
|
||||
assert_equal("\u{3053 3093 306b}", s.chomp!("\u{3061 306f}"))
|
||||
assert_equal("\u{3053 3093 306b}", s)
|
||||
|
||||
s = S("\u{3053 3093 306b 3061 306f}")
|
||||
assert_equal(nil, s.chomp!('lo'))
|
||||
assert_equal("\u{3053 3093 306b 3061 306f}", s)
|
||||
|
||||
s = S("hello")
|
||||
assert_equal(nil, s.chomp!("\u{3061 306f}"))
|
||||
assert_equal("hello", s)
|
||||
|
||||
# skip if argument is a broken string
|
||||
s = S("\xe3\x81\x82")
|
||||
assert_equal(nil, s.chomp!("\x82"))
|
||||
assert_equal("\xe3\x81\x82", s)
|
||||
|
||||
# clear coderange
|
||||
s = S("hello\u{3053 3093}")
|
||||
assert_not_predicate(s, :ascii_only?)
|
||||
assert_predicate(s.chomp!("\u{3053 3093}"), :ascii_only?)
|
||||
|
||||
# argument should be converted to String
|
||||
klass = Class.new {|klass| def to_str; 'a'; end }
|
||||
s = S("abba")
|
||||
assert_equal("abb", s.chomp!(klass.new))
|
||||
assert_equal("abb", s)
|
||||
ensure
|
||||
$/ = save
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue