Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion test/ttytest/assertions/column_assertions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")

Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions test/ttytest/assertions/row_assertions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 53 additions & 1 deletion test/ttytest/assertions/screen_assertions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions test/ttytest/terminal_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand Down Expand Up @@ -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"')
Expand All @@ -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"')

Expand Down