From 556439613aa6a0d05a9884a305ae43f48cd2c5f0 Mon Sep 17 00:00:00 2001 From: tomoya ishida Date: Thu, 2 Mar 2023 22:53:39 +0900 Subject: [ruby/irb] Handle long inspect and control character in prompt string (https://github.com/ruby/irb/pull/528) * Handle long inspect and control characters in prompt string * Add constants for prompt truncate length, omission and replace pattern * Simply compare string instead of regexp in prompt truncation test --- test/irb/test_context.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/irb') diff --git a/test/irb/test_context.rb b/test/irb/test_context.rb index 55f258de88..9b471202bc 100644 --- a/test/irb/test_context.rb +++ b/test/irb/test_context.rb @@ -656,6 +656,23 @@ module TestIRB $VERBOSE = verbose end + def test_prompt_main_escape + irb = IRB::Irb.new(IRB::WorkSpace.new("main\a\t\r\n")) + assert_equal("irb(main )>", irb.prompt('irb(%m)>', nil, 1, 1)) + end + + def test_prompt_main_inspect_escape + main = Struct.new(:inspect).new("main\\n\nmain") + irb = IRB::Irb.new(IRB::WorkSpace.new(main)) + assert_equal("irb(main\\n main)>", irb.prompt('irb(%M)>', nil, 1, 1)) + end + + def test_prompt_main_truncate + irb = IRB::Irb.new(IRB::WorkSpace.new("a" * 100)) + assert_equal('irb(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa...)>', irb.prompt('irb(%m)>', nil, 1, 1)) + assert_equal('irb("aaaaaaaaaaaaaaaaaaaaaaaaaaaa...)>', irb.prompt('irb(%M)>', nil, 1, 1)) + end + def test_lineno input = TestInputMethod.new([ "\n", -- cgit v1.2.1