6
if defined?(Readline) && !/EditLine/n.match(Readline::VERSION)
11
class TestReadline < Test::Unit::TestCase
13
stdin = Tempfile.new("test_readline_stdin")
14
stdout = Tempfile.new("test_readline_stdout")
16
stdin.write("hello\n")
19
line = replace_stdio(stdin.path, stdout.path) {
20
Readline.readline("> ", true)
22
assert_equal("hello", line)
23
assert_equal(true, line.tainted?)
25
assert_equal("> ", stdout.read(2))
26
assert_equal(1, Readline::HISTORY.length)
27
assert_equal("hello", Readline::HISTORY[0])
28
assert_raises(SecurityError) do
31
replace_stdio(stdin.path, stdout.path) do
32
Readline.readline("> ".taint)
36
assert_raises(SecurityError) do
39
replace_stdio(stdin.path, stdout.path) { Readline.readline("> ") }
48
def test_completion_append_character
50
Readline.completion_append_character = "x"
51
assert_equal("x", Readline.completion_append_character)
52
Readline.completion_append_character = "xyz"
53
assert_equal("x", Readline.completion_append_character)
54
Readline.completion_append_character = nil
55
assert_equal(nil, Readline.completion_append_character)
56
Readline.completion_append_character = ""
57
assert_equal(nil, Readline.completion_append_character)
58
rescue NotImplementedError
64
def replace_stdio(stdin_path, stdout_path)
65
open(stdin_path, "r"){|stdin|
66
open(stdout_path, "w"){|stdout|
67
orig_stdin = STDIN.dup
68
orig_stdout = STDOUT.dup
74
STDIN.reopen(orig_stdin)
75
STDOUT.reopen(orig_stdout)