ruby-changes:60939
From: aycabta <ko1@a...>
Date: Wed, 29 Apr 2020 19:14:29 +0900 (JST)
Subject: [ruby-changes:60939] d27fa87418 (master): [ruby/reline] New items to history are dropped if history_size is zero
https://git.ruby-lang.org/ruby.git/commit/?id=d27fa87418 From d27fa87418bcec8fff909f75a547a7c5e6dc83e5 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Sat, 25 Apr 2020 01:45:03 +0900 Subject: [ruby/reline] New items to history are dropped if history_size is zero https://github.com/ruby/reline/commit/9bdbed9cbc diff --git a/lib/reline/history.rb b/lib/reline/history.rb index d95f1ce..2e6a12e 100644 --- a/lib/reline/history.rb +++ b/lib/reline/history.rb @@ -29,6 +29,8 @@ class Reline::History < Array https://github.com/ruby/ruby/blob/trunk/lib/reline/history.rb#L29 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 https://github.com/ruby/ruby/blob/trunk/lib/reline/history.rb#L45 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 diff --git a/test/reline/test_history.rb b/test/reline/test_history.rb index 189f2db..0cb148d 100644 --- a/test/reline/test_history.rb +++ b/test/reline/test_history.rb @@ -242,6 +242,16 @@ class Reline::History::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_history.rb#L242 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) -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/