diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/error_highlight/test_error_highlight.rb | 83 |
1 files changed, 76 insertions, 7 deletions
diff --git a/test/error_highlight/test_error_highlight.rb b/test/error_highlight/test_error_highlight.rb index d00c04995d..be36fca260 100644 --- a/test/error_highlight/test_error_highlight.rb +++ b/test/error_highlight/test_error_highlight.rb @@ -5,7 +5,7 @@ require "did_you_mean" require "tempfile" class ErrorHighlightTest < Test::Unit::TestCase - ErrorHighlight::DefaultFormatter.viewport_size = 80 + ErrorHighlight::DefaultFormatter.snippet_max_width = 80 class DummyFormatter def self.message_for(corrections) @@ -1287,7 +1287,7 @@ undefined method `time' for #{ ONE_RECV_MESSAGE } end end - def test_errors_on_small_viewports_at_the_end + def test_errors_on_small_terminal_window_at_the_end assert_error_message(NoMethodError, <<~END) do undefined method `time' for #{ ONE_RECV_MESSAGE } @@ -1299,7 +1299,7 @@ undefined method `time' for #{ ONE_RECV_MESSAGE } end end - def test_errors_on_small_viewports_at_the_beginning + def test_errors_on_small_terminal_window_at_the_beginning assert_error_message(NoMethodError, <<~END) do undefined method `time' for #{ ONE_RECV_MESSAGE } @@ -1312,7 +1312,19 @@ undefined method `time' for #{ ONE_RECV_MESSAGE } end end - def test_errors_on_small_viewports_at_the_middle + def test_errors_on_small_terminal_window_at_the_middle_near_beginning + assert_error_message(NoMethodError, <<~END) do +undefined method `time' for #{ ONE_RECV_MESSAGE } + + 100000000000000000000000000000000000000 + 1.time { 1000000000000000000000... + ^^^^^ + END + + 100000000000000000000000000000000000000 + 1.time { 100000000000000000000000000000000000000 } + end + end + + def test_errors_on_small_terminal_window_at_the_middle assert_error_message(NoMethodError, <<~END) do undefined method `time' for #{ ONE_RECV_MESSAGE } @@ -1320,11 +1332,68 @@ undefined method `time' for #{ ONE_RECV_MESSAGE } ^^^^^ END - 100000000000000000000000000000000000000 + 1.time { 100000000000000000000000000000000000000 } + 10000000000000000000000000000000000000000000000000000000000000000000000 + 1.time { 1000000000000000000000000000000 } + end + end + + def test_errors_on_extremely_small_terminal_window + custom_max_width = 30 + original_max_width = ErrorHighlight::DefaultFormatter.snippet_max_width + + ErrorHighlight::DefaultFormatter.snippet_max_width = custom_max_width + + assert_error_message(NoMethodError, <<~END) do +undefined method `time' for #{ ONE_RECV_MESSAGE } + +...00000000 + 1.time { 1000... + ^^^^^ + END + + 100000000000000 + 1.time { 100000000000000 } + end + ensure + ErrorHighlight::DefaultFormatter.snippet_max_width = original_max_width + end + + def test_errors_on_terminal_window_smaller_than_min_width + custom_max_width = 5 + original_max_width = ErrorHighlight::DefaultFormatter.snippet_max_width + + ErrorHighlight::DefaultFormatter.snippet_max_width = custom_max_width + + assert_error_message(NoMethodError, <<~END) do +undefined method `time' for #{ ONE_RECV_MESSAGE } + +...000 + 1.time {... + ^^^^^ + END + + 100000000000000 + 1.time { 100000000000000 } + end + ensure + ErrorHighlight::DefaultFormatter.snippet_max_width = original_max_width + end + + def test_errors_on_terminal_window_when_truncation_is_disabled + custom_max_width = nil + original_max_width = ErrorHighlight::DefaultFormatter.snippet_max_width + + ErrorHighlight::DefaultFormatter.snippet_max_width = custom_max_width + + assert_error_message(NoMethodError, <<~END) do +undefined method `time' for #{ ONE_RECV_MESSAGE } + + 10000000000000000000000000000000000000000000000000000000000000000000000 + 1.time { 1000000000000000000000000000000 } + ^^^^^ + END + + 10000000000000000000000000000000000000000000000000000000000000000000000 + 1.time { 1000000000000000000000000000000 } end + ensure + ErrorHighlight::DefaultFormatter.snippet_max_width = original_max_width end - def test_errors_on_small_viewports_when_larger_than_viewport + def test_errors_on_small_terminal_window_when_larger_than_viewport assert_error_message(NoMethodError, <<~END) do undefined method `timessssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss!' for #{ ONE_RECV_MESSAGE } @@ -1336,7 +1405,7 @@ undefined method `timessssssssssssssssssssssssssssssssssssssssssssssssssssssssss end end - def test_errors_on_small_viewports_when_exact_size_of_viewport + def test_errors_on_small_terminal_window_when_exact_size_of_viewport assert_error_message(NoMethodError, <<~END) do undefined method `timessssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss!' for #{ ONE_RECV_MESSAGE } |
