Skip to content

Commit 054d6af

Browse files
committed
Add specs for $~ in Enumerator::Lazy#grep_v
1 parent d7cc826 commit 054d6af

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

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

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

34+
it "sets $~ in the block" do
35+
"z" =~ /z/ # Reset $~
36+
["abc", "def"].lazy.grep_v(/e/) { |e|
37+
e.should == "abc"
38+
$~.should == nil
39+
}.force
40+
41+
# Set by the match of "def"
42+
$&.should == "e"
43+
end
44+
45+
it "sets $~ in the next block with each" do
46+
"z" =~ /z/ # Reset $~
47+
["abc", "def"].lazy.grep_v(/e/).each { |e|
48+
e.should == "abc"
49+
$~.should == nil
50+
}
51+
52+
# Set by the match of "def"
53+
$&.should == "e"
54+
end
55+
56+
it "sets $~ in the next block with map" do
57+
"z" =~ /z/ # Reset $~
58+
["abc", "def"].lazy.grep_v(/e/).map { |e|
59+
e.should == "abc"
60+
$~.should == nil
61+
}.force
62+
63+
# Set by the match of "def"
64+
$&.should == "e"
65+
end
66+
3467
describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
3568
it "stops after specified times when not given a block" do
3669
(0..Float::INFINITY).lazy.grep_v(3..5).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_v sets $~ in the block
2+
fails:Enumerator::Lazy#grep_v sets $~ in the next block with each
3+
fails:Enumerator::Lazy#grep_v sets $~ in the next block with map

0 commit comments

Comments
 (0)