The deprecation of enumerators with block has been withdrawn
https://bugs.ruby-lang.org/issues/6670#change-75907
This commit is contained in:
parent
0eec4ae851
commit
eb9342d348
@ -2,8 +2,6 @@
|
||||
require 'test/unit'
|
||||
|
||||
class TestString < Test::Unit::TestCase
|
||||
ENUMERATOR_WANTARRAY = RUBY_VERSION >= "3.0.0"
|
||||
|
||||
WIDE_ENCODINGS = [
|
||||
Encoding::UTF_16BE, Encoding::UTF_16LE,
|
||||
Encoding::UTF_32BE, Encoding::UTF_32LE,
|
||||
@ -915,11 +913,6 @@ CODE
|
||||
s = S("ABC")
|
||||
assert_equal [65, 66, 67], s.bytes
|
||||
|
||||
if ENUMERATOR_WANTARRAY
|
||||
assert_warn(/block not used/) {
|
||||
assert_equal [65, 66, 67], s.bytes {}
|
||||
}
|
||||
else
|
||||
res = []
|
||||
assert_equal s.object_id, s.bytes {|x| res << x }.object_id
|
||||
assert_equal(65, res[0])
|
||||
@ -930,7 +923,6 @@ CODE
|
||||
assert_same s, s.bytes {|x| res << x }
|
||||
assert_equal [65, 66, 67], res
|
||||
end
|
||||
end
|
||||
|
||||
def test_each_codepoint
|
||||
# Single byte optimization
|
||||
@ -954,11 +946,6 @@ CODE
|
||||
s = S("\u3042\u3044\u3046")
|
||||
assert_equal [0x3042, 0x3044, 0x3046], s.codepoints
|
||||
|
||||
if ENUMERATOR_WANTARRAY
|
||||
assert_warn(/block not used/) {
|
||||
assert_equal [0x3042, 0x3044, 0x3046], s.codepoints {}
|
||||
}
|
||||
else
|
||||
res = []
|
||||
assert_equal s.object_id, s.codepoints {|x| res << x }.object_id
|
||||
assert_equal(0x3042, res[0])
|
||||
@ -969,7 +956,6 @@ CODE
|
||||
assert_same s, s.codepoints {|x| res << x }
|
||||
assert_equal [65, 66, 67], res
|
||||
end
|
||||
end
|
||||
|
||||
def test_each_char
|
||||
s = S("ABC")
|
||||
@ -987,18 +973,12 @@ CODE
|
||||
s = S("ABC")
|
||||
assert_equal ["A", "B", "C"], s.chars
|
||||
|
||||
if ENUMERATOR_WANTARRAY
|
||||
assert_warn(/block not used/) {
|
||||
assert_equal ["A", "B", "C"], s.chars {}
|
||||
}
|
||||
else
|
||||
res = []
|
||||
assert_equal s.object_id, s.chars {|x| res << x }.object_id
|
||||
assert_equal("A", res[0])
|
||||
assert_equal("B", res[1])
|
||||
assert_equal("C", res[2])
|
||||
end
|
||||
end
|
||||
|
||||
def test_each_grapheme_cluster
|
||||
[
|
||||
@ -1058,11 +1038,6 @@ CODE
|
||||
end
|
||||
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
|
||||
s = "ABC".b
|
||||
res = []
|
||||
assert_same s, s.grapheme_clusters {|x| res << x }
|
||||
@ -1071,7 +1046,6 @@ CODE
|
||||
assert_equal("B", res[1])
|
||||
assert_equal("C", res[2])
|
||||
end
|
||||
end
|
||||
|
||||
def test_each_line
|
||||
verbose, $VERBOSE = $VERBOSE, nil
|
||||
@ -1180,17 +1154,11 @@ CODE
|
||||
assert_equal ["hello\n", "world"], s.lines
|
||||
assert_equal ["hello\nworld"], s.lines(nil)
|
||||
|
||||
if ENUMERATOR_WANTARRAY
|
||||
assert_warn(/block not used/) {
|
||||
assert_equal ["hello\n", "world"], s.lines {}
|
||||
}
|
||||
else
|
||||
res = []
|
||||
assert_equal s.object_id, s.lines {|x| res << x }.object_id
|
||||
assert_equal(S("hello\n"), res[0])
|
||||
assert_equal(S("world"), res[1])
|
||||
end
|
||||
end
|
||||
|
||||
def test_empty?
|
||||
assert_empty(S(""))
|
||||
|
Loading…
x
Reference in New Issue
Block a user