aboutsummaryrefslogtreecommitdiffstats
path: root/test/readline
diff options
context:
space:
mode:
authorkouji <kouji@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-01 13:21:55 +0000
committerkouji <kouji@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-01 13:21:55 +0000
commit7a4b214558009bcb64630ae06e552a9c0c0ffba4 (patch)
tree042db6393a5679612e8ee37d10952fb6f9f03823 /test/readline
parent28b7df782088e1e18b53659b0ba0c96a1b8b1c8b (diff)
downloadruby-7a4b214558009bcb64630ae06e552a9c0c0ffba4.tar.gz
* ext/readline/readline.c (Readline.pre_input_hook)
(Readline.insert_text, Readline.redisplay): new function. An original patch was created by nagachika. [Feature #5785] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35513 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/readline')
-rw-r--r--test/readline/test_readline.rb80
1 files changed, 51 insertions, 29 deletions
diff --git a/test/readline/test_readline.rb b/test/readline/test_readline.rb
index 9ac67ca991..98922a2120 100644
--- a/test/readline/test_readline.rb
+++ b/test/readline/test_readline.rb
@@ -1,34 +1,5 @@
begin
require "readline"
-=begin
- class << Readline
- [
- "line_buffer",
- "point",
- "set_screen_size",
- "get_screen_size",
- "vi_editing_mode",
- "emacs_editing_mode",
- "completion_append_character=",
- "completion_append_character",
- "basic_word_break_characters=",
- "basic_word_break_characters",
- "completer_word_break_characters=",
- "completer_word_break_characters",
- "basic_quote_characters=",
- "basic_quote_characters",
- "completer_quote_characters=",
- "completer_quote_characters",
- "filename_quote_characters=",
- "filename_quote_characters",
- "refresh_line",
- ].each do |method_name|
- define_method(method_name.to_sym) do |*args|
- raise NotImplementedError
- end
- end
- end
-=end
rescue LoadError
else
require "test/unit"
@@ -77,6 +48,10 @@ class TestReadline < Test::Unit::TestCase
["point"],
["set_screen_size", 1, 1],
["get_screen_size"],
+ ["pre_input_hook=", proc {}],
+ ["pre_input_hook"],
+ ["insert_text", ""],
+ ["redisplay"],
]
method_args.each do |method_name, *args|
assert_raise(SecurityError, NotImplementedError,
@@ -372,6 +347,53 @@ class TestReadline < Test::Unit::TestCase
end
end
+ def test_pre_input_hook
+ begin
+ pr = proc {}
+ assert_equal(Readline.pre_input_hook = pr, pr)
+ assert_equal(Readline.pre_input_hook, pr)
+ assert_nil(Readline.pre_input_hook = nil)
+ rescue NotImplementedError
+ end
+ end
+
+ def test_insert_text
+ begin
+ str = "test_insert_text"
+ assert_equal(Readline.insert_text(str), Readline)
+ assert_equal(Readline.line_buffer, str)
+ assert_equal(Readline.line_buffer.encoding,
+ get_default_internal_encoding)
+ rescue NotImplementedError
+ end
+ end if !/EditLine/n.match(Readline::VERSION)
+
+ def test_modify_text_in_pre_input_hook
+ begin
+ stdin = Tempfile.new("readline_redisplay_stdin")
+ stdout = Tempfile.new("readline_redisplay_stdout")
+ stdin.write("world\n")
+ stdin.close
+ Readline.pre_input_hook = proc do
+ assert_equal("", Readline.line_buffer)
+ Readline.insert_text("hello ")
+ Readline.redisplay
+ end
+ replace_stdio(stdin.path, stdout.path) do
+ line = Readline.readline("> ")
+ assert_equal("hello world", line)
+ end
+ assert_equal("> hello world\n", stdout.read)
+ stdout.close
+ rescue NotImplementedError
+ ensure
+ begin
+ Readline.pre_input_hook = nil
+ rescue NotImplementedError
+ end
+ end
+ end if !/EditLine/n.match(Readline::VERSION)
+
private
def replace_stdio(stdin_path, stdout_path)