Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/irb/ext/eval_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def initialize(size = 16) # :nodoc:
end

def size(size) # :nodoc:
if size != 0 && size < @size
@contents = @contents[@size - size .. @size]
if size.positive? && @contents.size > size
@contents = @contents.last(size)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍
Can you add a test for this?
Adding a test that does the below in test_eval_history.rb would be enough

out, err = execute_lines(
  "IRB.CurrentContext.eval_history = 2",
  "__",
  conf: { EVAL_HISTORY: 5 }
)

end
@size = size
end
Expand Down
11 changes: 11 additions & 0 deletions test/irb/test_eval_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,16 @@ def test_eval_history_respects_given_limit
# Because eval_history injects `__` into the history AND decide to ignore it, we only get <limit> - 1 results
assert_match("2 \"bar\"\n" + "3 \"baz\"\n" + "4 \"xyz\"\n", out)
end

def test_eval_history_can_shrink_before_reaching_configured_limit
out, err = execute_lines(
"IRB.CurrentContext.eval_history = 2",
"__",
conf: { EVAL_HISTORY: 5 }
)

assert_empty(err)
assert_match("=> 2\n" + "=> 1 2\n", out)
end
end
end