Skip to content

Commit ea3ed76

Browse files
committed
Add specs for $~ in Enumerator::Lazy#grep
1 parent 99fb4a4 commit ea3ed76

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

spec/ruby/core/enumerator/lazy/grep_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,39 @@
3333
Enumerator::Lazy.new(Object.new, 100) {}.grep(Object).size.should == nil
3434
end
3535

36+
it "sets $~ in the block" do
37+
"z" =~ /z/ # Reset $~
38+
["abc", "def"].lazy.grep(/b/) { |e|
39+
e.should == "abc"
40+
$&.should == "b"
41+
}.force
42+
43+
# Set by the failed match of "def"
44+
$~.should == nil
45+
end
46+
47+
it "sets $~ in the next block with each" do
48+
"z" =~ /z/ # Reset $~
49+
["abc", "def"].lazy.grep(/b/).each { |e|
50+
e.should == "abc"
51+
$&.should == "b"
52+
}
53+
54+
# Set by the failed match of "def"
55+
$~.should == nil
56+
end
57+
58+
it "sets $~ in the next block with map" do
59+
"z" =~ /z/ # Reset $~
60+
["abc", "def"].lazy.grep(/b/).map { |e|
61+
e.should == "abc"
62+
$&.should == "b"
63+
}.force
64+
65+
# Set by the failed match of "def"
66+
$~.should == nil
67+
end
68+
3669
describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
3770
it "stops after specified times when not given a block" do
3871
(0..Float::INFINITY).lazy.grep(Integer).first(3).should == [0, 1, 2]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fails:Enumerator::Lazy#grep sets $~ in the next block with each
2+
fails:Enumerator::Lazy#grep sets $~ in the next block with map
3+
fails:Enumerator::Lazy#grep sets $~ in the block

0 commit comments

Comments
 (0)