From e468d9f49ca34f713c030c623f655a40370e186d Mon Sep 17 00:00:00 2001 From: aycabta Date: Sat, 29 Aug 2020 20:48:25 +0900 Subject: [ruby/irb] Add OMIT_ON_ASSIGNMENT Omit the results evaluated at assignment if they are too long. The behavior of ECHO_ON_ASSIGNMENT being on by default is hard to understand, so I change it to off by default. Instead, we turn OMIT_ON_ASSIGNMENT on by default. The result is displayed on assignment, but it will always be short and within one line of the screen. https://github.com/ruby/irb/commit/c5ea79d5ce --- test/irb/test_context.rb | 85 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 81 insertions(+), 4 deletions(-) (limited to 'test/irb/test_context.rb') diff --git a/test/irb/test_context.rb b/test/irb/test_context.rb index 55bd6ff63e..3a4c98729e 100644 --- a/test/irb/test_context.rb +++ b/test/irb/test_context.rb @@ -30,6 +30,10 @@ module TestIRB def reset @line_no = 0 end + + def winsize + [10, 20] + end end def setup @@ -213,6 +217,75 @@ module TestIRB assert_equal("", out) end + def test_omit_on_assignment + input = TestInputMethod.new([ + "a = [1] * 100\n", + "a\n", + ]) + value = [1] * 100 + irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input) + irb.context.return_format = "=> %s\n" + + irb.context.echo = true + irb.context.echo_on_assignment = false + irb.context.omit_on_assignment = true + out, err = capture_io do + irb.eval_input + end + assert_empty err + assert_equal("=> #{value.inspect}\n", out) + + input.reset + irb.context.echo = true + irb.context.echo_on_assignment = true + irb.context.omit_on_assignment = true + out, err = capture_io do + irb.eval_input + end + assert_empty err + assert_equal("=> #{value.inspect[0..(input.winsize.last - 9)]}...\e[0m\n=> #{value.inspect}\n", out) + + input.reset + irb.context.echo = true + irb.context.echo_on_assignment = true + irb.context.omit_on_assignment = false + out, err = capture_io do + irb.eval_input + end + assert_empty err + assert_equal("=> #{value.inspect}\n=> #{value.inspect}\n", out) + + input.reset + irb.context.echo = false + irb.context.echo_on_assignment = false + irb.context.omit_on_assignment = true + out, err = capture_io do + irb.eval_input + end + assert_empty err + assert_equal("", out) + + input.reset + irb.context.echo = false + irb.context.echo_on_assignment = true + irb.context.omit_on_assignment = true + out, err = capture_io do + irb.eval_input + end + assert_empty err + assert_equal("", out) + + input.reset + irb.context.echo = false + irb.context.echo_on_assignment = true + irb.context.omit_on_assignment = false + out, err = capture_io do + irb.eval_input + end + assert_empty err + assert_equal("", out) + end + def test_echo_on_assignment_conf # Default IRB.conf[:ECHO] = nil @@ -221,22 +294,26 @@ module TestIRB irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input) assert(irb.context.echo?, "echo? should be true by default") - refute(irb.context.echo_on_assignment?, "echo_on_assignment? should be false by default") + assert(irb.context.echo_on_assignment?, "echo_on_assignment? should be true by default") + assert(irb.context.omit_on_assignment?, "omit_on_assignment? should be true by default") # Explicitly set :ECHO to false IRB.conf[:ECHO] = false irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input) refute(irb.context.echo?, "echo? should be false when IRB.conf[:ECHO] is set to false") - refute(irb.context.echo_on_assignment?, "echo_on_assignment? should be false by default") + assert(irb.context.echo_on_assignment?, "echo_on_assignment? should be true by default") + assert(irb.context.omit_on_assignment?, "omit_on_assignment? should be true by default") # Explicitly set :ECHO_ON_ASSIGNMENT to true IRB.conf[:ECHO] = nil - IRB.conf[:ECHO_ON_ASSIGNMENT] = true + IRB.conf[:ECHO_ON_ASSIGNMENT] = false + IRB.conf[:OMIT_ON_ASSIGNMENT] = false irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input) assert(irb.context.echo?, "echo? should be true by default") - assert(irb.context.echo_on_assignment?, "echo_on_assignment? should be true when IRB.conf[:ECHO_ON_ASSIGNMENT] is set to true") + refute(irb.context.echo_on_assignment?, "echo_on_assignment? should be false when IRB.conf[:ECHO_ON_ASSIGNMENT] is set to false") + refute(irb.context.omit_on_assignment?, "omit_on_assignment? should be false when IRB.conf[:OMIT_ON_ASSIGNMENT] is set to false") end def test_multiline_output_on_default_inspector -- cgit v1.2.3