diff --git a/test/cli/ui/prompt_test.rb b/test/cli/ui/prompt_test.rb index cc5c4e1bc..84a22bfe9 100644 --- a/test/cli/ui/prompt_test.rb +++ b/test/cli/ui/prompt_test.rb @@ -37,8 +37,8 @@ def test_confirm_sigint expected_out = strip_heredoc(<<-EOF) + ' ' ? q (choose with ↑ ↓ ⏎) - \e[?25l#{option_text('1. yes', selected: true)} - #{option_text('2. no')} + \e[?25l> 1. yes\e[K + 2. no\e[K \e[?25h\e[\e[C EOF assert_result(expected_out, "", :SIGINT) @@ -74,8 +74,8 @@ def test_ask_interactive_sigint expected_out = strip_heredoc(<<-EOF) + ' ' ? q (choose with ↑ ↓ ⏎) - \e[?25l#{option_text('1. a', selected: true)} - #{option_text('2. b')} + \e[?25l> 1. a\e[K + 2. b\e[K \e[?25h\e[\e[C EOF assert_result(expected_out, "", :SIGINT) @@ -85,8 +85,8 @@ def test_confirm_happy_path _run('y') { assert Prompt.confirm('q') } expected_out = strip_heredoc(<<-EOF) + ' ' ? q (choose with ↑ ↓ ⏎) - \e[?25l#{option_text('1. yes', selected: true)} - #{option_text('2. no')} + \e[?25l> 1. yes\e[K + 2. no\e[K \e[\e[C #{' ' * CLI::UI::Terminal.width} #{' ' * CLI::UI::Terminal.width} @@ -101,8 +101,8 @@ def test_confirm_invalid _run(%w(r y n)) { Prompt.confirm('q') } expected_out = strip_heredoc(<<-EOF) + ' ' ? q (choose with ↑ ↓ ⏎) - \e[?25l#{option_text('1. yes', selected: true)} - #{option_text('2. no')} + \e[?25l> 1. yes\e[K + 2. no\e[K \e[\e[C #{' ' * CLI::UI::Terminal.width} #{' ' * CLI::UI::Terminal.width} @@ -117,8 +117,8 @@ def test_confirm_no_match_internal _run('x', 'n') { Prompt.confirm('q') } expected_out = strip_heredoc(<<-EOF) + ' ' ? q (choose with ↑ ↓ ⏎) - \e[?25l#{option_text('1. yes', selected: true)} - #{option_text('2. no')} + \e[?25l> 1. yes\e[K + 2. no\e[K \e[\e[C #{' ' * CLI::UI::Terminal.width} #{' ' * CLI::UI::Terminal.width} @@ -217,8 +217,8 @@ def test_ask_interactive_with_block end expected_out = strip_heredoc(<<-EOF) ? q (choose with ↑ ↓ ⏎) - \e[?25l#{option_text('1. a', selected: true)} - #{option_text('2. b')} + \e[?25l> 1. a\e[K + 2. b\e[K \e[\e[C #{' ' * CLI::UI::Terminal.width} #{' ' * CLI::UI::Terminal.width} @@ -235,8 +235,8 @@ def test_ask_interactive_with_number end expected_out = strip_heredoc(<<-EOF) ? q (choose with ↑ ↓ ⏎) - \e[?25l#{option_text('1. a', selected: true)} - #{option_text('2. b')} + \e[?25l> 1. a\e[K + 2. b\e[K \e[\e[C #{' ' * CLI::UI::Terminal.width} #{' ' * CLI::UI::Terminal.width} @@ -253,11 +253,11 @@ def test_ask_interactive_with_vim_bound_arrows end expected_out = strip_heredoc(<<-EOF) ? q (choose with ↑ ↓ ⏎) - \e[?25l#{option_text('1. a', selected: true)} - #{option_text('2. b')} + \e[?25l> 1. a\e[K + 2. b\e[K \e[\e[C - #{option_text('1. a')} - #{option_text('2. b', selected: true)} + 1. a\e[K + > 2. b\e[K \e[\e[C #{' ' * CLI::UI::Terminal.width} #{' ' * CLI::UI::Terminal.width} @@ -274,8 +274,8 @@ def test_ask_interactive_select_using_space end expected_out = strip_heredoc(<<-EOF) ? q (choose with ↑ ↓ ⏎) - \e[?25l#{option_text('1. a', selected: true)} - #{option_text('2. b')} + \e[?25l> 1. a\e[K + 2. b\e[K \e[\e[C #{' ' * CLI::UI::Terminal.width} #{' ' * CLI::UI::Terminal.width} @@ -297,8 +297,8 @@ def test_ask_interactive_escape expected_out = strip_heredoc(<<-EOF) ? q (choose with ↑ ↓ ⏎) - \e[?25l#{option_text('1. a', selected: true)} - #{option_text('2. b')} + \e[?25l> 1. a\e[K + 2. b\e[K \e[?25h\e[\e[C EOF assert_result(expected_out, nil, :SIGINT) @@ -310,8 +310,8 @@ def test_ask_interactive_invalid_input end expected_out = strip_heredoc(<<-EOF) ? q (choose with ↑ ↓ ⏎) - \e[?25l#{option_text('1. a', selected: true)} - #{option_text('2. b')} + \e[?25l> 1. a\e[K + 2. b\e[K \e[\e[C #{' ' * CLI::UI::Terminal.width} #{' ' * CLI::UI::Terminal.width} @@ -332,14 +332,14 @@ def test_ask_interactive_with_blank_option blank = '' expected_out = strip_heredoc(<<-EOF) ? q (choose with ↑ ↓ ⏎) - \e[?25l#{option_text('1. a', selected: true)} - #{option_text("2.#{blank}")} + \e[?25l> 1. a\e[K + 2.#{blank}\e[K \e[\e[C - #{option_text('1. a')} - #{option_text("2.#{blank}", selected: true)} + 1. a\e[K + > 2.#{blank}\e[K \e[\e[C - #{option_text('1. a', selected: true)} - #{option_text("2.#{blank}")} + > 1. a\e[K + 2.#{blank}\e[K \e[\e[C #{' ' * CLI::UI::Terminal.width} #{' ' * CLI::UI::Terminal.width} @@ -352,10 +352,6 @@ def test_ask_interactive_with_blank_option private - def option_text(text, selected: false) - "#{selected ? "> " : " "}#{text}#{CLI::UI::ANSI.clear_to_end_of_line}" - end - def _run(*lines) $stdin = @in_r start_process { @ret.write(Marshal.dump(yield)) }