[ruby/reline] Add Enumerable to KillRing for debugging
https://github.com/ruby/reline/commit/d208874152
This commit is contained in:
parent
dc61affd67
commit
671f2762fb
@ -1,4 +1,6 @@
|
||||
class Reline::KillRing
|
||||
include Enumerable
|
||||
|
||||
module State
|
||||
FRESH = :fresh
|
||||
CONTINUED = :continued
|
||||
@ -110,4 +112,14 @@ class Reline::KillRing
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def each
|
||||
start = head = @ring.head
|
||||
loop do
|
||||
break if head.nil?
|
||||
yield head.str
|
||||
head = head.backward
|
||||
break if head == start
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -253,4 +253,16 @@ class Reline::KillRing::Test < Reline::TestCase
|
||||
assert_equal(['AB', 'abcde'], @kill_ring.yank_pop)
|
||||
assert_equal(Reline::KillRing::State::YANK, @kill_ring.instance_variable_get(:@state))
|
||||
end
|
||||
|
||||
def test_enumerable
|
||||
@kill_ring.append('a')
|
||||
@kill_ring.process
|
||||
@kill_ring.process
|
||||
@kill_ring.append('b')
|
||||
@kill_ring.process
|
||||
@kill_ring.process
|
||||
@kill_ring.append('c')
|
||||
@kill_ring.process
|
||||
assert_equal(%w{c b a}, @kill_ring.to_a)
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user