summaryrefslogtreecommitdiff
path: root/test/ruby/test_string.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-03 02:08:55 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-03 02:08:55 +0000
commitadac7792180d678d7ca47a9aa523efff2b1ed4c3 (patch)
tree7ec342a5ed73db3f23fe80d45773ae615591d5d7 /test/ruby/test_string.rb
parent71de56621ec4643bdfee102f56a153260bb97998 (diff)
string.c: enumerator_wantarray
* string.c (enumerator_wantarray): show warnings at method functions for proper method names. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_string.rb')
-rw-r--r--test/ruby/test_string.rb39
1 files changed, 35 insertions, 4 deletions
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index eab0c7cdd8..f662a83c12 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -807,13 +807,20 @@ CODE
assert_equal [65, 66, 67], s.bytes {}
}
else
- assert_warning(/deprecated/) {
+ warning = /passing a block to String#bytes is deprecated/
+ assert_warning(warning) {
res = []
assert_equal s.object_id, s.bytes {|x| res << x }.object_id
assert_equal(65, res[0])
assert_equal(66, res[1])
assert_equal(67, res[2])
}
+ assert_warning(warning) {
+ s = S("ABC")
+ res = []
+ assert_same s, s.bytes {|x| res << x }
+ assert_equal [65, 66, 67], res
+ }
end
end
@@ -844,13 +851,20 @@ CODE
assert_equal [0x3042, 0x3044, 0x3046], s.codepoints {}
}
else
- assert_warning(/deprecated/) {
+ warning = /passing a block to String#codepoints is deprecated/
+ assert_warning(warning) {
res = []
assert_equal s.object_id, s.codepoints {|x| res << x }.object_id
assert_equal(0x3042, res[0])
assert_equal(0x3044, res[1])
assert_equal(0x3046, res[2])
}
+ assert_warning(warning) {
+ s = S("ABC")
+ res = []
+ assert_same s, s.codepoints {|x| res << x }
+ assert_equal [65, 66, 67], res
+ }
end
end
@@ -875,7 +889,8 @@ CODE
assert_equal ["A", "B", "C"], s.chars {}
}
else
- assert_warning(/deprecated/) {
+ warning = /passing a block to String#chars is deprecated/
+ assert_warning(warning) {
res = []
assert_equal s.object_id, s.chars {|x| res << x }.object_id
assert_equal("A", res[0])
@@ -925,6 +940,22 @@ CODE
assert_equal ["\u000A", "\u0308"], "\u{a 308}".grapheme_clusters
assert_equal ["\u000D", "\u0308"], "\u{d 308}".grapheme_clusters
assert_equal ["a", "b", "c"], "abc".b.grapheme_clusters
+
+ if ENUMERATOR_WANTARRAY
+ assert_warn(/block not used/) {
+ assert_equal ["A", "B", "C"], "ABC".grapheme_clusters {}
+ }
+ else
+ warning = /passing a block to String#grapheme_clusters is deprecated/
+ assert_warning(warning) {
+ s = "ABC".b
+ res = []
+ assert_same s, s.grapheme_clusters {|x| res << x }
+ assert_equal("A", res[0])
+ assert_equal("B", res[1])
+ assert_equal("C", res[2])
+ }
+ end
end
def test_each_line
@@ -1032,7 +1063,7 @@ CODE
assert_equal ["hello\n", "world"], s.lines {}
}
else
- assert_warning(/deprecated/) {
+ assert_warning(/passing a block to String#lines is deprecated/) {
res = []
assert_equal s.object_id, s.lines {|x| res << x }.object_id
assert_equal(S("hello\n"), res[0])