summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Edward Gray II <james@grayproductions.net>2015-02-01 17:12:50 -0600
committerJames Edward Gray II <james@grayproductions.net>2015-02-01 17:12:50 -0600
commit410d9ecca53298634a1b5ed4d9366caf210a4db3 (patch)
tree1efb9843e4626d77ca75173876cddca9e0ed8643
parentea906c38741c1071697a4ac03840c9be8c0062dd (diff)
parentb4160cd939ba5e6db0e97175fab8d02fbc493ec7 (diff)
downloadhighline-410d9ecca53298634a1b5ed4d9366caf210a4db3.tar.gz
Merge pull request #120 from abinoam/issue_113
Fix issue #113
-rwxr-xr-xlib/highline.rb2
-rwxr-xr-xtest/tc_highline.rb64
2 files changed, 64 insertions, 2 deletions
diff --git a/lib/highline.rb b/lib/highline.rb
index 2f16dde..ac7c9c5 100755
--- a/lib/highline.rb
+++ b/lib/highline.rb
@@ -259,7 +259,7 @@ class HighLine
# the prompt will not be issued. And we have to account for that now.
# Also, JRuby-1.7's ConsoleReader.readLine() needs to be passed the prompt
# to handle line editing properly.
- say(@question) unless ((JRUBY or @question.readline) and @question.echo == true)
+ say(@question) unless ((JRUBY or @question.readline) and (@question.echo == true and @question.limit.nil?))
begin
@answer = @question.answer_or_default(get_response)
diff --git a/test/tc_highline.rb b/test/tc_highline.rb
index bcd218d..b2daf19 100755
--- a/test/tc_highline.rb
+++ b/test/tc_highline.rb
@@ -9,6 +9,8 @@ require "test/unit"
require "highline"
require "stringio"
+require "readline"
+require "tempfile"
if HighLine::CHARACTER_MODE == "Win32API"
class HighLine
@@ -244,7 +246,67 @@ class TestHighLine < Test::Unit::TestCase
assert_equal("", answer)
assert_equal("maçã".size, @output.string.count("\b"))
end
-
+
+ def test_readline_mode
+ # Creating Tempfiles here because Readline.input
+ # and Readline.output only accepts a File object
+ # as argument (not any duck type as StringIO)
+ temp_stdin = Tempfile.create "temp_stdin"
+ temp_stdout = Tempfile.create "temp_stdout"
+
+ Readline.input = @input = temp_stdin
+ Readline.output = @output = temp_stdout
+
+ @terminal = HighLine.new(@input, @output)
+
+ @input << "any input\n"
+ @input.rewind
+
+ answer = @terminal.ask("Prompt: ") do |q|
+ q.readline = true
+ end
+
+ @output.rewind
+ output = @output.read
+
+ assert_equal "any input", answer
+ assert_equal "Prompt: any input\n", output
+
+ @input.close
+ @output.close
+ Readline.input = STDIN
+ Readline.output = STDOUT
+ end
+
+ def test_readline_mode_with_limit_set
+ temp_stdin = Tempfile.create "temp_stdin"
+ temp_stdout = Tempfile.create "temp_stdout"
+
+ Readline.input = @input = temp_stdin
+ Readline.output = @output = temp_stdout
+
+ @terminal = HighLine.new(@input, @output)
+
+ @input << "any input\n"
+ @input.rewind
+
+ answer = @terminal.ask("Prompt: ") do |q|
+ q.limit = 50
+ q.readline = true
+ end
+
+ @output.rewind
+ output = @output.read
+
+ assert_equal "any input", answer
+ assert_equal "Prompt: any input\n", output
+
+ @input.close
+ @output.close
+ Readline.input = STDIN
+ Readline.output = STDOUT
+ end
+
def test_readline_on_non_echo_question_has_prompt
@input << "you can't see me"
@input.rewind