aboutsummaryrefslogtreecommitdiffstats
path: root/test/irb/test_context.rb
diff options
context:
space:
mode:
authortomoya ishida <tomoyapenguin@gmail.com>2023-03-02 22:53:39 +0900
committergit <svn-admin@ruby-lang.org>2023-03-02 13:53:44 +0000
commit556439613aa6a0d05a9884a305ae43f48cd2c5f0 (patch)
tree469ee829bd90c78d5bfac75f9e1086a03e717cc8 /test/irb/test_context.rb
parentda6ac30d1e505bd15b8c118816a9990b5cb072a7 (diff)
downloadruby-556439613aa6a0d05a9884a305ae43f48cd2c5f0.tar.gz
[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
Diffstat (limited to 'test/irb/test_context.rb')
-rw-r--r--test/irb/test_context.rb17
1 files changed, 17 insertions, 0 deletions
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",