* test/readline/test_readline.rb: added test for Readline's class

methods.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18489 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kouji 2008-08-11 07:58:02 +00:00
Родитель 2897632f16
Коммит 5898c07466
2 изменённых файлов: 134 добавлений и 8 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Mon Aug 11 16:56:40 2008 TAKAO Kouji <kouji@takao7.net>
* test/readline/test_readline.rb: added test for Readline's class
methods.
Mon Aug 11 16:34:48 2008 Tanaka Akira <akr@fsij.org>
* enc/trans/iso2022.trans: renamed from iso2022.erb.c.

Просмотреть файл

@ -1,14 +1,77 @@
begin
require "readline"
=begin
class << Readline
[
"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",
].each do |method_name|
define_method(method_name.to_sym) do |*args|
raise NotImplementedError
end
end
end
=end
rescue LoadError
else
require "test/unit"
require "tempfile"
end
if defined?(Readline) && !/EditLine/n.match(Readline::VERSION)
require "test/unit"
require "tempfile"
class TestReadline < Test::Unit::TestCase
def teardown
Readline.instance_variable_set("@completion_proc", nil)
end
def test_safe_level_4
method_args =
[
["readline"],
["input=", $stdin],
["output=", $stdout],
["completion_proc=", proc {}],
["completion_proc"],
["completion_case_fold=", true],
["completion_case_fold"],
["vi_editing_mode"],
["emacs_editing_mode"],
["completion_append_character=", "s"],
["completion_append_character"],
["basic_word_break_characters=", "s"],
["basic_word_break_characters"],
["completer_word_break_characters=", "s"],
["completer_word_break_characters"],
["basic_quote_characters=", "\\"],
["basic_quote_characters"],
["completer_quote_characters=", "\\"],
["completer_quote_characters"],
["filename_quote_characters=", "\\"],
["filename_quote_characters"],
]
method_args.each do |method_name, *args|
assert_raises(SecurityError, NotImplementedError,
"method=<#{method_name}>") do
Thread.start {
$SAFE = 4
Readline.send(method_name.to_sym, *args)
assert(true)
}.join
end
end
end
def test_readline
stdin = Tempfile.new("test_readline_stdin")
stdout = Tempfile.new("test_readline_stdout")
@ -43,6 +106,36 @@ class TestReadline < Test::Unit::TestCase
stdin.close(true)
stdout.close(true)
end
end if !/EditLine/n.match(Readline::VERSION)
def test_input=
assert_raise(TypeError) do
Readline.input = "This is not a file."
end
end
def test_output=
assert_raise(TypeError) do
Readline.output = "This is not a file."
end
end
def test_completion_proc
expected = proc { |input| input }
Readline.completion_proc = expected
assert_equal(expected, Readline.completion_proc)
assert_raise(ArgumentError) do
Readline.completion_proc = "This does not have call method."
end
end
def test_completion_case_fold
expected = [true, false, "string", {"a" => "b"}]
expected.each do |e|
Readline.completion_case_fold = e
assert_equal(e, Readline.completion_case_fold)
end
end
def test_completion_append_character
@ -59,6 +152,36 @@ class TestReadline < Test::Unit::TestCase
end
end
# basic_word_break_characters
# completer_word_break_characters
# basic_quote_characters
# completer_quote_characters
# filename_quote_characters
def test_some_characters_methods
method_names = [
"basic_word_break_characters",
"completer_word_break_characters",
"basic_quote_characters",
"completer_quote_characters",
"filename_quote_characters",
]
method_names.each do |method_name|
begin
begin
saved = Readline.send(method_name.to_sym)
expecteds = [" ", " .,|\t", ""]
expecteds.each do |e|
Readline.send((method_name + "=").to_sym, e)
assert_equal(e, Readline.send(method_name.to_sym))
end
ensure
Readline.send((method_name + "=").to_sym, saved) if saved
end
rescue NotImplementedError
end
end
end
private
def replace_stdio(stdin_path, stdout_path)
@ -81,6 +204,4 @@ class TestReadline < Test::Unit::TestCase
}
}
end
end
end
end if defined?(::Readline)