From 6175ca03be6d0d51359f9017123708987d0f5eb7 Mon Sep 17 00:00:00 2001 From: shyouhei Date: Wed, 15 Aug 2007 23:23:39 +0000 Subject: add tag v1_8_5_91 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_8_5_91@13046 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ruby_1_8_5/test/readline/test_readline.rb | 84 +++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 ruby_1_8_5/test/readline/test_readline.rb (limited to 'ruby_1_8_5/test/readline/test_readline.rb') diff --git a/ruby_1_8_5/test/readline/test_readline.rb b/ruby_1_8_5/test/readline/test_readline.rb new file mode 100644 index 0000000000..edc3aa09b9 --- /dev/null +++ b/ruby_1_8_5/test/readline/test_readline.rb @@ -0,0 +1,84 @@ +begin + require "readline" +rescue LoadError +end + +if defined?(Readline) && !/EditLine/n.match(Readline::VERSION) + +require "test/unit" +require "tempfile" + +class TestReadline < Test::Unit::TestCase + def test_readline + stdin = Tempfile.new("test_readline_stdin") + stdout = Tempfile.new("test_readline_stdout") + begin + stdin.write("hello\n") + stdin.close + stdout.close + line = replace_stdio(stdin.path, stdout.path) { + Readline.readline("> ", true) + } + assert_equal("hello", line) + assert_equal(true, line.tainted?) + stdout.open + assert_equal("> ", stdout.read(2)) + assert_equal(1, Readline::HISTORY.length) + assert_equal("hello", Readline::HISTORY[0]) + assert_raises(SecurityError) do + Thread.start { + $SAFE = 1 + replace_stdio(stdin.path, stdout.path) do + Readline.readline("> ".taint) + end + }.join + end + assert_raises(SecurityError) do + Thread.start { + $SAFE = 4 + replace_stdio(stdin.path, stdout.path) { Readline.readline("> ") } + }.join + end + ensure + stdin.close(true) + stdout.close(true) + end + end + + def test_completion_append_character + begin + Readline.completion_append_character = "x" + assert_equal("x", Readline.completion_append_character) + Readline.completion_append_character = "xyz" + assert_equal("x", Readline.completion_append_character) + Readline.completion_append_character = nil + assert_equal(nil, Readline.completion_append_character) + Readline.completion_append_character = "" + assert_equal(nil, Readline.completion_append_character) + rescue NotImplementedError + end + end + + private + + def replace_stdio(stdin_path, stdout_path) + open(stdin_path, "r"){|stdin| + open(stdout_path, "w"){|stdout| + orig_stdin = STDIN.dup + orig_stdout = STDOUT.dup + STDIN.reopen(stdin) + STDOUT.reopen(stdout) + begin + yield + ensure + STDIN.reopen(orig_stdin) + STDOUT.reopen(orig_stdout) + orig_stdin.close + orig_stdout.close + end + } + } + end +end + +end -- cgit v1.2.3