diff --git a/test/ttytest/assertions/column_assertions_test.rb b/test/ttytest/assertions/column_assertions_test.rb index 4190bae..19477e8 100644 --- a/test/ttytest/assertions/column_assertions_test.rb +++ b/test/ttytest/assertions/column_assertions_test.rb @@ -5,14 +5,19 @@ module TTYtest class ColumnAssertionsTest < Minitest::Test def test_assert_column_success - @capture = Capture.new("$\n$\n$\n$\n$\n$\n") + @capture = Capture.new("$@za\n$@za\n$@za\n$@za\n$@za\n$@za\n") @capture.assert_column(0, '$$$$$$') + @capture.assert_column(1, '@@@@@@') + @capture.assert_column(2, 'zzzzzz') + @capture.assert_column(3, 'aaaaaa') end def test_assert_column_right_success @capture = Capture.new(" $\n $\n $\n $\n $\n $\n") + @capture.assert_column_is_empty(0) + @capture.assert_column_is_empty(1) @capture.assert_column(2, '$$$$$$') end @@ -25,6 +30,14 @@ def test_assert_column_failure assert_includes ex.message, 'expected column 0 to be' end + def test_assert_column_nil_failure + @capture = Capture.new(nil) + ex = assert_raises TTYtest::MatchError do + @capture.assert_column(0, 'foo') + end + assert_includes ex.message, 'expected column 0 to be "foo"' + end + def test_assert_column_wrong_column_failure @capture = Capture.new("$\n$\n$\n$\n$\n$\n") @@ -115,13 +128,30 @@ def test_assert_column_at_right_success @capture = Capture.new(" $\n $\n $\n $\n $\n $\n") @capture.assert_column_at(2, 0, 5, '$$$$$$') + @capture.assert_column_at(2, 0, 4, '$$$$$') + @capture.assert_column_at(2, 0, 3, '$$$$') + @capture.assert_column_at(2, 0, 2, '$$$') + @capture.assert_column_at(2, 0, 1, '$$') + @capture.assert_column_at(2, 0, 0, '$') + @capture.assert_column_at(2, 1, 5, '$$$$$') @capture.assert_column_at(2, 1, 4, '$$$$') + @capture.assert_column_at(2, 1, 3, '$$$') + @capture.assert_column_at(2, 1, 2, '$$') + @capture.assert_column_at(2, 1, 1, '$') + @capture.assert_column_at(2, 2, 5, '$$$$') @capture.assert_column_at(2, 2, 4, '$$$') + @capture.assert_column_at(2, 2, 3, '$$') + @capture.assert_column_at(2, 2, 2, '$') + @capture.assert_column_at(2, 3, 5, '$$$') @capture.assert_column_at(2, 3, 4, '$$') + @capture.assert_column_at(2, 3, 3, '$') + + @capture.assert_column_at(2, 4, 5, '$$') @capture.assert_column_at(2, 4, 4, '$') + @capture.assert_column_at(2, 5, 5, '$') end diff --git a/test/ttytest/assertions/row_assertions_test.rb b/test/ttytest/assertions/row_assertions_test.rb index 7fec4b2..23a8b04 100644 --- a/test/ttytest/assertions/row_assertions_test.rb +++ b/test/ttytest/assertions/row_assertions_test.rb @@ -320,6 +320,8 @@ def test_assert_rows_each_match_regexp_success @capture.assert_rows_each_match_regexp(0, 2, 'foo') @capture.assert_rows_each_match_regexp(0, 2, '[o]') @capture.assert_rows_each_match_regexp(0, 2, '[f]') + @capture.assert_rows_each_match_regexp(0, 2, '[fo]') + @capture.assert_rows_each_match_regexp(0, 2, '[fo]') end def test_assert_rows_each_match_regexp_failure diff --git a/test/ttytest/assertions/screen_assertions_test.rb b/test/ttytest/assertions/screen_assertions_test.rb index bfc6c10..8cc18b0 100644 --- a/test/ttytest/assertions/screen_assertions_test.rb +++ b/test/ttytest/assertions/screen_assertions_test.rb @@ -21,6 +21,13 @@ def test_assert_contents_success $ echo "Hello, world Hello, world TERM + + @capture.assert_contents <<~TERM + $ echo "Hello, world + Hello, world + + + TERM end def test_assert_contents_failure @@ -79,10 +86,28 @@ def test_assert_contents_at_success @capture.assert_contents_at(0, 0, '$ echo "Hello, world"') @capture.assert_contents_at(1, 1, 'Hello, world') + @capture.assert_contents_at 0, 0, <<~TERM + $ echo "Hello, world" + TERM + @capture.assert_contents_at 0, 1, <<~TERM $ echo "Hello, world" Hello, world TERM + + @capture.assert_contents_at 0, 2, <<~TERM + $ echo "Hello, world" + Hello, world + + TERM + + @capture.assert_contents_at 0, 0, <<~TERM + $ echo "Hello, world" + TERM + + @capture.assert_contents_at 1, 1, <<~TERM + Hello, world + TERM end def test_assert_contents_at_success_multiple_lines @@ -110,7 +135,8 @@ def test_assert_contents_at_success_multiple_lines Hello, world TERM - @capture.assert_contents_at 1, 2, <<~TERM + @capture.assert_contents_at 0, 2, <<~TERM + $ echo "Hello, world" Hello, world $ echo "Hello, world" TERM @@ -121,6 +147,30 @@ def test_assert_contents_at_success_multiple_lines $ echo "Hello, world" Hello, world TERM + + @capture.assert_contents_at 1, 1, <<~TERM + Hello, world + TERM + + @capture.assert_contents_at 1, 2, <<~TERM + Hello, world + $ echo "Hello, world" + TERM + + @capture.assert_contents_at 1, 3, <<~TERM + Hello, world + $ echo "Hello, world" + Hello, world + TERM + + @capture.assert_contents_at 2, 3, <<~TERM + $ echo "Hello, world" + Hello, world + TERM + + @capture.assert_contents_at 3, 3, <<~TERM + Hello, world + TERM end def test_assert_contents_at_failure @@ -160,6 +210,8 @@ def test_assert_contents_at_trailing_whitespace def test_assert_contents_include_true @capture = Capture.new(FOO_BAR_BAZ_THEN_EMPTY) + @capture.assert_contents_include('foo') + @capture.assert_contents_include('bar') @capture.assert_contents_include('baz') end diff --git a/test/ttytest/terminal_test.rb b/test/ttytest/terminal_test.rb index a59694a..e55982a 100644 --- a/test/ttytest/terminal_test.rb +++ b/test/ttytest/terminal_test.rb @@ -50,6 +50,12 @@ def test_new_default_sh_terminal_hello_world hello_world_test end + def test_new_default_sh_terminal_hello_world_return + @tty = TTYtest.new_default_sh_terminal + @tty.use_return_for_newline = true + hello_world_test + end + def test_command_exiting @tty = TTYtest.new_terminal(%(printf "foo\nbar\n")) @tty.assert_row(0, 'foo') @@ -70,6 +76,9 @@ def empty_command_test_helper(input) tty = TTYtest.new_terminal(input) tty.assert_cursor_position(0, 0) tty.assert_contents '' + tty.assert_contents_empty + tty.assert_row_is_empty(0) + tty.assert_column_is_empty(0) end def test_empty_commands @@ -304,6 +313,11 @@ def test_typical_example @tty.assert_cursor_position(2, 2) @tty.assert_contents_at(0, 0, '$ echo "Hello, world"') + @tty.assert_contents_at 0, 2, <<~TTY + $ echo "Hello, world" + Hello, world + $ + TTY @tty.assert_row_starts_with(0, '$ echo') @tty.assert_row_ends_with(0, '"Hello, world"') @@ -322,6 +336,7 @@ def test_typical_example_return @tty = TTYtest.new_terminal(%(PS1='$ ' /bin/sh), width: 80, height: 7, use_return_for_newline: true) @tty.assert_row(0, '$') @tty.assert_cursor_position(2, 0) + @tty.assert_cursor_visible @tty.send_line('echo "Hello, world"')