зеркало из https://github.com/github/ruby.git
[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:
Родитель
0ac5009165
Коммит
d27fa87418
|
@ -29,6 +29,8 @@ class Reline::History < Array
|
|||
end
|
||||
|
||||
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
|
||||
if diff > 0
|
||||
if diff <= size
|
||||
|
@ -43,6 +45,8 @@ class Reline::History < Array
|
|||
end
|
||||
|
||||
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
|
||||
super(String.new(val, encoding: Reline.encoding_system_needs))
|
||||
end
|
||||
|
|
|
@ -242,6 +242,16 @@ class Reline::History::Test < Reline::TestCase
|
|||
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
|
||||
|
||||
def history_new(history_size: 10)
|
||||
|
|
Загрузка…
Ссылка в новой задаче