string.c: remove the deprecation warnings of String#bytes with block

And its friends: lines, chars, grapheme_clusters, and codepoints.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2018-12-26 08:52:19 +00:00
parent 35b7af7503
commit 2b21744efa
2 changed files with 36 additions and 71 deletions

View File

@ -42,8 +42,6 @@
# define HAVE_CRYPT_R 1 # define HAVE_CRYPT_R 1
#endif #endif
#define STRING_ENUMERATORS_WANTARRAY 0 /* next major */
#undef rb_str_new #undef rb_str_new
#undef rb_usascii_str_new #undef rb_usascii_str_new
#undef rb_utf8_str_new #undef rb_utf8_str_new
@ -7956,22 +7954,7 @@ rb_str_split(VALUE str, const char *sep0)
return rb_str_split_m(1, &sep, str); return rb_str_split_m(1, &sep, str);
} }
static int #define WANTARRAY(m, size) (!rb_block_given_p() ? rb_ary_new_capa(size) : 0)
enumerator_wantarray(const char *method)
{
if (rb_block_given_p()) {
#if STRING_ENUMERATORS_WANTARRAY
rb_warn("given block not used");
#else
rb_warning("passing a block to String#%s is deprecated", method);
return 0;
#endif
}
return 1;
}
#define WANTARRAY(m, size) \
(enumerator_wantarray(m) ? rb_ary_new_capa(size) : 0)
static inline int static inline int
enumerator_element(VALUE ary, VALUE e) enumerator_element(VALUE ary, VALUE e)

View File

@ -878,20 +878,15 @@ CODE
assert_equal [65, 66, 67], s.bytes {} assert_equal [65, 66, 67], s.bytes {}
} }
else else
warning = /passing a block to String#bytes is deprecated/ res = []
assert_warning(warning) { assert_equal s.object_id, s.bytes {|x| res << x }.object_id
res = [] assert_equal(65, res[0])
assert_equal s.object_id, s.bytes {|x| res << x }.object_id assert_equal(66, res[1])
assert_equal(65, res[0]) assert_equal(67, res[2])
assert_equal(66, res[1]) s = S("ABC")
assert_equal(67, res[2]) res = []
} assert_same s, s.bytes {|x| res << x }
assert_warning(warning) { assert_equal [65, 66, 67], res
s = S("ABC")
res = []
assert_same s, s.bytes {|x| res << x }
assert_equal [65, 66, 67], res
}
end end
end end
@ -922,20 +917,15 @@ CODE
assert_equal [0x3042, 0x3044, 0x3046], s.codepoints {} assert_equal [0x3042, 0x3044, 0x3046], s.codepoints {}
} }
else else
warning = /passing a block to String#codepoints is deprecated/ res = []
assert_warning(warning) { assert_equal s.object_id, s.codepoints {|x| res << x }.object_id
res = [] assert_equal(0x3042, res[0])
assert_equal s.object_id, s.codepoints {|x| res << x }.object_id assert_equal(0x3044, res[1])
assert_equal(0x3042, res[0]) assert_equal(0x3046, res[2])
assert_equal(0x3044, res[1]) s = S("ABC")
assert_equal(0x3046, res[2]) res = []
} assert_same s, s.codepoints {|x| res << x }
assert_warning(warning) { assert_equal [65, 66, 67], res
s = S("ABC")
res = []
assert_same s, s.codepoints {|x| res << x }
assert_equal [65, 66, 67], res
}
end end
end end
@ -960,14 +950,11 @@ CODE
assert_equal ["A", "B", "C"], s.chars {} assert_equal ["A", "B", "C"], s.chars {}
} }
else else
warning = /passing a block to String#chars is deprecated/ res = []
assert_warning(warning) { assert_equal s.object_id, s.chars {|x| res << x }.object_id
res = [] assert_equal("A", res[0])
assert_equal s.object_id, s.chars {|x| res << x }.object_id assert_equal("B", res[1])
assert_equal("A", res[0]) assert_equal("C", res[2])
assert_equal("B", res[1])
assert_equal("C", res[2])
}
end end
end end
@ -1032,17 +1019,14 @@ CODE
assert_equal ["A", "B", "C"], "ABC".grapheme_clusters {} assert_equal ["A", "B", "C"], "ABC".grapheme_clusters {}
} }
else else
warning = /passing a block to String#grapheme_clusters is deprecated/ s = "ABC".b.taint
assert_warning(warning) { res = []
s = "ABC".b.taint assert_same s, s.grapheme_clusters {|x| res << x }
res = [] assert_equal(3, res.size)
assert_same s, s.grapheme_clusters {|x| res << x } assert_equal("A", res[0])
assert_equal(3, res.size) assert_equal("B", res[1])
assert_equal("A", res[0]) assert_equal("C", res[2])
assert_equal("B", res[1]) res.each {|g| assert_predicate(g, :tainted?)}
assert_equal("C", res[2])
res.each {|g| assert_predicate(g, :tainted?)}
}
end end
end end
@ -1155,12 +1139,10 @@ CODE
assert_equal ["hello\n", "world"], s.lines {} assert_equal ["hello\n", "world"], s.lines {}
} }
else else
assert_warning(/passing a block to String#lines is deprecated/) { res = []
res = [] assert_equal s.object_id, s.lines {|x| res << x }.object_id
assert_equal s.object_id, s.lines {|x| res << x }.object_id assert_equal(S("hello\n"), res[0])
assert_equal(S("hello\n"), res[0]) assert_equal(S("world"), res[1])
assert_equal(S("world"), res[1])
}
end end
end end