Skip to content

Commit

Permalink
Fix prompt test not to change STDIO.external_encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Mar 3, 2023
1 parent 00b39be commit 856f744
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions test/irb/test_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ def setup
def Reline.get_screen_size
[36, 80]
end
save_encodings
end

def teardown
Reline.instance_eval { undef :get_screen_size }
Reline.define_singleton_method(:get_screen_size, @get_screen_size)
restore_encodings
end

def test_last_value
Expand Down Expand Up @@ -658,20 +660,20 @@ def test_eval_input_with_long_exception

def test_prompt_main_escape
main = Struct.new(:to_s).new("main\a\t\r\n")
irb = IRB::Irb.new(IRB::WorkSpace.new(main))
irb = IRB::Irb.new(IRB::WorkSpace.new(main), TestInputMethod.new)
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))
irb = IRB::Irb.new(IRB::WorkSpace.new(main), TestInputMethod.new)
assert_equal("irb(main\\n main)>", irb.prompt('irb(%M)>', nil, 1, 1))
end

def test_prompt_main_truncate
main = Struct.new(:to_s).new("a" * 100)
def main.inspect; to_s.inspect; end
irb = IRB::Irb.new(IRB::WorkSpace.new(main))
irb = IRB::Irb.new(IRB::WorkSpace.new(main), TestInputMethod.new)
assert_equal('irb(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa...)>', irb.prompt('irb(%m)>', nil, 1, 1))
assert_equal('irb("aaaaaaaaaaaaaaaaaaaaaaaaaaaa...)>', irb.prompt('irb(%M)>', nil, 1, 1))
end
Expand Down

0 comments on commit 856f744

Please sign in to comment.