mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/reline] New items to history are dropped if history_size is zero
https://github.com/ruby/reline/commit/9bdbed9cbc
This commit is contained in:
parent
0ac5009165
commit
d27fa87418
2 changed files with 14 additions and 0 deletions
|
@ -29,6 +29,8 @@ class Reline::History < Array
|
||||||
end
|
end
|
||||||
|
|
||||||
def push(*val)
|
def push(*val)
|
||||||
|
# If history_size is zero, all histories are dropped.
|
||||||
|
return self if @config.history_size.zero?
|
||||||
diff = size + val.size - @config.history_size
|
diff = size + val.size - @config.history_size
|
||||||
if diff > 0
|
if diff > 0
|
||||||
if diff <= size
|
if diff <= size
|
||||||
|
@ -43,6 +45,8 @@ class Reline::History < Array
|
||||||
end
|
end
|
||||||
|
|
||||||
def <<(val)
|
def <<(val)
|
||||||
|
# If history_size is zero, all histories are dropped.
|
||||||
|
return self if @config.history_size.zero?
|
||||||
shift if size + 1 > @config.history_size
|
shift if size + 1 > @config.history_size
|
||||||
super(String.new(val, encoding: Reline.encoding_system_needs))
|
super(String.new(val, encoding: Reline.encoding_system_needs))
|
||||||
end
|
end
|
||||||
|
|
|
@ -242,6 +242,16 @@ class Reline::History::Test < Reline::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_history_size_zero
|
||||||
|
history = history_new(history_size: 0)
|
||||||
|
assert_equal 0, history.size
|
||||||
|
history << 'aa'
|
||||||
|
history << 'bb'
|
||||||
|
assert_equal 0, history.size
|
||||||
|
history.push(*%w{aa bb cc})
|
||||||
|
assert_equal 0, history.size
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def history_new(history_size: 10)
|
def history_new(history_size: 10)
|
||||||
|
|
Loading…
Add table
Reference in a new issue