summaryrefslogtreecommitdiff
path: root/test/irb/test_context.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/irb/test_context.rb')
-rw-r--r--test/irb/test_context.rb85
1 files changed, 81 insertions, 4 deletions
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