-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ruby/irb] Show a quick preview of inspect result before pager
launch (ruby/irb#1040) * Quickly show inspect preview even if pretty_print takes too much time * Show a message "Inspecting..." while generating pretty_print content * Update inspecting message Co-authored-by: Stan Lo <[email protected]> * Update rendering test for preparing inspect message * Don't show preview if pretty_print does not take time --------- ruby/irb@03c36586e6 Co-authored-by: Stan Lo <[email protected]>
- Loading branch information
Showing
8 changed files
with
243 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# frozen_string_literal: false | ||
require 'irb/pager' | ||
|
||
require_relative 'helper' | ||
|
||
module TestIRB | ||
class PagerTest < TestCase | ||
def test_take_first_page | ||
assert_equal ['a' * 40, true], IRB::Pager.take_first_page(10, 4) {|io| io.puts 'a' * 41; raise 'should not reach here' } | ||
assert_equal ['a' * 39, false], IRB::Pager.take_first_page(10, 4) {|io| io.write 'a' * 39 } | ||
assert_equal ['a' * 39 + 'b', false], IRB::Pager.take_first_page(10, 4) {|io| io.write 'a' * 39 + 'b' } | ||
assert_equal ['a' * 39 + 'b', true], IRB::Pager.take_first_page(10, 4) {|io| io.write 'a' * 39 + 'bc' } | ||
assert_equal ["a\nb\nc\nd\n", false], IRB::Pager.take_first_page(10, 4) {|io| io.write "a\nb\nc\nd\n" } | ||
assert_equal ["a\nb\nc\nd\n", true], IRB::Pager.take_first_page(10, 4) {|io| io.write "a\nb\nc\nd\ne" } | ||
assert_equal ['a' * 15 + "\n" + 'b' * 20, true], IRB::Pager.take_first_page(10, 4) {|io| io.puts 'a' * 15; io.puts 'b' * 30 } | ||
assert_equal ["\e[31mA\e[0m" * 10 + 'x' * 30, true], IRB::Pager.take_first_page(10, 4) {|io| io.puts "\e[31mA\e[0m" * 10 + 'x' * 31; } | ||
end | ||
end | ||
|
||
class PageOverflowIOTest < TestCase | ||
def test_overflow | ||
actual_events = [] | ||
overflow_callback = ->(lines) do | ||
actual_events << [:callback_called, lines] | ||
end | ||
out = IRB::Pager::PageOverflowIO.new(10, 4, overflow_callback) | ||
out.puts 'a' * 15 | ||
out.write 'b' * 15 | ||
|
||
actual_events << :before_write | ||
out.write 'c' * 1000 | ||
actual_events << :after_write | ||
|
||
out.puts 'd' * 1000 | ||
out.write 'e' * 1000 | ||
|
||
expected_events = [ | ||
:before_write, | ||
[:callback_called, ['a' * 10, 'a' * 5 + "\n", 'b' * 10, 'b' * 5 + 'c' * 5]], | ||
:after_write, | ||
] | ||
assert_equal expected_events, actual_events | ||
|
||
expected_whole_content = 'a' * 15 + "\n" + 'b' * 15 + 'c' * 1000 + 'd' * 1000 + "\n" + 'e' * 1000 | ||
assert_equal expected_whole_content, out.string | ||
end | ||
|
||
def test_callback_delay | ||
actual_events = [] | ||
overflow_callback = ->(lines) do | ||
actual_events << [:callback_called, lines] | ||
end | ||
out = IRB::Pager::PageOverflowIO.new(10, 4, overflow_callback, delay: 0.2) | ||
out.write 'a' * 1000 | ||
assert_equal ['a' * 10] * 4, out.first_page_lines | ||
out.write 'b' | ||
actual_events << :before_delay | ||
sleep 0.2 | ||
out.write 'c' | ||
actual_events << :after_delay | ||
out.write 'd' | ||
assert_equal 'a' * 1000 + 'bcd', out.string | ||
assert_equal [:before_delay, [:callback_called, ['a' * 10] * 4], :after_delay], actual_events | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters