1
0
Fork 0
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:
aycabta 2020-04-25 01:45:03 +09:00
parent 0ac5009165
commit d27fa87418
2 changed files with 14 additions and 0 deletions

View file

@ -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

View file

@ -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)