2004-11-18 01:12:12 -05:00
|
|
|
begin
|
|
|
|
require "readline"
|
|
|
|
rescue LoadError
|
2008-08-11 03:58:02 -04:00
|
|
|
else
|
|
|
|
require "test/unit"
|
|
|
|
require "tempfile"
|
2013-07-23 12:17:58 -04:00
|
|
|
require "timeout"
|
2004-11-18 01:12:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class TestReadline < Test::Unit::TestCase
|
2012-04-26 21:58:21 -04:00
|
|
|
INPUTRC = "INPUTRC"
|
2015-03-12 23:29:43 -04:00
|
|
|
SAVED_ENV = %w[COLUMNS LINES]
|
2012-04-26 21:58:21 -04:00
|
|
|
|
|
|
|
def setup
|
2015-03-12 23:29:43 -04:00
|
|
|
@saved_env = ENV.values_at(*SAVED_ENV)
|
2012-04-26 21:58:21 -04:00
|
|
|
@inputrc, ENV[INPUTRC] = ENV[INPUTRC], IO::NULL
|
|
|
|
end
|
|
|
|
|
2008-08-11 03:58:02 -04:00
|
|
|
def teardown
|
2012-04-26 21:58:21 -04:00
|
|
|
ENV[INPUTRC] = @inputrc
|
2008-08-11 03:58:02 -04:00
|
|
|
Readline.instance_variable_set("@completion_proc", nil)
|
2013-08-06 08:52:22 -04:00
|
|
|
begin
|
|
|
|
Readline.delete_text
|
|
|
|
Readline.point = 0
|
|
|
|
rescue NotImplementedError
|
|
|
|
end
|
2013-10-28 10:26:41 -04:00
|
|
|
Readline.input = nil
|
|
|
|
Readline.output = nil
|
2015-03-12 23:29:43 -04:00
|
|
|
SAVED_ENV.each_with_index {|k, i| ENV[k] = @saved_env[i] }
|
2008-08-11 03:58:02 -04:00
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2009-07-10 08:13:18 -04:00
|
|
|
if !/EditLine/n.match(Readline::VERSION)
|
|
|
|
def test_readline
|
2012-01-09 20:41:15 -05:00
|
|
|
with_temp_stdio do |stdin, stdout|
|
2009-07-10 08:13:18 -04:00
|
|
|
stdin.write("hello\n")
|
|
|
|
stdin.close
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-20 19:03:52 -04:00
|
|
|
stdout.flush
|
2009-07-10 08:13:18 -04:00
|
|
|
line = replace_stdio(stdin.path, stdout.path) {
|
|
|
|
Readline.readline("> ", true)
|
|
|
|
}
|
|
|
|
assert_equal("hello", line)
|
|
|
|
assert_equal(true, line.tainted?)
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-20 19:03:52 -04:00
|
|
|
stdout.rewind
|
2009-07-10 08:13:18 -04:00
|
|
|
assert_equal("> ", stdout.read(2))
|
|
|
|
assert_equal(1, Readline::HISTORY.length)
|
|
|
|
assert_equal("hello", Readline::HISTORY[0])
|
|
|
|
assert_raise(SecurityError) do
|
|
|
|
Thread.start {
|
|
|
|
$SAFE = 1
|
|
|
|
replace_stdio(stdin.path, stdout.path) do
|
|
|
|
Readline.readline("> ".taint)
|
|
|
|
end
|
|
|
|
}.join
|
|
|
|
end
|
2004-11-18 01:12:12 -05:00
|
|
|
end
|
2011-05-15 07:55:52 -04:00
|
|
|
end
|
|
|
|
|
2009-07-10 08:13:18 -04:00
|
|
|
# line_buffer
|
|
|
|
# point
|
|
|
|
def test_line_buffer__point
|
|
|
|
begin
|
|
|
|
Readline.line_buffer
|
|
|
|
Readline.point
|
|
|
|
rescue NotImplementedError
|
|
|
|
return
|
|
|
|
end
|
2011-05-15 07:55:52 -04:00
|
|
|
|
2012-01-09 20:41:15 -05:00
|
|
|
with_temp_stdio do |stdin, stdout|
|
2009-07-10 08:13:18 -04:00
|
|
|
actual_text = nil
|
|
|
|
actual_line_buffer = nil
|
|
|
|
actual_point = nil
|
2011-12-23 16:59:54 -05:00
|
|
|
Readline.completion_proc = ->(text) {
|
2009-07-10 08:13:18 -04:00
|
|
|
actual_text = text
|
|
|
|
actual_point = Readline.point
|
2011-12-23 16:59:54 -05:00
|
|
|
actual_line_buffer = Readline.line_buffer
|
2009-07-10 08:13:18 -04:00
|
|
|
stdin.write(" finish\n")
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-20 19:03:52 -04:00
|
|
|
stdin.flush
|
|
|
|
stdout.flush
|
2009-07-10 08:13:18 -04:00
|
|
|
return ["complete"]
|
|
|
|
}
|
2011-12-23 16:59:54 -05:00
|
|
|
|
|
|
|
stdin.write("first second\t")
|
|
|
|
stdin.flush
|
|
|
|
Readline.completion_append_character = " "
|
|
|
|
line = replace_stdio(stdin.path, stdout.path) {
|
|
|
|
Readline.readline("> ", false)
|
|
|
|
}
|
|
|
|
assert_equal("second", actual_text)
|
|
|
|
assert_equal("first second", actual_line_buffer)
|
|
|
|
assert_equal(12, actual_point)
|
|
|
|
assert_equal("first complete finish", Readline.line_buffer)
|
|
|
|
assert_equal(Encoding.find("locale"), Readline.line_buffer.encoding)
|
|
|
|
assert_equal(true, Readline.line_buffer.tainted?)
|
|
|
|
assert_equal(22, Readline.point)
|
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-20 19:03:52 -04:00
|
|
|
stdin.rewind
|
|
|
|
stdout.rewind
|
2011-12-23 16:59:54 -05:00
|
|
|
|
2009-07-10 08:13:18 -04:00
|
|
|
stdin.write("first second\t")
|
|
|
|
stdin.flush
|
2011-12-23 16:59:54 -05:00
|
|
|
Readline.completion_append_character = nil
|
2009-07-10 08:13:18 -04:00
|
|
|
line = replace_stdio(stdin.path, stdout.path) {
|
|
|
|
Readline.readline("> ", false)
|
|
|
|
}
|
2011-12-23 16:59:54 -05:00
|
|
|
assert_equal("second", actual_text)
|
2009-07-10 08:13:18 -04:00
|
|
|
assert_equal("first second", actual_line_buffer)
|
|
|
|
assert_equal(12, actual_point)
|
|
|
|
assert_equal("first complete finish", Readline.line_buffer)
|
2010-09-05 21:38:51 -04:00
|
|
|
assert_equal(Encoding.find("locale"), Readline.line_buffer.encoding)
|
|
|
|
assert_equal(true, Readline.line_buffer.tainted?)
|
2009-07-10 08:13:18 -04:00
|
|
|
assert_equal(21, Readline.point)
|
2004-11-18 01:12:12 -05:00
|
|
|
end
|
|
|
|
end
|
2009-07-10 08:13:18 -04:00
|
|
|
end
|
2008-08-11 03:58:02 -04:00
|
|
|
|
|
|
|
def test_input=
|
|
|
|
assert_raise(TypeError) do
|
|
|
|
Readline.input = "This is not a file."
|
|
|
|
end
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2008-08-11 03:58:02 -04:00
|
|
|
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
|
2004-11-18 01:12:12 -05:00
|
|
|
end
|
|
|
|
|
2012-01-09 20:41:15 -05:00
|
|
|
def test_completion_proc_empty_result
|
|
|
|
with_temp_stdio do |stdin, stdout|
|
|
|
|
stdin.write("first\t")
|
|
|
|
stdin.flush
|
|
|
|
Readline.completion_proc = ->(text) {[]}
|
2012-01-11 08:46:32 -05:00
|
|
|
line1 = line2 = nil
|
2012-01-09 20:45:09 -05:00
|
|
|
replace_stdio(stdin.path, stdout.path) {
|
2012-01-11 08:46:32 -05:00
|
|
|
assert_nothing_raised(NoMemoryError) {line1 = Readline.readline("> ")}
|
|
|
|
stdin.write("\n")
|
|
|
|
stdin.flush
|
|
|
|
assert_nothing_raised(NoMemoryError) {line2 = Readline.readline("> ")}
|
2012-01-09 20:41:15 -05:00
|
|
|
}
|
2012-01-11 08:46:32 -05:00
|
|
|
assert_equal("first", line1)
|
|
|
|
assert_equal("", line2)
|
|
|
|
begin
|
|
|
|
assert_equal("", Readline.line_buffer)
|
|
|
|
rescue NotimplementedError
|
|
|
|
end
|
2012-01-09 20:41:15 -05:00
|
|
|
end
|
2012-04-08 02:26:48 -04:00
|
|
|
end if !/EditLine/n.match(Readline::VERSION)
|
2012-01-09 20:41:15 -05:00
|
|
|
|
2009-02-03 07:21:08 -05:00
|
|
|
def test_get_screen_size
|
|
|
|
begin
|
|
|
|
res = Readline.get_screen_size
|
|
|
|
assert(res.is_a?(Array))
|
|
|
|
rows, columns = *res
|
|
|
|
assert(rows.is_a?(Integer))
|
|
|
|
assert(rows >= 0)
|
|
|
|
assert(columns.is_a?(Integer))
|
|
|
|
assert(columns >= 0)
|
|
|
|
rescue NotImplementedError
|
|
|
|
end
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2008-08-11 04:31:45 -04:00
|
|
|
# vi_editing_mode
|
|
|
|
# emacs_editing_mode
|
|
|
|
def test_editing_mode
|
|
|
|
begin
|
|
|
|
assert_equal(false, Readline.vi_editing_mode?)
|
|
|
|
assert_equal(true, Readline.emacs_editing_mode?)
|
|
|
|
|
|
|
|
assert_equal(nil, Readline.vi_editing_mode)
|
|
|
|
assert_equal(true, Readline.vi_editing_mode?)
|
|
|
|
assert_equal(false, Readline.emacs_editing_mode?)
|
|
|
|
assert_equal(nil, Readline.vi_editing_mode)
|
|
|
|
assert_equal(true, Readline.vi_editing_mode?)
|
|
|
|
assert_equal(false, Readline.emacs_editing_mode?)
|
|
|
|
|
|
|
|
assert_equal(nil, Readline.emacs_editing_mode)
|
|
|
|
assert_equal(false, Readline.vi_editing_mode?)
|
|
|
|
assert_equal(true, Readline.emacs_editing_mode?)
|
|
|
|
assert_equal(nil, Readline.emacs_editing_mode)
|
|
|
|
assert_equal(false, Readline.vi_editing_mode?)
|
|
|
|
assert_equal(true, Readline.emacs_editing_mode?)
|
|
|
|
rescue NotImplementedError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-11-18 20:38:38 -05:00
|
|
|
def test_completion_append_character
|
2005-05-19 10:36:20 -04:00
|
|
|
begin
|
2008-12-20 23:51:43 -05:00
|
|
|
enc = get_default_internal_encoding
|
2008-12-12 11:13:11 -05:00
|
|
|
data_expected = [
|
|
|
|
["x", "x"],
|
|
|
|
["xyx", "x"],
|
|
|
|
[" ", " "],
|
|
|
|
["\t", "\t"],
|
|
|
|
]
|
|
|
|
data_expected.each do |(data, expected)|
|
|
|
|
Readline.completion_append_character = data
|
|
|
|
assert_equal(expected, Readline.completion_append_character)
|
|
|
|
assert_equal(enc, Readline.completion_append_character.encoding)
|
|
|
|
end
|
2005-05-19 10:36:20 -04:00
|
|
|
Readline.completion_append_character = ""
|
|
|
|
assert_equal(nil, Readline.completion_append_character)
|
|
|
|
rescue NotImplementedError
|
|
|
|
end
|
2004-11-18 20:38:38 -05:00
|
|
|
end
|
|
|
|
|
2012-01-28 22:18:11 -05:00
|
|
|
def test_completion_encoding
|
|
|
|
bug5941 = '[Bug #5941]'
|
2012-01-30 00:37:28 -05:00
|
|
|
append_character = Readline.completion_append_character
|
|
|
|
Readline.completion_append_character = ""
|
2012-01-28 22:18:11 -05:00
|
|
|
completion_case_fold = Readline.completion_case_fold
|
2012-01-30 00:37:28 -05:00
|
|
|
locale = Encoding.find("locale")
|
|
|
|
if locale == Encoding::UTF_8
|
2012-01-28 22:18:11 -05:00
|
|
|
enc1 = Encoding::EUC_JP
|
2012-01-29 09:24:05 -05:00
|
|
|
else
|
2012-01-30 00:37:28 -05:00
|
|
|
enc1 = Encoding::UTF_8
|
2012-01-28 22:18:11 -05:00
|
|
|
end
|
|
|
|
results = nil
|
|
|
|
Readline.completion_proc = ->(text) {results}
|
|
|
|
|
2012-01-30 00:37:28 -05:00
|
|
|
[%W"\u{3042 3042} \u{3042 3044}", %W"\u{fe5b fe5b} \u{fe5b fe5c}"].any? do |w|
|
|
|
|
begin
|
|
|
|
results = w.map {|s| s.encode(locale)}
|
|
|
|
rescue Encoding::UndefinedConversionError
|
|
|
|
end
|
|
|
|
end or
|
|
|
|
begin
|
|
|
|
"\xa1\xa2".encode(Encoding::UTF_8, locale)
|
|
|
|
rescue
|
|
|
|
else
|
|
|
|
results = %W"\xa1\xa1 \xa1\xa2".map {|s| s.force_encoding(locale)}
|
|
|
|
end or
|
2013-04-17 01:20:18 -04:00
|
|
|
begin
|
|
|
|
return if assert_under_utf8
|
2012-01-30 00:37:28 -05:00
|
|
|
skip("missing test for locale #{locale.name}")
|
2013-04-17 01:20:18 -04:00
|
|
|
end
|
2012-01-30 00:37:28 -05:00
|
|
|
expected = results[0][0...1]
|
2012-01-28 22:18:11 -05:00
|
|
|
Readline.completion_case_fold = false
|
2012-01-30 00:37:28 -05:00
|
|
|
assert_equal(expected, with_pipe {|r, w| w << "\t"}, bug5941)
|
|
|
|
Readline.completion_case_fold = true
|
|
|
|
assert_equal(expected, with_pipe {|r, w| w << "\t"}, bug5941)
|
|
|
|
results.map! {|s| s.encode(enc1)}
|
|
|
|
assert_raise(Encoding::CompatibilityError, bug5941) do
|
|
|
|
with_pipe {|r, w| w << "\t"}
|
|
|
|
end
|
2012-01-28 22:18:11 -05:00
|
|
|
ensure
|
|
|
|
Readline.completion_case_fold = completion_case_fold
|
2012-01-30 00:37:28 -05:00
|
|
|
Readline.completion_append_character = append_character
|
2012-04-08 02:26:48 -04:00
|
|
|
end if !/EditLine/n.match(Readline::VERSION)
|
2012-01-28 22:18:11 -05:00
|
|
|
|
2008-08-11 03:58:02 -04:00
|
|
|
# basic_word_break_characters
|
|
|
|
# completer_word_break_characters
|
|
|
|
# basic_quote_characters
|
|
|
|
# completer_quote_characters
|
|
|
|
# filename_quote_characters
|
2012-05-01 20:47:57 -04:00
|
|
|
# special_prefixes
|
2008-08-11 03:58:02 -04:00
|
|
|
def test_some_characters_methods
|
|
|
|
method_names = [
|
|
|
|
"basic_word_break_characters",
|
|
|
|
"completer_word_break_characters",
|
|
|
|
"basic_quote_characters",
|
|
|
|
"completer_quote_characters",
|
|
|
|
"filename_quote_characters",
|
2012-05-01 20:47:57 -04:00
|
|
|
"special_prefixes",
|
2008-08-11 03:58:02 -04:00
|
|
|
]
|
|
|
|
method_names.each do |method_name|
|
|
|
|
begin
|
|
|
|
begin
|
2008-12-20 23:51:43 -05:00
|
|
|
enc = get_default_internal_encoding
|
2008-08-11 03:58:02 -04:00
|
|
|
saved = Readline.send(method_name.to_sym)
|
|
|
|
expecteds = [" ", " .,|\t", ""]
|
|
|
|
expecteds.each do |e|
|
|
|
|
Readline.send((method_name + "=").to_sym, e)
|
2008-12-20 23:51:43 -05:00
|
|
|
res = Readline.send(method_name.to_sym)
|
|
|
|
assert_equal(e, res)
|
|
|
|
assert_equal(enc, res.encoding)
|
2008-08-11 03:58:02 -04:00
|
|
|
end
|
|
|
|
ensure
|
|
|
|
Readline.send((method_name + "=").to_sym, saved) if saved
|
|
|
|
end
|
|
|
|
rescue NotImplementedError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-23 20:56:36 -05:00
|
|
|
def test_closed_outstream
|
|
|
|
bug5803 = '[ruby-dev:45043]'
|
|
|
|
IO.pipe do |r, w|
|
|
|
|
Readline.input = r
|
|
|
|
Readline.output = w
|
|
|
|
(w << "##\t").close
|
|
|
|
assert_raise(IOError, bug5803) {Readline.readline}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-05-01 09:21:55 -04:00
|
|
|
def test_pre_input_hook
|
|
|
|
begin
|
|
|
|
pr = proc {}
|
2012-06-17 11:38:22 -04:00
|
|
|
Readline.pre_input_hook = pr
|
|
|
|
assert_equal(pr, Readline.pre_input_hook)
|
|
|
|
Readline.pre_input_hook = nil
|
|
|
|
assert_nil(Readline.pre_input_hook)
|
2012-05-01 09:21:55 -04:00
|
|
|
rescue NotImplementedError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-06 08:52:22 -04:00
|
|
|
def test_point
|
|
|
|
assert_equal(0, Readline.point)
|
|
|
|
Readline.insert_text('12345')
|
|
|
|
assert_equal(5, Readline.point)
|
|
|
|
|
|
|
|
assert_equal(4, Readline.point=(4))
|
2013-08-06 08:56:12 -04:00
|
|
|
|
2013-08-06 08:52:22 -04:00
|
|
|
Readline.insert_text('abc')
|
|
|
|
assert_equal(7, Readline.point)
|
|
|
|
|
|
|
|
assert_equal('1234abc5', Readline.line_buffer)
|
|
|
|
rescue NotImplementedError
|
|
|
|
end if !/EditLine/n.match(Readline::VERSION)
|
|
|
|
|
2012-05-01 09:21:55 -04:00
|
|
|
def test_insert_text
|
2013-07-23 14:00:26 -04:00
|
|
|
str = "test_insert_text"
|
|
|
|
assert_equal(0, Readline.point)
|
|
|
|
assert_equal(Readline, Readline.insert_text(str))
|
|
|
|
assert_equal(str, Readline.line_buffer)
|
|
|
|
assert_equal(16, Readline.point)
|
|
|
|
assert_equal(get_default_internal_encoding,
|
|
|
|
Readline.line_buffer.encoding)
|
|
|
|
|
|
|
|
Readline.delete_text(1, 3)
|
|
|
|
assert_equal("t_insert_text", Readline.line_buffer)
|
|
|
|
Readline.delete_text(11)
|
|
|
|
assert_equal("t_insert_te", Readline.line_buffer)
|
|
|
|
Readline.delete_text(-3...-1)
|
|
|
|
assert_equal("t_inserte", Readline.line_buffer)
|
|
|
|
Readline.delete_text(-3..-1)
|
|
|
|
assert_equal("t_inse", Readline.line_buffer)
|
|
|
|
Readline.delete_text(3..-3)
|
|
|
|
assert_equal("t_ise", Readline.line_buffer)
|
|
|
|
Readline.delete_text(3, 1)
|
|
|
|
assert_equal("t_ie", Readline.line_buffer)
|
|
|
|
Readline.delete_text(1..1)
|
|
|
|
assert_equal("tie", Readline.line_buffer)
|
|
|
|
Readline.delete_text(1...2)
|
|
|
|
assert_equal("te", Readline.line_buffer)
|
|
|
|
Readline.delete_text
|
|
|
|
assert_equal("", Readline.line_buffer)
|
|
|
|
rescue NotImplementedError
|
|
|
|
end if !/EditLine/n.match(Readline::VERSION)
|
|
|
|
|
|
|
|
def test_delete_text
|
2013-08-06 09:07:25 -04:00
|
|
|
str = "test_insert_text"
|
|
|
|
assert_equal(0, Readline.point)
|
|
|
|
assert_equal(Readline, Readline.insert_text(str))
|
|
|
|
assert_equal(16, Readline.point)
|
|
|
|
assert_equal(str, Readline.line_buffer)
|
|
|
|
Readline.delete_text
|
2013-07-23 14:00:26 -04:00
|
|
|
|
2013-08-06 09:07:25 -04:00
|
|
|
# NOTE: unexpected but GNU Readline's spec
|
|
|
|
assert_equal(16, Readline.point)
|
|
|
|
assert_equal("", Readline.line_buffer)
|
|
|
|
assert_equal(Readline, Readline.insert_text(str))
|
|
|
|
assert_equal(32, Readline.point)
|
|
|
|
assert_equal("", Readline.line_buffer)
|
2013-07-23 14:00:26 -04:00
|
|
|
rescue NotImplementedError
|
2012-05-01 09:21:55 -04:00
|
|
|
end if !/EditLine/n.match(Readline::VERSION)
|
|
|
|
|
|
|
|
def test_modify_text_in_pre_input_hook
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-20 19:03:52 -04:00
|
|
|
with_temp_stdio {|stdin, stdout|
|
2012-05-01 09:21:55 -04:00
|
|
|
begin
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-20 19:03:52 -04:00
|
|
|
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
|
2012-05-01 09:21:55 -04:00
|
|
|
rescue NotImplementedError
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-20 19:03:52 -04:00
|
|
|
ensure
|
|
|
|
begin
|
|
|
|
Readline.pre_input_hook = nil
|
|
|
|
rescue NotImplementedError
|
|
|
|
end
|
2012-05-01 09:21:55 -04:00
|
|
|
end
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-20 19:03:52 -04:00
|
|
|
}
|
2012-06-18 23:05:54 -04:00
|
|
|
end if !/EditLine|\A4\.3\z/n.match(Readline::VERSION)
|
2012-05-01 09:21:55 -04:00
|
|
|
|
2012-06-17 21:43:00 -04:00
|
|
|
def test_input_metachar
|
|
|
|
bug6601 = '[ruby-core:45682]'
|
|
|
|
Readline::HISTORY << "hello"
|
|
|
|
wo = nil
|
|
|
|
line = with_pipe do |r, w|
|
|
|
|
wo = w.dup
|
|
|
|
wo.write("\C-re\ef\n")
|
|
|
|
end
|
|
|
|
assert_equal("hello", line, bug6601)
|
|
|
|
ensure
|
|
|
|
wo.close
|
2013-07-21 20:37:10 -04:00
|
|
|
Readline.delete_text
|
2012-06-17 21:43:00 -04:00
|
|
|
Readline::HISTORY.clear
|
2012-06-18 22:58:40 -04:00
|
|
|
end if !/EditLine/n.match(Readline::VERSION)
|
2012-06-17 21:43:00 -04:00
|
|
|
|
2012-06-19 00:15:37 -04:00
|
|
|
def test_input_metachar_multibyte
|
2013-04-17 01:20:18 -04:00
|
|
|
unless Encoding.find("locale") == Encoding::UTF_8
|
|
|
|
return if assert_under_utf8
|
|
|
|
skip 'this test needs UTF-8 locale'
|
|
|
|
end
|
2012-06-19 00:15:37 -04:00
|
|
|
bug6602 = '[ruby-core:45683]'
|
|
|
|
Readline::HISTORY << "\u3042\u3093"
|
|
|
|
Readline::HISTORY << "\u3044\u3093"
|
|
|
|
Readline::HISTORY << "\u3046\u3093"
|
|
|
|
open(IO::NULL, 'w') do |null|
|
|
|
|
IO.pipe do |r, w|
|
|
|
|
Readline.input = r
|
|
|
|
Readline.output = null
|
|
|
|
w << "\cr\u3093\n\n"
|
|
|
|
w << "\cr\u3042\u3093"
|
|
|
|
w.reopen(IO::NULL)
|
|
|
|
assert_equal("\u3046\u3093", Readline.readline("", true), bug6602)
|
2013-07-23 12:20:03 -04:00
|
|
|
Timeout.timeout(2) do
|
2013-07-23 12:17:58 -04:00
|
|
|
assert_equal("\u3042\u3093", Readline.readline("", true), bug6602)
|
|
|
|
end
|
2012-06-19 00:15:37 -04:00
|
|
|
assert_equal(nil, Readline.readline("", true), bug6602)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
ensure
|
2013-07-21 20:37:10 -04:00
|
|
|
Readline.delete_text
|
2012-06-19 00:15:37 -04:00
|
|
|
Readline::HISTORY.clear
|
|
|
|
end if !/EditLine/n.match(Readline::VERSION)
|
|
|
|
|
2015-01-14 01:43:50 -05:00
|
|
|
def test_refresh_line
|
|
|
|
bug6232 = '[ruby-core:43957] [Bug #6232] refresh_line after set_screen_size'
|
|
|
|
with_temp_stdio do |stdin, stdout|
|
|
|
|
replace_stdio(stdin.path, stdout.path) do
|
|
|
|
assert_ruby_status(%w[-rreadline -], <<-'end;', bug6232)
|
|
|
|
Readline.set_screen_size(40, 80)
|
|
|
|
Readline.refresh_line
|
|
|
|
end;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end if Readline.respond_to?(:refresh_line)
|
|
|
|
|
2004-11-18 01:12:12 -05:00
|
|
|
private
|
|
|
|
|
2004-12-01 20:54:13 -05:00
|
|
|
def replace_stdio(stdin_path, stdout_path)
|
2005-09-22 04:33:05 -04:00
|
|
|
open(stdin_path, "r"){|stdin|
|
|
|
|
open(stdout_path, "w"){|stdout|
|
|
|
|
orig_stdin = STDIN.dup
|
|
|
|
orig_stdout = STDOUT.dup
|
2012-04-26 21:41:02 -04:00
|
|
|
orig_stderr = STDERR.dup
|
2005-09-22 04:33:05 -04:00
|
|
|
STDIN.reopen(stdin)
|
|
|
|
STDOUT.reopen(stdout)
|
2012-04-26 21:41:02 -04:00
|
|
|
STDERR.reopen(stdout)
|
2005-09-22 04:33:05 -04:00
|
|
|
begin
|
|
|
|
Readline.input = STDIN
|
|
|
|
Readline.output = STDOUT
|
|
|
|
yield
|
|
|
|
ensure
|
2012-04-26 21:41:02 -04:00
|
|
|
STDERR.reopen(orig_stderr)
|
2005-09-22 04:33:05 -04:00
|
|
|
STDIN.reopen(orig_stdin)
|
|
|
|
STDOUT.reopen(orig_stdout)
|
|
|
|
orig_stdin.close
|
|
|
|
orig_stdout.close
|
2014-05-29 10:47:28 -04:00
|
|
|
orig_stderr.close
|
2005-09-22 04:33:05 -04:00
|
|
|
end
|
|
|
|
}
|
|
|
|
}
|
2004-11-18 01:12:12 -05:00
|
|
|
end
|
2008-12-20 23:51:43 -05:00
|
|
|
|
2012-01-09 20:41:15 -05:00
|
|
|
def with_temp_stdio
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-20 19:03:52 -04:00
|
|
|
Tempfile.create("test_readline_stdin") {|stdin|
|
|
|
|
Tempfile.create("test_readline_stdout") {|stdout|
|
|
|
|
yield stdin, stdout
|
|
|
|
}
|
|
|
|
}
|
2012-01-09 20:41:15 -05:00
|
|
|
end
|
|
|
|
|
2012-01-28 22:18:11 -05:00
|
|
|
def with_pipe
|
2012-04-26 21:41:02 -04:00
|
|
|
stderr = nil
|
2012-01-28 22:18:11 -05:00
|
|
|
IO.pipe do |r, w|
|
|
|
|
yield(r, w)
|
|
|
|
Readline.input = r
|
|
|
|
Readline.output = w.reopen(IO::NULL)
|
2012-04-26 21:41:02 -04:00
|
|
|
stderr = STDERR.dup
|
|
|
|
STDERR.reopen(w)
|
2012-01-28 22:18:11 -05:00
|
|
|
Readline.readline
|
|
|
|
end
|
|
|
|
ensure
|
2012-04-26 21:41:02 -04:00
|
|
|
if stderr
|
|
|
|
STDERR.reopen(stderr)
|
|
|
|
stderr.close
|
|
|
|
end
|
2012-01-28 22:18:11 -05:00
|
|
|
Readline.input = STDIN
|
|
|
|
Readline.output = STDOUT
|
|
|
|
end
|
|
|
|
|
2008-12-20 23:51:43 -05:00
|
|
|
def get_default_internal_encoding
|
|
|
|
return Encoding.default_internal || Encoding.find("locale")
|
|
|
|
end
|
2013-04-17 01:20:18 -04:00
|
|
|
|
|
|
|
def assert_under_utf8
|
|
|
|
return false if ENV['LC_ALL'] == 'UTF-8'
|
|
|
|
loc = caller_locations(1, 1)[0].base_label.to_s
|
|
|
|
assert_separately([{"LC_ALL"=>"UTF-8"}, "-r", __FILE__], <<SRC)
|
|
|
|
#skip "test \#{ENV['LC_ALL']}"
|
|
|
|
#{self.class.name}.new(#{loc.dump}).run(Test::Unit::Runner.new)
|
|
|
|
SRC
|
|
|
|
return true
|
|
|
|
end
|
2008-08-11 03:58:02 -04:00
|
|
|
end if defined?(::Readline)
|