summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbinoam P. Marques Jr <abinoam@gmail.com>2023-01-06 22:10:09 -0300
committerAbinoam P. Marques Jr <abinoam@gmail.com>2023-01-06 22:10:09 -0300
commit8caf3eb173c125355906fe4904d274f178abf59f (patch)
tree98ed94130b312474c4686e1853708267409633cd
parenta5342f160708cc87bcfdc544d10d85c7bcab554d (diff)
downloadhighline-8caf3eb173c125355906fe4904d274f178abf59f.tar.gz
Add tests for Ctrl-U (erase line) handling
-rwxr-xr-xtest/test_highline.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/test_highline.rb b/test/test_highline.rb
index a5c4e26..627f52c 100755
--- a/test/test_highline.rb
+++ b/test/test_highline.rb
@@ -349,6 +349,44 @@ class TestHighLine < Minitest::Test
assert_equal(4, @output.string.count("\b"))
end
+ def test_erase_line_does_not_enter_prompt
+ @input << "\cU\cU\cU\cU\cU\cU\cU\cU\cU"
+ @input.rewind
+ answer = @terminal.ask("Please enter your password: ") do |q|
+ q.echo = "*"
+ end
+ assert_equal("", answer)
+ assert_equal("Please enter your password: \n", @output.string)
+
+ # There's no backspaces as the line is already empty
+ assert_equal(0, @output.string.count("\b"))
+ end
+
+ def test_after_some_chars_erase_line_does_not_enter_prompt_when_ascii
+ @input << "apple\cU\cU\cU\cU\cU\cU\cU\cU"
+ @input.rewind
+ answer = @terminal.ask("Please enter your password: ") do |q|
+ q.echo = "*"
+ end
+ assert_equal("", answer)
+
+ # There's only enough backspaces to clear the given string
+ assert_equal(5, @output.string.count("\b"))
+ end
+
+
+ def test_after_some_chars_erase_line_does_not_enter_prompt_when_utf8
+ @input << "maçã\cU\cU\cU\cU\cU\cU\cU\cU"
+ @input.rewind
+ answer = @terminal.ask("Please enter your password: ") do |q|
+ q.echo = "*"
+ end
+ assert_equal("", answer)
+
+ # There's only enough backspaces to clear the given string
+ assert_equal(4, @output.string.count("\b"))
+ end
+
def test_readline_mode
#
# Rubinius (and JRuby) seems to be ignoring