зеркало из https://github.com/github/ruby.git
Extract ext/readline
This commit is contained in:
Родитель
5831f7c831
Коммит
59fd67fc3d
|
@ -1 +0,0 @@
|
|||
/readline-[1-9]*.*
|
|
@ -1,10 +0,0 @@
|
|||
The Readline module provides interface for GNU Readline.
|
||||
This module defines a number of methods to facilitate completion
|
||||
and accesses input history from the Ruby interpreter.
|
||||
This module supported Edit Line(libedit) too.
|
||||
libedit is compatible with GNU Readline.
|
||||
|
||||
GNU Readline:: http://www.gnu.org/directory/readline.html
|
||||
libedit:: http://www.thrysoee.dk/editline/
|
||||
|
||||
See RDoc for Readline module.
|
|
@ -1,386 +0,0 @@
|
|||
GNU Readline によるコマンドライン入力インタフェースを提供するモジュール
|
||||
です。GNU Readline の互換ライブラリのひとつである Edit Line(libedit) も
|
||||
サポートしています。
|
||||
|
||||
GNU Readline:: http://www.gnu.org/directory/readline.html
|
||||
libedit:: http://www.thrysoee.dk/editline/
|
||||
|
||||
Readline.readline を使用してユーザからの入力を取得できます。このとき、
|
||||
GNU Readline のように入力の補完やEmacs のようなキー操作などができます。
|
||||
|
||||
require "readline"
|
||||
while buf = Readline.readline("> ", true)
|
||||
p buf
|
||||
end
|
||||
|
||||
ユーザが入力した内容を履歴(以下、ヒストリ)として記録することができます。
|
||||
定数 Readline::HISTORY を使用してヒストリにアクセスできます。
|
||||
|
||||
require "readline"
|
||||
while buf = Readline.readline("> ", true)
|
||||
p Readline::HISTORY.to_a
|
||||
print("-> ", buf, "\n")
|
||||
end
|
||||
|
||||
使用するライブラリにより、いくつかのメソッドで例外 NotImplementedError
|
||||
が発生します。
|
||||
|
||||
== Readline モジュール
|
||||
|
||||
=== モジュール関数
|
||||
|
||||
readline([prompt, [add_hist]]) -> String | nil
|
||||
|
||||
prompt を出力し、ユーザからのキー入力を待ちます。
|
||||
エンターキーの押下などでユーザが文字列を入力し終えると、
|
||||
入力した文字列を返します。
|
||||
このとき、add_hist が true であれば、入力した文字列をヒストリに追加します。
|
||||
|
||||
何も入力していない状態で EOF(UNIX では ^D) を入力するなどで、
|
||||
ユーザからの入力がない場合は nil を返します。
|
||||
|
||||
次の条件を全て満たす場合、例外 IOError が発生します。
|
||||
1. 標準入力が tty でない。
|
||||
2. 標準入力をクローズしている。(isatty(2) の errno が EBADF である。)
|
||||
|
||||
本メソッドはスレッドに対応しています。
|
||||
入力待ち状態のときはスレッドコンテキストの切替えが発生します。
|
||||
|
||||
入力時には行内編集が可能で、vi モードと Emacs モードが用意されています。
|
||||
デフォルトは Emacs モードです。
|
||||
|
||||
本メソッドには注意事項があります。
|
||||
入力待ちの状態で ^C すると ruby インタプリタが終了し、端末状態を復帰しません。
|
||||
これを回避するための例を3つ挙げます。
|
||||
|
||||
* ^CによるInterrupt例外を補足して、端末状態を復帰します:
|
||||
|
||||
require "readline"
|
||||
|
||||
stty_save = `stty -g`.chomp
|
||||
begin
|
||||
while buf = Readline.readline
|
||||
p buf
|
||||
end
|
||||
rescue Interrupt
|
||||
system("stty", stty_save)
|
||||
exit
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
* INTシグナルを補足して、端末状態を復帰します:
|
||||
|
||||
require "readline"
|
||||
|
||||
stty_save = `stty -g`.chomp
|
||||
trap("INT") { system "stty", stty_save; exit }
|
||||
|
||||
while buf = Readline.readline
|
||||
p buf
|
||||
end
|
||||
|
||||
* 単に ^C を無視する方法もあります:
|
||||
|
||||
require "readline"
|
||||
|
||||
trap("INT", "SIG_IGN")
|
||||
|
||||
while buf = Readline.readline
|
||||
p buf
|
||||
end
|
||||
|
||||
入力履歴 Readline::HISTORY を使用して、空行や直前の入力と同じ内容は入力
|
||||
履歴に残さないということもできます。
|
||||
|
||||
require "readline"
|
||||
|
||||
while buf = Readline.readline("> ", true)
|
||||
# p Readline::HISTORY.to_a
|
||||
Readline::HISTORY.pop if /^\s*$/ =~ buf
|
||||
|
||||
begin
|
||||
if Readline::HISTORY[Readline::HISTORY.length-2] == buf
|
||||
Readline::HISTORY.pop
|
||||
end
|
||||
rescue IndexError
|
||||
end
|
||||
|
||||
# p Readline::HISTORY.to_a
|
||||
print "-> ", buf, "\n"
|
||||
end
|
||||
|
||||
=== クラスメソッド
|
||||
|
||||
Readline.input = input
|
||||
|
||||
Readline.readline メソッドで使用する入力用の File オブジェクト input
|
||||
を指定します。
|
||||
|
||||
Readline.output = output
|
||||
|
||||
Readline.readline メソッドで使用する出力用の File オブジェクト
|
||||
output を指定します。
|
||||
|
||||
Readline.completion_proc = proc
|
||||
|
||||
ユーザからの入力を補完する時の候補を取得する Proc オブジェクト proc を
|
||||
指定します。proc は、次のものを想定しています。
|
||||
1. call メソッドを持ちます。
|
||||
call メソッドを持たない場合、例外 ArgumentError が発生します。
|
||||
2. 引数にユーザからの入力文字列(注1)を取ります。
|
||||
3. 候補の文字列の配列を返します。
|
||||
|
||||
注1:「/var/lib /v」の後で補完を行うと、
|
||||
デフォルトでは proc の引数に「/v」が渡されます。
|
||||
このように、ユーザが入力した文字列を
|
||||
Readline.completer_word_break_characters に含まれる文字で区切ったも
|
||||
のを単語とすると、カーソルがある単語の最初の文字から現在のカーソル位
|
||||
置までの文字列が proc の引数に渡されます。
|
||||
|
||||
Readline.completion_proc -> proc
|
||||
|
||||
ユーザからの入力を補完する時の候補を取得する Proc オブジェクト proc
|
||||
を取得します。
|
||||
|
||||
Readline.completion_case_fold = bool
|
||||
|
||||
ユーザの入力を補完する際、大文字と小文字を区別する/しないを指定します。
|
||||
bool が真ならば区別しません。bool が偽ならば区別します。
|
||||
|
||||
Readline.completion_case_fold -> bool
|
||||
|
||||
ユーザの入力を補完する際、大文字と小文字を区別する/しないを取得します。
|
||||
bool が真ならば区別しません。bool が偽ならば区別します。
|
||||
|
||||
なお、Readline.completion_case_fold= メソッドで指定したオブジェクトを
|
||||
そのまま取得するので、次のような動作をします。
|
||||
|
||||
require "readline"
|
||||
|
||||
Readline.completion_case_fold = "This is a String."
|
||||
p Readline.completion_case_fold # => "This is a String."
|
||||
|
||||
Readline.line_buffer -> string
|
||||
|
||||
入力中の行全体を返します。complete_proc の中で使用することを想定し
|
||||
ています。Readline.line_buffer の長さは GNU Readline の rl_end 変数の
|
||||
値と一致します。
|
||||
|
||||
Readline.point -> int
|
||||
|
||||
現在のカーソルの位置を返します。
|
||||
Readline モジュールは補完対象の単語の開始位置の情報を提供していません。
|
||||
しかしながら、 completion_proc の中で入力した単語 text と
|
||||
Readline.point を使用することで開始位置を導くことができます。
|
||||
|
||||
開始位置 = 入力した単語の長さ - Readline.point
|
||||
|
||||
Readline.vi_editing_mode -> nil
|
||||
|
||||
編集モードを vi モードにします。
|
||||
vi モードの詳細は、GNU Readline のマニュアルを参照してください。
|
||||
|
||||
サポートしていない環境では、例外 NotImplementedError が発生します。
|
||||
|
||||
Readline.vi_editing_mode? -> bool
|
||||
|
||||
編集モードが vi モードの場合、true を返します。そうでなければ false
|
||||
を返します。
|
||||
|
||||
サポートしていない環境では、例外 NotImplementedError が発生します。
|
||||
|
||||
Readline.emacs_editing_mode -> nil
|
||||
|
||||
編集モードを Emacs モードにします。
|
||||
デフォルトは Emacs モードです。
|
||||
Emacs モードの詳細は、GNU Readline のマニュアルを参照してください。
|
||||
|
||||
サポートしていない環境では、例外 NotImplementedError が発生します。
|
||||
|
||||
Readline.emacs_editing_mode? -> bool
|
||||
|
||||
編集モードが Emacs モードの場合、true を返します。そうでなければ false
|
||||
を返します。
|
||||
|
||||
サポートしていない環境では、例外 NotImplementedError が発生します。
|
||||
|
||||
Readline.completion_append_character = char
|
||||
|
||||
ユーザの入力の補完が完了した場合に、最後に付加する文字 char を指定し
|
||||
ます。半角スペース「" "」などの単語を区切る文字を指定すれば、連続して
|
||||
入力する際に便利です。
|
||||
|
||||
使用例:
|
||||
|
||||
require "readline"
|
||||
|
||||
Readline.readline("> ", true)
|
||||
Readline.completion_append_character = " "
|
||||
|
||||
実行例:
|
||||
|
||||
>
|
||||
ここで "/var/li" を入力します。
|
||||
|
||||
> /var/li
|
||||
ここで TAB キーを入力します。
|
||||
|
||||
> /var/lib
|
||||
"b" が補完され、最後に " " が追加されるので、"/usr" を連続して入力できます。
|
||||
|
||||
> /var/lib /usr
|
||||
|
||||
なお、1文字しか指定することはできません。
|
||||
例えば、"string"を指定した場合は最初の文字である"s"だけを使用します。
|
||||
|
||||
require "readline"
|
||||
|
||||
Readline.completion_append_character = "string"
|
||||
p Readline.completion_append_character # => "s"
|
||||
|
||||
サポートしていない環境では、例外 NotImplementedError が発生します。
|
||||
|
||||
Readline.completion_append_character -> char
|
||||
|
||||
ユーザの入力の補完が完了した場合に、最後に付加する文字を取得します。
|
||||
デフォルトは空白 (" ") です。
|
||||
|
||||
サポートしていない環境では、例外 NotImplementedError が発生します。
|
||||
|
||||
Readline.basic_word_break_characters = string
|
||||
|
||||
ユーザの入力の補完を行う際、単語の区切りを示す複数の文字で構成される
|
||||
文字列 string を指定します。
|
||||
|
||||
GNU Readline のデフォルトの値は、Bash の補完処理で使用している文字列
|
||||
" \t\n\"\\'`@$><=;|&{(" (スペースを含む) になっています。
|
||||
|
||||
サポートしていない環境では、例外 NotImplementedError が発生します。
|
||||
|
||||
Readline.basic_word_break_characters -> string
|
||||
|
||||
ユーザの入力の補完を行う際、単語の区切りを示す複数の文字で構成される
|
||||
文字列を取得します。
|
||||
|
||||
サポートしていない環境では、例外 NotImplementedError が発生します。
|
||||
|
||||
Readline.completer_word_break_characters = string
|
||||
|
||||
ユーザの入力の補完を行う際、単語の区切りを示す複数の文字で構成される
|
||||
文字列 string を指定します。
|
||||
Readline.basic_word_break_characters= との違いは、
|
||||
GNU Readline の rl_complete_internal 関数で使用されることです。
|
||||
|
||||
GNU Readline のデフォルトの値は、
|
||||
Readline.basic_word_break_characters と同じです。
|
||||
|
||||
サポートしていない環境では、例外 NotImplementedError が発生します。
|
||||
|
||||
Readline.completer_word_break_characters -> string
|
||||
|
||||
ユーザの入力の補完を行う際、単語の区切りを示す複数の文字で構成された
|
||||
文字列を取得します。
|
||||
|
||||
サポートしていない環境では、例外 NotImplementedError が発生します。
|
||||
|
||||
Readline.basic_quote_characters = string
|
||||
|
||||
スペースなどの単語の区切りをクオートするための複数の文字で構成される
|
||||
文字列 string を指定します。
|
||||
|
||||
サポートしていない環境では、例外 NotImplementedError が発生します。
|
||||
|
||||
Readline.basic_quote_characters -> string
|
||||
|
||||
スペースなどの単語の区切りをクオートするための複数の文字で構成される
|
||||
文字列を取得します。
|
||||
|
||||
サポートしていない環境では、例外 NotImplementedError が発生します。
|
||||
|
||||
Readline.completer_quote_characters = string
|
||||
|
||||
ユーザの入力の補完を行う際、スペースなどの単語の区切りを
|
||||
クオートするための複数の文字で構成される文字列 string を指定します。
|
||||
指定した文字の間では、Readline.completer_word_break_characters=
|
||||
で指定した文字列に含まれる文字も、普通の文字列として扱われます。
|
||||
|
||||
サポートしていない環境では、例外 NotImplementedError が発生します。
|
||||
|
||||
Readline.completer_quote_characters -> string
|
||||
|
||||
ユーザの入力の補完を行う際、スペースなどの単語の区切りを
|
||||
クオートするための複数の文字で構成される文字列を取得します。
|
||||
|
||||
サポートしていない環境では、例外 NotImplementedError が発生します。
|
||||
|
||||
Readline.filename_quote_characters = string
|
||||
|
||||
ユーザの入力時にファイル名の補完を行う際、スペースなどの単語の区切りを
|
||||
クオートするための複数の文字で構成される文字列 string を指定します。
|
||||
|
||||
GNU Readline のデフォルト値は nil です。
|
||||
|
||||
サポートしていない環境では、例外 NotImplementedError が発生します。
|
||||
|
||||
Readline.filename_quote_characters -> string
|
||||
|
||||
ユーザの入力時にファイル名の補完を行う際、スペースなどの単語の区切りを
|
||||
クオートするための複数の文字で構成される文字列を取得します。
|
||||
|
||||
サポートしていない環境では、例外 NotImplementedError が発生します。
|
||||
|
||||
=== クラス定数
|
||||
|
||||
HISTORY
|
||||
|
||||
定数 HISTORY を使用してヒストリにアクセスできます。
|
||||
Enumerable モジュールを extend しており、
|
||||
配列のように振る舞うことができます。
|
||||
例えば、HISTORY[4] により 5 番目に入力した内容を取り出すことができます。
|
||||
|
||||
require "readline"
|
||||
|
||||
Readline::HISTORY.push("a", "b", "c", "d", "e")
|
||||
p Readline::HISTORY[4] # => "e"
|
||||
|
||||
実装しているメソッドを次に挙げます。
|
||||
* HISTORY.to_s -> "HISTORY"
|
||||
* HISTORY[index] -> string
|
||||
* HISTORY[index] = string
|
||||
* HISTORY.push(string[, string, ...]) -> self
|
||||
* HISTORY << string -> self
|
||||
* HISTORY.pop -> string
|
||||
* HISTORY.shift -> string
|
||||
* HISTORY.each -> Enumerator
|
||||
* HISTORY.each { |i| } -> [string]
|
||||
* HISTORY.length -> Integer
|
||||
* HISTORY.empty? -> true or false
|
||||
* HISTORY.delete_at(index) -> string
|
||||
* HISTORY.clear -> self
|
||||
|
||||
サポートしていない環境では、次のメソッドで例外 NotImplementedError が
|
||||
発生します。
|
||||
* HISTORY[index] = string
|
||||
* HISTORY.pop -> string
|
||||
* HISTORY.shift -> string
|
||||
* HISTORY.delete_at(index) -> string
|
||||
* HISTORY.clear -> self
|
||||
|
||||
FILENAME_COMPLETION_PROC
|
||||
|
||||
ファイル名の補完を行う call メソッドを持つオブジェクトです。
|
||||
|
||||
Readline.completion_proc= により、ユーザの入力時にファイル名の補完を
|
||||
行うように設定するために使用することを想定してます。
|
||||
|
||||
USERNAME_COMPLETION_PROC
|
||||
|
||||
ユーザ名の補完を行う call メソッドを持つオブジェクトです。
|
||||
|
||||
Readline.completion_proc= により、ユーザの入力時にユーザ名の補完を行
|
||||
うように設定するために使用することを想定してます。
|
||||
|
||||
VERSION
|
||||
|
||||
使用している GNU Readline または libedit のバージョンです。
|
|
@ -1,174 +0,0 @@
|
|||
# AUTOGENERATED DEPENDENCIES START
|
||||
readline.o: $(RUBY_EXTCONF_H)
|
||||
readline.o: $(arch_hdrdir)/ruby/config.h
|
||||
readline.o: $(hdrdir)/ruby/assert.h
|
||||
readline.o: $(hdrdir)/ruby/backward.h
|
||||
readline.o: $(hdrdir)/ruby/backward/2/assume.h
|
||||
readline.o: $(hdrdir)/ruby/backward/2/attributes.h
|
||||
readline.o: $(hdrdir)/ruby/backward/2/bool.h
|
||||
readline.o: $(hdrdir)/ruby/backward/2/inttypes.h
|
||||
readline.o: $(hdrdir)/ruby/backward/2/limits.h
|
||||
readline.o: $(hdrdir)/ruby/backward/2/long_long.h
|
||||
readline.o: $(hdrdir)/ruby/backward/2/stdalign.h
|
||||
readline.o: $(hdrdir)/ruby/backward/2/stdarg.h
|
||||
readline.o: $(hdrdir)/ruby/defines.h
|
||||
readline.o: $(hdrdir)/ruby/encoding.h
|
||||
readline.o: $(hdrdir)/ruby/intern.h
|
||||
readline.o: $(hdrdir)/ruby/internal/abi.h
|
||||
readline.o: $(hdrdir)/ruby/internal/anyargs.h
|
||||
readline.o: $(hdrdir)/ruby/internal/arithmetic.h
|
||||
readline.o: $(hdrdir)/ruby/internal/arithmetic/char.h
|
||||
readline.o: $(hdrdir)/ruby/internal/arithmetic/double.h
|
||||
readline.o: $(hdrdir)/ruby/internal/arithmetic/fixnum.h
|
||||
readline.o: $(hdrdir)/ruby/internal/arithmetic/gid_t.h
|
||||
readline.o: $(hdrdir)/ruby/internal/arithmetic/int.h
|
||||
readline.o: $(hdrdir)/ruby/internal/arithmetic/intptr_t.h
|
||||
readline.o: $(hdrdir)/ruby/internal/arithmetic/long.h
|
||||
readline.o: $(hdrdir)/ruby/internal/arithmetic/long_long.h
|
||||
readline.o: $(hdrdir)/ruby/internal/arithmetic/mode_t.h
|
||||
readline.o: $(hdrdir)/ruby/internal/arithmetic/off_t.h
|
||||
readline.o: $(hdrdir)/ruby/internal/arithmetic/pid_t.h
|
||||
readline.o: $(hdrdir)/ruby/internal/arithmetic/short.h
|
||||
readline.o: $(hdrdir)/ruby/internal/arithmetic/size_t.h
|
||||
readline.o: $(hdrdir)/ruby/internal/arithmetic/st_data_t.h
|
||||
readline.o: $(hdrdir)/ruby/internal/arithmetic/uid_t.h
|
||||
readline.o: $(hdrdir)/ruby/internal/assume.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/alloc_size.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/artificial.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/cold.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/const.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/constexpr.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/deprecated.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/diagnose_if.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/enum_extensibility.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/error.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/flag_enum.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/forceinline.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/format.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/maybe_unused.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/noalias.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/nodiscard.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/noexcept.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/noinline.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/nonnull.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/noreturn.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/packed_struct.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/pure.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/restrict.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/returns_nonnull.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/warning.h
|
||||
readline.o: $(hdrdir)/ruby/internal/attr/weakref.h
|
||||
readline.o: $(hdrdir)/ruby/internal/cast.h
|
||||
readline.o: $(hdrdir)/ruby/internal/compiler_is.h
|
||||
readline.o: $(hdrdir)/ruby/internal/compiler_is/apple.h
|
||||
readline.o: $(hdrdir)/ruby/internal/compiler_is/clang.h
|
||||
readline.o: $(hdrdir)/ruby/internal/compiler_is/gcc.h
|
||||
readline.o: $(hdrdir)/ruby/internal/compiler_is/intel.h
|
||||
readline.o: $(hdrdir)/ruby/internal/compiler_is/msvc.h
|
||||
readline.o: $(hdrdir)/ruby/internal/compiler_is/sunpro.h
|
||||
readline.o: $(hdrdir)/ruby/internal/compiler_since.h
|
||||
readline.o: $(hdrdir)/ruby/internal/config.h
|
||||
readline.o: $(hdrdir)/ruby/internal/constant_p.h
|
||||
readline.o: $(hdrdir)/ruby/internal/core.h
|
||||
readline.o: $(hdrdir)/ruby/internal/core/rarray.h
|
||||
readline.o: $(hdrdir)/ruby/internal/core/rbasic.h
|
||||
readline.o: $(hdrdir)/ruby/internal/core/rbignum.h
|
||||
readline.o: $(hdrdir)/ruby/internal/core/rclass.h
|
||||
readline.o: $(hdrdir)/ruby/internal/core/rdata.h
|
||||
readline.o: $(hdrdir)/ruby/internal/core/rfile.h
|
||||
readline.o: $(hdrdir)/ruby/internal/core/rhash.h
|
||||
readline.o: $(hdrdir)/ruby/internal/core/robject.h
|
||||
readline.o: $(hdrdir)/ruby/internal/core/rregexp.h
|
||||
readline.o: $(hdrdir)/ruby/internal/core/rstring.h
|
||||
readline.o: $(hdrdir)/ruby/internal/core/rstruct.h
|
||||
readline.o: $(hdrdir)/ruby/internal/core/rtypeddata.h
|
||||
readline.o: $(hdrdir)/ruby/internal/ctype.h
|
||||
readline.o: $(hdrdir)/ruby/internal/dllexport.h
|
||||
readline.o: $(hdrdir)/ruby/internal/dosish.h
|
||||
readline.o: $(hdrdir)/ruby/internal/encoding/coderange.h
|
||||
readline.o: $(hdrdir)/ruby/internal/encoding/ctype.h
|
||||
readline.o: $(hdrdir)/ruby/internal/encoding/encoding.h
|
||||
readline.o: $(hdrdir)/ruby/internal/encoding/pathname.h
|
||||
readline.o: $(hdrdir)/ruby/internal/encoding/re.h
|
||||
readline.o: $(hdrdir)/ruby/internal/encoding/sprintf.h
|
||||
readline.o: $(hdrdir)/ruby/internal/encoding/string.h
|
||||
readline.o: $(hdrdir)/ruby/internal/encoding/symbol.h
|
||||
readline.o: $(hdrdir)/ruby/internal/encoding/transcode.h
|
||||
readline.o: $(hdrdir)/ruby/internal/error.h
|
||||
readline.o: $(hdrdir)/ruby/internal/eval.h
|
||||
readline.o: $(hdrdir)/ruby/internal/event.h
|
||||
readline.o: $(hdrdir)/ruby/internal/fl_type.h
|
||||
readline.o: $(hdrdir)/ruby/internal/gc.h
|
||||
readline.o: $(hdrdir)/ruby/internal/glob.h
|
||||
readline.o: $(hdrdir)/ruby/internal/globals.h
|
||||
readline.o: $(hdrdir)/ruby/internal/has/attribute.h
|
||||
readline.o: $(hdrdir)/ruby/internal/has/builtin.h
|
||||
readline.o: $(hdrdir)/ruby/internal/has/c_attribute.h
|
||||
readline.o: $(hdrdir)/ruby/internal/has/cpp_attribute.h
|
||||
readline.o: $(hdrdir)/ruby/internal/has/declspec_attribute.h
|
||||
readline.o: $(hdrdir)/ruby/internal/has/extension.h
|
||||
readline.o: $(hdrdir)/ruby/internal/has/feature.h
|
||||
readline.o: $(hdrdir)/ruby/internal/has/warning.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/array.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/bignum.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/class.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/compar.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/complex.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/cont.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/dir.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/enum.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/enumerator.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/error.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/eval.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/file.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/hash.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/io.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/load.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/marshal.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/numeric.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/object.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/parse.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/proc.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/process.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/random.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/range.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/rational.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/re.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/ruby.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/select.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/select/largesize.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/signal.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/sprintf.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/string.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/struct.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/thread.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/time.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/variable.h
|
||||
readline.o: $(hdrdir)/ruby/internal/intern/vm.h
|
||||
readline.o: $(hdrdir)/ruby/internal/interpreter.h
|
||||
readline.o: $(hdrdir)/ruby/internal/iterator.h
|
||||
readline.o: $(hdrdir)/ruby/internal/memory.h
|
||||
readline.o: $(hdrdir)/ruby/internal/method.h
|
||||
readline.o: $(hdrdir)/ruby/internal/module.h
|
||||
readline.o: $(hdrdir)/ruby/internal/newobj.h
|
||||
readline.o: $(hdrdir)/ruby/internal/scan_args.h
|
||||
readline.o: $(hdrdir)/ruby/internal/special_consts.h
|
||||
readline.o: $(hdrdir)/ruby/internal/static_assert.h
|
||||
readline.o: $(hdrdir)/ruby/internal/stdalign.h
|
||||
readline.o: $(hdrdir)/ruby/internal/stdbool.h
|
||||
readline.o: $(hdrdir)/ruby/internal/symbol.h
|
||||
readline.o: $(hdrdir)/ruby/internal/value.h
|
||||
readline.o: $(hdrdir)/ruby/internal/value_type.h
|
||||
readline.o: $(hdrdir)/ruby/internal/variable.h
|
||||
readline.o: $(hdrdir)/ruby/internal/warning_push.h
|
||||
readline.o: $(hdrdir)/ruby/internal/xmalloc.h
|
||||
readline.o: $(hdrdir)/ruby/io.h
|
||||
readline.o: $(hdrdir)/ruby/missing.h
|
||||
readline.o: $(hdrdir)/ruby/onigmo.h
|
||||
readline.o: $(hdrdir)/ruby/oniguruma.h
|
||||
readline.o: $(hdrdir)/ruby/ruby.h
|
||||
readline.o: $(hdrdir)/ruby/st.h
|
||||
readline.o: $(hdrdir)/ruby/subst.h
|
||||
readline.o: $(hdrdir)/ruby/thread.h
|
||||
readline.o: readline.c
|
||||
# AUTOGENERATED DEPENDENCIES END
|
|
@ -1,4 +0,0 @@
|
|||
# AUTOGENERATED DEPENDENCIES START
|
||||
readline.o: $(RUBY_EXTCONF_H)
|
||||
readline.o: readline.c
|
||||
# AUTOGENERATED DEPENDENCIES END
|
|
@ -1,112 +0,0 @@
|
|||
# frozen_string_literal: false
|
||||
require "mkmf"
|
||||
|
||||
readline = Struct.new(:headers, :extra_check).new(["stdio.h"])
|
||||
|
||||
def readline.have_header(header)
|
||||
if super(header, &extra_check)
|
||||
headers.push(header)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def readline.have_var(var)
|
||||
return super(var, headers)
|
||||
end
|
||||
|
||||
def readline.have_func(func)
|
||||
return super(func, headers)
|
||||
end
|
||||
|
||||
def readline.have_type(type)
|
||||
return super(type, headers)
|
||||
end
|
||||
|
||||
dir_config('curses')
|
||||
dir_config('ncurses')
|
||||
dir_config('termcap')
|
||||
dir_config("readline")
|
||||
enable_libedit = enable_config("libedit")
|
||||
|
||||
have_library("user32", nil) if /cygwin/ === RUBY_PLATFORM
|
||||
have_library("ncurses", "tgetnum") ||
|
||||
have_library("termcap", "tgetnum") ||
|
||||
have_library("curses", "tgetnum")
|
||||
|
||||
case enable_libedit
|
||||
when true
|
||||
# --enable-libedit
|
||||
dir_config("libedit")
|
||||
unless (readline.have_header("editline/readline.h") ||
|
||||
readline.have_header("readline/readline.h")) &&
|
||||
have_library("edit", "readline")
|
||||
raise "libedit not found"
|
||||
end
|
||||
when false
|
||||
# --disable-libedit
|
||||
unless ((readline.have_header("readline/readline.h") &&
|
||||
readline.have_header("readline/history.h")) &&
|
||||
have_library("readline", "readline"))
|
||||
raise "readline not found"
|
||||
end
|
||||
else
|
||||
# does not specify
|
||||
unless ((readline.have_header("readline/readline.h") &&
|
||||
readline.have_header("readline/history.h")) &&
|
||||
(have_library("readline", "readline") ||
|
||||
have_library("edit", "readline"))) ||
|
||||
(readline.have_header("editline/readline.h") &&
|
||||
have_library("edit", "readline"))
|
||||
raise "Neither readline nor libedit was found"
|
||||
end
|
||||
end
|
||||
|
||||
readline.have_func("rl_getc")
|
||||
readline.have_func("rl_getc_function")
|
||||
readline.have_func("rl_filename_completion_function")
|
||||
readline.have_func("rl_username_completion_function")
|
||||
readline.have_func("rl_completion_matches")
|
||||
readline.have_func("rl_refresh_line")
|
||||
readline.have_var("rl_deprep_term_function")
|
||||
readline.have_var("rl_completion_append_character")
|
||||
readline.have_var("rl_completion_quote_character")
|
||||
readline.have_var("rl_basic_word_break_characters")
|
||||
readline.have_var("rl_completer_word_break_characters")
|
||||
readline.have_var("rl_basic_quote_characters")
|
||||
readline.have_var("rl_completer_quote_characters")
|
||||
readline.have_var("rl_filename_quote_characters")
|
||||
readline.have_var("rl_attempted_completion_over")
|
||||
readline.have_var("rl_library_version")
|
||||
readline.have_var("rl_editing_mode")
|
||||
readline.have_var("rl_line_buffer")
|
||||
readline.have_var("rl_point")
|
||||
readline.have_var("rl_char_is_quoted_p")
|
||||
# workaround for native windows.
|
||||
/mswin|bccwin/ !~ RUBY_PLATFORM && readline.have_var("rl_event_hook")
|
||||
/mswin|bccwin/ !~ RUBY_PLATFORM && readline.have_var("rl_catch_sigwinch")
|
||||
/mswin|bccwin/ !~ RUBY_PLATFORM && readline.have_var("rl_catch_signals")
|
||||
readline.have_var("rl_pre_input_hook")
|
||||
readline.have_var("rl_special_prefixes")
|
||||
readline.have_func("rl_cleanup_after_signal")
|
||||
readline.have_func("rl_free_line_state")
|
||||
readline.have_func("rl_clear_signals")
|
||||
readline.have_func("rl_set_screen_size")
|
||||
readline.have_func("rl_get_screen_size")
|
||||
readline.have_func("rl_vi_editing_mode")
|
||||
readline.have_func("rl_emacs_editing_mode")
|
||||
readline.have_func("replace_history_entry")
|
||||
readline.have_func("remove_history")
|
||||
readline.have_func("clear_history")
|
||||
readline.have_func("rl_redisplay")
|
||||
readline.have_func("rl_insert_text")
|
||||
readline.have_func("rl_delete_text")
|
||||
unless readline.have_type("rl_hook_func_t*")
|
||||
# rl_hook_func_t is available since readline-4.2 (2001).
|
||||
# Function is removed at readline-6.3 (2014).
|
||||
# However, editline (NetBSD 6.1.3, 2014) doesn't have rl_hook_func_t.
|
||||
$defs << "-Drl_hook_func_t=Function"
|
||||
end
|
||||
|
||||
create_makefile("readline")
|
|
@ -1,32 +0,0 @@
|
|||
source_version = ["", "ext/readline/"].find do |dir|
|
||||
begin
|
||||
break File.open(File.join(__dir__, "#{dir}readline.c")) {|f|
|
||||
f.gets("\n#define READLINE_VERSION ")
|
||||
f.gets[/\s*"(.+)"/, 1]
|
||||
}
|
||||
rescue Errno::ENOENT
|
||||
end
|
||||
end
|
||||
|
||||
Gem::Specification.new do |spec|
|
||||
spec.name = "readline-ext"
|
||||
spec.version = source_version
|
||||
spec.authors = ["Yukihiro Matsumoto"]
|
||||
spec.email = ["matz@ruby-lang.org"]
|
||||
|
||||
spec.summary = %q{Provides an interface for GNU Readline and Edit Line (libedit).}
|
||||
spec.description = %q{Provides an interface for GNU Readline and Edit Line (libedit).}
|
||||
spec.homepage = "https://github.com/ruby/readline-ext"
|
||||
spec.licenses = ["Ruby", "BSD-2-Clause"]
|
||||
spec.extensions = %w[ext/readline/extconf.rb]
|
||||
|
||||
spec.metadata["homepage_uri"] = spec.homepage
|
||||
spec.metadata["source_code_uri"] = spec.homepage
|
||||
|
||||
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
||||
`git ls-files -z 2>#{IO::NULL}`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
||||
end
|
||||
spec.bindir = "exe"
|
||||
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
||||
spec.require_paths = ["lib"]
|
||||
end
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,35 +0,0 @@
|
|||
begin
|
||||
# for standalone test suite on ruby/logger
|
||||
require_relative '../lib/envutil'
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
begin
|
||||
require "readline.so"
|
||||
ReadlineSo = Readline
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
def use_ext_readline # Use ext/readline as Readline
|
||||
Object.send(:remove_const, :Readline) if Object.const_defined?(:Readline)
|
||||
Object.const_set(:Readline, ReadlineSo)
|
||||
end
|
||||
|
||||
begin
|
||||
require "reline"
|
||||
rescue LoadError
|
||||
Object.class_eval {remove_const :Reline} if defined?(Reline)
|
||||
else
|
||||
def use_lib_reline # Use lib/reline as Readline
|
||||
Reline.send(:remove_const, 'IOGate') if Reline.const_defined?('IOGate')
|
||||
Reline.const_set('IOGate', Reline::GeneralIO)
|
||||
Reline.send(:core).config.instance_variable_set(:@test_mode, true)
|
||||
Reline.send(:core).config.reset
|
||||
Object.send(:remove_const, :Readline) if Object.const_defined?(:Readline)
|
||||
Object.const_set(:Readline, Reline)
|
||||
end
|
||||
|
||||
def finish_using_lib_reline
|
||||
Reline.instance_variable_set(:@core, nil)
|
||||
end
|
||||
end
|
|
@ -1,955 +0,0 @@
|
|||
# frozen_string_literal: false
|
||||
require_relative "helper"
|
||||
require "test/unit"
|
||||
require "tempfile"
|
||||
require "timeout"
|
||||
require "open3"
|
||||
|
||||
module BasetestReadline
|
||||
RUBY = EnvUtil.rubybin
|
||||
|
||||
INPUTRC = "INPUTRC"
|
||||
TERM = "TERM"
|
||||
SAVED_ENV = %w[COLUMNS LINES]
|
||||
|
||||
TIMEOUT = 8
|
||||
|
||||
def setup
|
||||
@saved_env = ENV.values_at(*SAVED_ENV)
|
||||
@inputrc, ENV[INPUTRC] = ENV[INPUTRC], IO::NULL
|
||||
@term, ENV[TERM] = ENV[TERM], "vt100"
|
||||
end
|
||||
|
||||
def teardown
|
||||
ENV[INPUTRC] = @inputrc
|
||||
ENV[TERM] = @term
|
||||
Readline.instance_variable_set("@completion_proc", nil)
|
||||
begin
|
||||
Readline.delete_text
|
||||
Readline.point = 0
|
||||
rescue NotImplementedError
|
||||
end
|
||||
Readline.special_prefixes = ""
|
||||
Readline.completion_append_character = nil
|
||||
Readline.input = nil
|
||||
Readline.output = nil
|
||||
SAVED_ENV.each_with_index {|k, i| ENV[k] = @saved_env[i] }
|
||||
end
|
||||
|
||||
def test_readline
|
||||
Readline::HISTORY.clear
|
||||
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
|
||||
with_temp_stdio do |stdin, stdout|
|
||||
stdin.write("hello\n")
|
||||
stdin.close
|
||||
stdout.flush
|
||||
line = replace_stdio(stdin.path, stdout.path) {
|
||||
Readline.readline("> ", true)
|
||||
}
|
||||
assert_equal("hello", line)
|
||||
assert_equal(true, line.tainted?) if RUBY_VERSION < '2.7'
|
||||
stdout.rewind
|
||||
assert_equal("> ", stdout.read(2))
|
||||
assert_equal(1, Readline::HISTORY.length)
|
||||
assert_equal("hello", Readline::HISTORY[0])
|
||||
|
||||
# Work around lack of SecurityError in Reline
|
||||
# test mode with tainted prompt.
|
||||
# Also skip test on Ruby 2.7+, where $SAFE/taint is deprecated.
|
||||
if RUBY_VERSION < '2.7' && defined?(TestRelineAsReadline) && !kind_of?(TestRelineAsReadline)
|
||||
begin
|
||||
Thread.start {
|
||||
$SAFE = 1
|
||||
assert_raise(SecurityError) do
|
||||
replace_stdio(stdin.path, stdout.path) do
|
||||
Readline.readline("> ".taint)
|
||||
end
|
||||
end
|
||||
}.join
|
||||
ensure
|
||||
$SAFE = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# line_buffer
|
||||
# point
|
||||
def test_line_buffer__point
|
||||
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
|
||||
omit "GNU Readline has special behaviors" if defined?(Reline) and Readline == Reline
|
||||
begin
|
||||
Readline.line_buffer
|
||||
Readline.point
|
||||
rescue NotImplementedError
|
||||
return
|
||||
end
|
||||
|
||||
with_temp_stdio do |stdin, stdout|
|
||||
actual_text = nil
|
||||
actual_line_buffer = nil
|
||||
actual_point = nil
|
||||
Readline.completion_proc = ->(text) {
|
||||
actual_text = text
|
||||
actual_point = Readline.point
|
||||
actual_line_buffer = Readline.line_buffer
|
||||
stdin.write(" finish\n")
|
||||
stdin.flush
|
||||
stdout.flush
|
||||
return ["complete"]
|
||||
}
|
||||
|
||||
stdin.write("first second\t")
|
||||
stdin.flush
|
||||
Readline.completion_append_character = " "
|
||||
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?) if RUBY_VERSION < '2.7'
|
||||
|
||||
assert_equal(22, Readline.point)
|
||||
|
||||
stdin.rewind
|
||||
stdout.rewind
|
||||
|
||||
stdin.write("first second\t")
|
||||
stdin.flush
|
||||
Readline.completion_append_character = nil
|
||||
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?) if RUBY_VERSION < '2.7'
|
||||
|
||||
assert_equal(21, Readline.point)
|
||||
end
|
||||
end
|
||||
|
||||
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"}]
|
||||
completion_case_fold = Readline.completion_case_fold
|
||||
expected.each do |e|
|
||||
Readline.completion_case_fold = e
|
||||
assert_equal(e, Readline.completion_case_fold)
|
||||
end
|
||||
ensure
|
||||
Readline.completion_case_fold = completion_case_fold
|
||||
end
|
||||
|
||||
def test_completion_proc_empty_result
|
||||
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
|
||||
with_temp_stdio do |stdin, stdout|
|
||||
stdin.write("first\t")
|
||||
stdin.flush
|
||||
Readline.completion_proc = ->(text) {[]}
|
||||
line1 = line2 = nil
|
||||
replace_stdio(stdin.path, stdout.path) {
|
||||
assert_nothing_raised(NoMemoryError) {line1 = Readline.readline("> ")}
|
||||
stdin.write("\n")
|
||||
stdin.flush
|
||||
assert_nothing_raised(NoMemoryError) {line2 = Readline.readline("> ")}
|
||||
}
|
||||
assert_equal("first", line1)
|
||||
assert_equal("", line2)
|
||||
begin
|
||||
assert_equal("", Readline.line_buffer)
|
||||
rescue NotImplementedError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
# 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
|
||||
|
||||
def test_completion_append_character
|
||||
begin
|
||||
enc = get_default_internal_encoding
|
||||
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
|
||||
Readline.completion_append_character = ""
|
||||
assert_equal(nil, Readline.completion_append_character)
|
||||
rescue NotImplementedError
|
||||
end
|
||||
end
|
||||
|
||||
def test_completion_encoding
|
||||
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
|
||||
bug5941 = '[Bug #5941]'
|
||||
append_character = Readline.completion_append_character
|
||||
Readline.completion_append_character = ""
|
||||
completion_case_fold = Readline.completion_case_fold
|
||||
locale = get_default_internal_encoding
|
||||
if locale == Encoding::UTF_8
|
||||
enc1 = Encoding::EUC_JP
|
||||
else
|
||||
enc1 = Encoding::UTF_8
|
||||
end
|
||||
results = nil
|
||||
Readline.completion_proc = ->(text) {results}
|
||||
|
||||
[%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
|
||||
begin
|
||||
return if assert_under_utf8
|
||||
omit("missing test for locale #{locale.name}")
|
||||
end
|
||||
expected = results[0][0...1]
|
||||
Readline.completion_case_fold = false
|
||||
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
|
||||
ensure
|
||||
return if /EditLine/n.match(Readline::VERSION)
|
||||
Readline.completion_case_fold = completion_case_fold
|
||||
Readline.completion_append_character = append_character
|
||||
end
|
||||
|
||||
# basic_word_break_characters
|
||||
# completer_word_break_characters
|
||||
# basic_quote_characters
|
||||
# completer_quote_characters
|
||||
# filename_quote_characters
|
||||
# special_prefixes
|
||||
def test_some_characters_methods
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def test_pre_input_hook
|
||||
begin
|
||||
pr = proc {}
|
||||
Readline.pre_input_hook = pr
|
||||
assert_equal(pr, Readline.pre_input_hook)
|
||||
Readline.pre_input_hook = nil
|
||||
assert_nil(Readline.pre_input_hook)
|
||||
rescue NotImplementedError
|
||||
end
|
||||
end
|
||||
|
||||
def test_point
|
||||
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
|
||||
assert_equal(0, Readline.point)
|
||||
Readline.insert_text('12345')
|
||||
assert_equal(5, Readline.point)
|
||||
|
||||
assert_equal(4, Readline.point=(4))
|
||||
|
||||
Readline.insert_text('abc')
|
||||
assert_equal(7, Readline.point)
|
||||
|
||||
assert_equal('1234abc5', Readline.line_buffer)
|
||||
rescue NotImplementedError
|
||||
end
|
||||
|
||||
def test_insert_text
|
||||
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
|
||||
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
|
||||
|
||||
def test_delete_text
|
||||
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
|
||||
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
|
||||
|
||||
if !defined?(Reline) or Readline != Reline
|
||||
# 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)
|
||||
end
|
||||
rescue NotImplementedError
|
||||
end
|
||||
|
||||
def test_modify_text_in_pre_input_hook
|
||||
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
|
||||
with_temp_stdio {|stdin, stdout|
|
||||
begin
|
||||
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
|
||||
# Readline 4.3 doesn't include inserted text or input
|
||||
# Reline's rendering logic is tricky
|
||||
if Readline::VERSION != '4.3' and (!defined?(Reline) or Readline != Reline)
|
||||
assert_equal("> hello world\n", stdout.read)
|
||||
end
|
||||
stdout.close
|
||||
rescue NotImplementedError
|
||||
ensure
|
||||
begin
|
||||
Readline.pre_input_hook = nil
|
||||
rescue NotImplementedError
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_input_metachar
|
||||
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
|
||||
# test will pass on Windows reline, but not readline
|
||||
omit "Won't pass on mingw readline.so using 8.0.001" if /mingw/ =~ RUBY_PLATFORM and defined?(TestReadline) and kind_of?(TestReadline)
|
||||
omit 'Needs GNU Readline 6 or later' if /mswin|mingw/ =~ RUBY_PLATFORM and defined?(TestReadline) and kind_of?(TestReadline) and Readline::VERSION < '6.0'
|
||||
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
|
||||
return if /EditLine/n.match(Readline::VERSION)
|
||||
Readline.delete_text
|
||||
Readline::HISTORY.clear
|
||||
end
|
||||
|
||||
def test_input_metachar_multibyte
|
||||
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
|
||||
unless Encoding.find("locale") == Encoding::UTF_8
|
||||
return if assert_under_utf8
|
||||
omit 'this test needs UTF-8 locale'
|
||||
end
|
||||
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)
|
||||
Timeout.timeout(TIMEOUT) do
|
||||
assert_equal("\u3042\u3093", Readline.readline("", true), bug6602)
|
||||
end
|
||||
assert_equal(nil, Readline.readline("", true), bug6602)
|
||||
end
|
||||
end
|
||||
ensure
|
||||
return if /EditLine/n.match(Readline::VERSION)
|
||||
Readline.delete_text
|
||||
Readline::HISTORY.clear
|
||||
end
|
||||
|
||||
def test_refresh_line
|
||||
omit "Only when refresh_line exists" unless Readline.respond_to?(:refresh_line)
|
||||
omit unless respond_to?(:assert_ruby_status)
|
||||
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
|
||||
|
||||
# TODO Green CI for arm32-linux (Travis CI), and Readline 7.0.
|
||||
def test_interrupt_in_other_thread
|
||||
# Editline and Readline 7.0 can't treat I/O that is not tty.
|
||||
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
|
||||
omit "Skip Readline 7.0" if Readline::VERSION == "7.0"
|
||||
omit unless respond_to?(:assert_ruby_status)
|
||||
omit if /mswin|mingw/ =~ RUBY_PLATFORM
|
||||
|
||||
# On 32-bit machine, readline library (or libtinfo) seems to cause SEGV internally even with Readline 8.0
|
||||
# GDB Backtrace: https://gist.github.com/mame/d12b9de3bbc3f16d440c1927398d176a
|
||||
# Maybe the same issue: https://github.com/facebookresearch/nle/issues/120
|
||||
omit if /i[3-6]86-linux/ =~ RUBY_PLATFORM
|
||||
|
||||
# likewise with 32-bit userspace on 64-bit kernel
|
||||
omit if /\Ax86_64-linux-(?:x32|i[3-6]686)\z/ =~ RUBY_PLATFORM
|
||||
|
||||
if defined?(TestReadline) && self.class == TestReadline
|
||||
use = "use_ext_readline"
|
||||
elsif defined?(TestRelineAsReadline) && self.class == TestRelineAsReadline
|
||||
use = "use_lib_reline"
|
||||
end
|
||||
code = <<-"end;"
|
||||
$stdout.sync = true
|
||||
require 'readline'
|
||||
require 'helper'
|
||||
#{use}
|
||||
puts "Readline::VERSION is \#{Readline::VERSION}."
|
||||
Readline.input = STDIN
|
||||
# 0. Send SIGINT to this script.
|
||||
begin
|
||||
Thread.new{
|
||||
trap(:INT) {
|
||||
puts 'TRAP' # 2. Show 'TRAP' message.
|
||||
}
|
||||
Readline.readline('input> ') # 1. Should keep working and call old trap.
|
||||
# 4. Receive "\\n" and return because still working.
|
||||
}.value
|
||||
rescue Interrupt
|
||||
puts 'FAILED' # 3. "Interrupt" shouldn't be raised because trapped.
|
||||
raise
|
||||
end
|
||||
puts 'SUCCEEDED' # 5. Finish correctly.
|
||||
end;
|
||||
|
||||
script = Tempfile.new("interrupt_in_other_thread")
|
||||
script.write code
|
||||
script.close
|
||||
|
||||
log = String.new
|
||||
|
||||
EnvUtil.invoke_ruby(["-I#{__dir__}", script.path], "", true, :merge_to_stdout) do |_in, _out, _, pid|
|
||||
Timeout.timeout(TIMEOUT) do
|
||||
log << "** START **"
|
||||
loop do
|
||||
c = _out.read(1)
|
||||
log << c if c
|
||||
break if log.include?('input> ')
|
||||
end
|
||||
log << "** SIGINT **"
|
||||
sleep 0.5
|
||||
Process.kill(:INT, pid)
|
||||
sleep 0.5
|
||||
loop do
|
||||
c = _out.read(1)
|
||||
log << c if c
|
||||
break if log.include?('TRAP')
|
||||
end
|
||||
begin
|
||||
log << "** NEWLINE **"
|
||||
_in.write "\n"
|
||||
rescue Errno::EPIPE
|
||||
log << "** Errno::EPIPE **"
|
||||
# The "write" will fail if Reline crashed by SIGINT.
|
||||
end
|
||||
interrupt_suppressed = nil
|
||||
loop do
|
||||
c = _out.read(1)
|
||||
log << c if c
|
||||
if log.include?('FAILED')
|
||||
interrupt_suppressed = false
|
||||
break
|
||||
end
|
||||
if log.include?('SUCCEEDED')
|
||||
interrupt_suppressed = true
|
||||
break
|
||||
end
|
||||
end
|
||||
assert interrupt_suppressed, "Should handle SIGINT correctly but raised interrupt.\nLog: #{log}\n----"
|
||||
end
|
||||
rescue Timeout::Error => e
|
||||
Process.kill(:KILL, pid)
|
||||
log << "\nKilled by timeout"
|
||||
assert false, "Timed out to handle SIGINT!\nLog: #{log}\nBacktrace:\n#{e.full_message(highlight: false)}\n----"
|
||||
ensure
|
||||
status = nil
|
||||
begin
|
||||
Timeout.timeout(TIMEOUT) do
|
||||
status = Process.wait2(pid).last
|
||||
end
|
||||
rescue Timeout::Error => e
|
||||
log << "\nKilled by timeout to wait2"
|
||||
Process.kill(:KILL, pid)
|
||||
assert false, "Timed out to wait for terminating a process in a test of SIGINT!\nLog: #{log}\nBacktrace:\n#{e.full_message(highlight: false)}\n----"
|
||||
end
|
||||
assert status&.success?, "Unknown failure with exit status #{status.inspect}\nLog: #{log}\n----"
|
||||
end
|
||||
|
||||
assert log.include?('INT'), "Interrupt was handled correctly."
|
||||
ensure
|
||||
script&.close!
|
||||
end
|
||||
|
||||
def test_setting_quoting_detection_proc
|
||||
return unless Readline.respond_to?(:quoting_detection_proc=)
|
||||
|
||||
expected = proc { |text, index| false }
|
||||
Readline.quoting_detection_proc = expected
|
||||
assert_equal(expected, Readline.quoting_detection_proc)
|
||||
|
||||
assert_raise(ArgumentError) do
|
||||
Readline.quoting_detection_proc = "This does not have call method."
|
||||
end
|
||||
end
|
||||
|
||||
def test_using_quoting_detection_proc
|
||||
saved_completer_quote_characters = Readline.completer_quote_characters
|
||||
saved_completer_word_break_characters = Readline.completer_word_break_characters
|
||||
|
||||
# skip if previous value is nil because Readline... = nil is not allowed.
|
||||
omit "No completer_quote_characters" unless saved_completer_quote_characters
|
||||
omit "No completer_word_break_characters" unless saved_completer_word_break_characters
|
||||
|
||||
return unless Readline.respond_to?(:quoting_detection_proc=)
|
||||
|
||||
begin
|
||||
passed_text = nil
|
||||
line = nil
|
||||
|
||||
with_temp_stdio do |stdin, stdout|
|
||||
replace_stdio(stdin.path, stdout.path) do
|
||||
Readline.completion_proc = ->(text) do
|
||||
passed_text = text
|
||||
['completion'].map { |i|
|
||||
i.encode(Encoding.default_external)
|
||||
}
|
||||
end
|
||||
Readline.completer_quote_characters = '\'"'
|
||||
Readline.completer_word_break_characters = ' '
|
||||
Readline.quoting_detection_proc = ->(text, index) do
|
||||
index > 0 && text[index-1] == '\\'
|
||||
end
|
||||
|
||||
stdin.write("first second\\ third\t")
|
||||
stdin.flush
|
||||
line = Readline.readline('> ', false)
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal('second\\ third', passed_text)
|
||||
assert_equal('first completion', line.chomp(' '))
|
||||
ensure
|
||||
Readline.completer_quote_characters = saved_completer_quote_characters
|
||||
Readline.completer_word_break_characters = saved_completer_word_break_characters
|
||||
end
|
||||
end
|
||||
|
||||
def test_using_quoting_detection_proc_with_multibyte_input
|
||||
Readline.completion_append_character = nil
|
||||
saved_completer_quote_characters = Readline.completer_quote_characters
|
||||
saved_completer_word_break_characters = Readline.completer_word_break_characters
|
||||
|
||||
# skip if previous value is nil because Readline... = nil is not allowed.
|
||||
omit "No completer_quote_characters" unless saved_completer_quote_characters
|
||||
omit "No completer_word_break_characters" unless saved_completer_word_break_characters
|
||||
|
||||
return unless Readline.respond_to?(:quoting_detection_proc=)
|
||||
unless get_default_internal_encoding == Encoding::UTF_8
|
||||
return if assert_under_utf8
|
||||
omit 'this test needs UTF-8 locale'
|
||||
end
|
||||
|
||||
begin
|
||||
passed_text = nil
|
||||
escaped_char_indexes = []
|
||||
line = nil
|
||||
|
||||
with_temp_stdio do |stdin, stdout|
|
||||
replace_stdio(stdin.path, stdout.path) do
|
||||
Readline.completion_proc = ->(text) do
|
||||
passed_text = text
|
||||
['completion'].map { |i|
|
||||
i.encode(Encoding.default_external)
|
||||
}
|
||||
end
|
||||
Readline.completer_quote_characters = '\'"'
|
||||
Readline.completer_word_break_characters = ' '
|
||||
Readline.quoting_detection_proc = ->(text, index) do
|
||||
escaped = index > 0 && text[index-1] == '\\'
|
||||
escaped_char_indexes << index if escaped
|
||||
escaped
|
||||
end
|
||||
|
||||
stdin.write("\u3042\u3093 second\\ third\t")
|
||||
stdin.flush
|
||||
line = Readline.readline('> ', false)
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal([10], escaped_char_indexes)
|
||||
assert_equal('second\\ third', passed_text)
|
||||
assert_equal("\u3042\u3093 completion#{Readline.completion_append_character}", line)
|
||||
ensure
|
||||
Readline.completer_quote_characters = saved_completer_quote_characters
|
||||
Readline.completer_word_break_characters = saved_completer_word_break_characters
|
||||
end
|
||||
end
|
||||
|
||||
def test_simple_completion
|
||||
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
|
||||
|
||||
line = nil
|
||||
|
||||
open(IO::NULL, 'w') do |null|
|
||||
IO.pipe do |r, w|
|
||||
Readline.input = r
|
||||
Readline.output = null
|
||||
Readline.completion_proc = ->(text) do
|
||||
['abcde', 'abc12'].map { |i|
|
||||
i.encode(get_default_internal_encoding)
|
||||
}
|
||||
end
|
||||
w.write("a\t\n")
|
||||
w.flush
|
||||
begin
|
||||
stderr = $stderr.dup
|
||||
$stderr.reopen(null)
|
||||
line = Readline.readline('> ', false)
|
||||
ensure
|
||||
$stderr.reopen(stderr)
|
||||
stderr.close
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal('abc', line)
|
||||
end
|
||||
|
||||
def test_completion_with_completion_append_character
|
||||
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
|
||||
omit "Readline.completion_append_character is not implemented" unless Readline.respond_to?(:completion_append_character=)
|
||||
line = nil
|
||||
|
||||
append_character = Readline.completion_append_character
|
||||
open(IO::NULL, 'w') do |null|
|
||||
IO.pipe do |r, w|
|
||||
Readline.input = r
|
||||
Readline.output = null
|
||||
Readline.completion_append_character = '!'
|
||||
Readline.completion_proc = ->(text) do
|
||||
['abcde'].map { |i|
|
||||
i.encode(get_default_internal_encoding)
|
||||
}
|
||||
end
|
||||
w.write("a\t\n")
|
||||
w.flush
|
||||
line = Readline.readline('> ', false)
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal('abcde!', line)
|
||||
ensure
|
||||
return if /EditLine/n.match(Readline::VERSION)
|
||||
return unless Readline.respond_to?(:completion_append_character=)
|
||||
Readline.completion_append_character = append_character
|
||||
end
|
||||
|
||||
def test_completion_quote_character_completing_unquoted_argument
|
||||
return unless Readline.respond_to?(:completion_quote_character)
|
||||
|
||||
saved_completer_quote_characters = Readline.completer_quote_characters
|
||||
|
||||
quote_character = "original value"
|
||||
Readline.completion_proc = -> (_) do
|
||||
quote_character = Readline.completion_quote_character
|
||||
[]
|
||||
end
|
||||
Readline.completer_quote_characters = "'\""
|
||||
|
||||
with_temp_stdio do |stdin, stdout|
|
||||
replace_stdio(stdin.path, stdout.path) do
|
||||
stdin.write("input\t")
|
||||
stdin.flush
|
||||
Readline.readline("> ", false)
|
||||
end
|
||||
end
|
||||
|
||||
assert_nil(quote_character)
|
||||
ensure
|
||||
Readline.completer_quote_characters = saved_completer_quote_characters if saved_completer_quote_characters
|
||||
end
|
||||
|
||||
def test_completion_quote_character_completing_quoted_argument
|
||||
return unless Readline.respond_to?(:completion_quote_character)
|
||||
|
||||
saved_completer_quote_characters = Readline.completer_quote_characters
|
||||
|
||||
quote_character = "original value"
|
||||
Readline.completion_proc = -> (_) do
|
||||
quote_character = Readline.completion_quote_character
|
||||
[]
|
||||
end
|
||||
Readline.completer_quote_characters = "'\""
|
||||
|
||||
with_temp_stdio do |stdin, stdout|
|
||||
replace_stdio(stdin.path, stdout.path) do
|
||||
stdin.write("'input\t")
|
||||
stdin.flush
|
||||
Readline.readline("> ", false)
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal("'", quote_character)
|
||||
ensure
|
||||
Readline.completer_quote_characters = saved_completer_quote_characters if saved_completer_quote_characters
|
||||
end
|
||||
|
||||
def test_completion_quote_character_after_completion
|
||||
return unless Readline.respond_to?(:completion_quote_character)
|
||||
if /solaris/i =~ RUBY_PLATFORM
|
||||
# http://rubyci.s3.amazonaws.com/solaris11s-sunc/ruby-trunk/log/20181228T102505Z.fail.html.gz
|
||||
omit 'This test does not succeed on Oracle Developer Studio for now'
|
||||
end
|
||||
omit 'Needs GNU Readline 6 or later' if /mswin|mingw/ =~ RUBY_PLATFORM and defined?(TestReadline) and kind_of?(TestReadline) and Readline::VERSION < '6.0'
|
||||
|
||||
saved_completer_quote_characters = Readline.completer_quote_characters
|
||||
|
||||
Readline.completion_proc = -> (_) { [] }
|
||||
Readline.completer_quote_characters = "'\""
|
||||
|
||||
with_temp_stdio do |stdin, stdout|
|
||||
replace_stdio(stdin.path, stdout.path) do
|
||||
stdin.write("'input\t")
|
||||
stdin.flush
|
||||
Readline.readline("> ", false)
|
||||
end
|
||||
end
|
||||
|
||||
assert_nil(Readline.completion_quote_character)
|
||||
ensure
|
||||
Readline.completer_quote_characters = saved_completer_quote_characters if saved_completer_quote_characters
|
||||
end
|
||||
|
||||
def test_without_tty
|
||||
omit "Skip Editline" if /EditLine/n.match(Readline::VERSION)
|
||||
loader = nil
|
||||
if defined?(TestReadline) && self.class == TestReadline
|
||||
loader = "use_ext_readline"
|
||||
elsif defined?(TestRelineAsReadline) && self.class == TestRelineAsReadline
|
||||
loader = "use_lib_reline"
|
||||
end
|
||||
if loader
|
||||
res, exit_status = Open3.capture2e("#{RUBY} -I#{__dir__} -Ilib -rhelper -e '#{loader}; Readline.readline(%{y or n?})'", stdin_data: "y\n")
|
||||
assert exit_status.success?, "It should work fine without tty, but it failed.\nError output:\n#{res}"
|
||||
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
|
||||
orig_stderr = STDERR.dup
|
||||
STDIN.reopen(stdin)
|
||||
STDOUT.reopen(stdout)
|
||||
STDERR.reopen(stdout)
|
||||
begin
|
||||
Readline.input = STDIN
|
||||
Readline.output = STDOUT
|
||||
yield
|
||||
ensure
|
||||
STDERR.reopen(orig_stderr)
|
||||
STDIN.reopen(orig_stdin)
|
||||
STDOUT.reopen(orig_stdout)
|
||||
orig_stdin.close
|
||||
orig_stdout.close
|
||||
orig_stderr.close
|
||||
end
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def with_temp_stdio
|
||||
Tempfile.create("test_readline_stdin") {|stdin|
|
||||
Tempfile.create("test_readline_stdout") {|stdout|
|
||||
yield stdin, stdout
|
||||
if /mswin|mingw/ =~ RUBY_PLATFORM
|
||||
# needed since readline holds refs to tempfiles, can't delete on Windows
|
||||
Readline.input = STDIN
|
||||
Readline.output = STDOUT
|
||||
end
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def with_pipe
|
||||
stderr = nil
|
||||
IO.pipe do |r, w|
|
||||
yield(r, w)
|
||||
Readline.input = r
|
||||
Readline.output = w.reopen(IO::NULL)
|
||||
stderr = STDERR.dup
|
||||
STDERR.reopen(w)
|
||||
Readline.readline
|
||||
end
|
||||
ensure
|
||||
if stderr
|
||||
STDERR.reopen(stderr)
|
||||
stderr.close
|
||||
end
|
||||
Readline.input = STDIN
|
||||
Readline.output = STDOUT
|
||||
end
|
||||
|
||||
def get_default_internal_encoding
|
||||
return Encoding.default_internal || Encoding.find("locale")
|
||||
end
|
||||
|
||||
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)
|
||||
#omit "test \#{ENV['LC_ALL']}"
|
||||
#{self.class.name}.new(#{loc.dump}).run(Test::Unit::Runner.new)
|
||||
SRC
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
class TestReadline < Test::Unit::TestCase
|
||||
include BasetestReadline
|
||||
|
||||
def setup
|
||||
use_ext_readline
|
||||
super
|
||||
end
|
||||
end if defined?(ReadlineSo) && ENV["TEST_READLINE_OR_RELINE"] != "Reline"
|
||||
|
||||
class TestRelineAsReadline < Test::Unit::TestCase
|
||||
include BasetestReadline
|
||||
|
||||
def setup
|
||||
use_lib_reline
|
||||
super
|
||||
end
|
||||
|
||||
def teardown
|
||||
finish_using_lib_reline
|
||||
super
|
||||
end
|
||||
|
||||
def get_default_internal_encoding
|
||||
if RUBY_PLATFORM =~ /mswin|mingw/
|
||||
Encoding.default_internal || Encoding::UTF_8
|
||||
else
|
||||
Reline::IOGate.encoding
|
||||
end
|
||||
end
|
||||
end if defined?(Reline) && ENV["TEST_READLINE_OR_RELINE"] != "Readline"
|
|
@ -1,292 +0,0 @@
|
|||
# frozen_string_literal: false
|
||||
require_relative "helper"
|
||||
require "test/unit"
|
||||
|
||||
module BasetestReadlineHistory
|
||||
def setup
|
||||
Readline::HISTORY.clear
|
||||
end
|
||||
|
||||
def test_to_s
|
||||
expected = "HISTORY"
|
||||
assert_equal(expected, Readline::HISTORY.to_s)
|
||||
end
|
||||
|
||||
def test_get
|
||||
lines = push_history(5)
|
||||
lines.each_with_index do |s, i|
|
||||
assert_external_string_equal(s, Readline::HISTORY[i])
|
||||
end
|
||||
end
|
||||
|
||||
def test_get__negative
|
||||
lines = push_history(5)
|
||||
(1..5).each do |i|
|
||||
assert_equal(lines[-i], Readline::HISTORY[-i])
|
||||
end
|
||||
end
|
||||
|
||||
def test_get__out_of_range
|
||||
push_history(5)
|
||||
invalid_indexes = [5, 6, 100, -6, -7, -100]
|
||||
invalid_indexes.each do |i|
|
||||
assert_raise(IndexError, "i=<#{i}>") do
|
||||
Readline::HISTORY[i]
|
||||
end
|
||||
end
|
||||
|
||||
invalid_indexes = [100_000_000_000_000_000_000,
|
||||
-100_000_000_000_000_000_000]
|
||||
invalid_indexes.each do |i|
|
||||
assert_raise(RangeError, "i=<#{i}>") do
|
||||
Readline::HISTORY[i]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_set
|
||||
begin
|
||||
push_history(5)
|
||||
5.times do |i|
|
||||
expected = "set: #{i}"
|
||||
Readline::HISTORY[i] = expected
|
||||
assert_external_string_equal(expected, Readline::HISTORY[i])
|
||||
end
|
||||
rescue NotImplementedError
|
||||
end
|
||||
end
|
||||
|
||||
def test_set__out_of_range
|
||||
assert_raise(IndexError, NotImplementedError, "index=<0>") do
|
||||
Readline::HISTORY[0] = "set: 0"
|
||||
end
|
||||
|
||||
push_history(5)
|
||||
invalid_indexes = [5, 6, 100, -6, -7, -100]
|
||||
invalid_indexes.each do |i|
|
||||
assert_raise(IndexError, NotImplementedError, "index=<#{i}>") do
|
||||
Readline::HISTORY[i] = "set: #{i}"
|
||||
end
|
||||
end
|
||||
|
||||
invalid_indexes = [100_000_000_000_000_000_000,
|
||||
-100_000_000_000_000_000_000]
|
||||
invalid_indexes.each do |i|
|
||||
assert_raise(RangeError, NotImplementedError, "index=<#{i}>") do
|
||||
Readline::HISTORY[i] = "set: #{i}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_push
|
||||
5.times do |i|
|
||||
s = i.to_s
|
||||
assert_equal(Readline::HISTORY, Readline::HISTORY.push(s))
|
||||
assert_external_string_equal(s, Readline::HISTORY[i])
|
||||
end
|
||||
assert_equal(5, Readline::HISTORY.length)
|
||||
end
|
||||
|
||||
def test_push__operator
|
||||
5.times do |i|
|
||||
s = i.to_s
|
||||
assert_equal(Readline::HISTORY, Readline::HISTORY << s)
|
||||
assert_external_string_equal(s, Readline::HISTORY[i])
|
||||
end
|
||||
assert_equal(5, Readline::HISTORY.length)
|
||||
end
|
||||
|
||||
def test_push__plural
|
||||
assert_equal(Readline::HISTORY, Readline::HISTORY.push("0", "1", "2", "3", "4"))
|
||||
(0..4).each do |i|
|
||||
assert_external_string_equal(i.to_s, Readline::HISTORY[i])
|
||||
end
|
||||
assert_equal(5, Readline::HISTORY.length)
|
||||
|
||||
assert_equal(Readline::HISTORY, Readline::HISTORY.push("5", "6", "7", "8", "9"))
|
||||
(5..9).each do |i|
|
||||
assert_external_string_equal(i.to_s, Readline::HISTORY[i])
|
||||
end
|
||||
assert_equal(10, Readline::HISTORY.length)
|
||||
end
|
||||
|
||||
def test_pop
|
||||
begin
|
||||
assert_equal(nil, Readline::HISTORY.pop)
|
||||
|
||||
lines = push_history(5)
|
||||
(1..5).each do |i|
|
||||
assert_external_string_equal(lines[-i], Readline::HISTORY.pop)
|
||||
assert_equal(lines.length - i, Readline::HISTORY.length)
|
||||
end
|
||||
|
||||
assert_equal(nil, Readline::HISTORY.pop)
|
||||
rescue NotImplementedError
|
||||
end
|
||||
end
|
||||
|
||||
def test_shift
|
||||
begin
|
||||
assert_equal(nil, Readline::HISTORY.shift)
|
||||
|
||||
lines = push_history(5)
|
||||
(0..4).each do |i|
|
||||
assert_external_string_equal(lines[i], Readline::HISTORY.shift)
|
||||
assert_equal(lines.length - (i + 1), Readline::HISTORY.length)
|
||||
end
|
||||
|
||||
assert_equal(nil, Readline::HISTORY.shift)
|
||||
rescue NotImplementedError
|
||||
end
|
||||
end
|
||||
|
||||
def test_each
|
||||
e = Readline::HISTORY.each do |s|
|
||||
assert(false) # not reachable
|
||||
end
|
||||
assert_equal(Readline::HISTORY, e)
|
||||
lines = push_history(5)
|
||||
i = 0
|
||||
e = Readline::HISTORY.each do |s|
|
||||
assert_external_string_equal(Readline::HISTORY[i], s)
|
||||
assert_external_string_equal(lines[i], s)
|
||||
i += 1
|
||||
end
|
||||
assert_equal(Readline::HISTORY, e)
|
||||
end
|
||||
|
||||
def test_each__enumerator
|
||||
e = Readline::HISTORY.each
|
||||
assert_instance_of(Enumerator, e)
|
||||
end
|
||||
|
||||
def test_length
|
||||
assert_equal(0, Readline::HISTORY.length)
|
||||
push_history(1)
|
||||
assert_equal(1, Readline::HISTORY.length)
|
||||
push_history(4)
|
||||
assert_equal(5, Readline::HISTORY.length)
|
||||
Readline::HISTORY.clear
|
||||
assert_equal(0, Readline::HISTORY.length)
|
||||
end
|
||||
|
||||
def test_empty_p
|
||||
2.times do
|
||||
assert(Readline::HISTORY.empty?)
|
||||
Readline::HISTORY.push("s")
|
||||
assert_equal(false, Readline::HISTORY.empty?)
|
||||
Readline::HISTORY.clear
|
||||
assert(Readline::HISTORY.empty?)
|
||||
end
|
||||
end
|
||||
|
||||
def test_delete_at
|
||||
begin
|
||||
lines = push_history(5)
|
||||
(0..4).each do |i|
|
||||
assert_external_string_equal(lines[i], Readline::HISTORY.delete_at(0))
|
||||
end
|
||||
assert(Readline::HISTORY.empty?)
|
||||
|
||||
lines = push_history(5)
|
||||
(1..5).each do |i|
|
||||
assert_external_string_equal(lines[lines.length - i], Readline::HISTORY.delete_at(-1))
|
||||
end
|
||||
assert(Readline::HISTORY.empty?)
|
||||
|
||||
lines = push_history(5)
|
||||
assert_external_string_equal(lines[0], Readline::HISTORY.delete_at(0))
|
||||
assert_external_string_equal(lines[4], Readline::HISTORY.delete_at(3))
|
||||
assert_external_string_equal(lines[1], Readline::HISTORY.delete_at(0))
|
||||
assert_external_string_equal(lines[3], Readline::HISTORY.delete_at(1))
|
||||
assert_external_string_equal(lines[2], Readline::HISTORY.delete_at(0))
|
||||
assert(Readline::HISTORY.empty?)
|
||||
rescue NotImplementedError
|
||||
end
|
||||
end
|
||||
|
||||
def test_delete_at__out_of_range
|
||||
assert_raise(IndexError, NotImplementedError, "index=<0>") do
|
||||
Readline::HISTORY.delete_at(0)
|
||||
end
|
||||
|
||||
push_history(5)
|
||||
invalid_indexes = [5, 6, 100, -6, -7, -100]
|
||||
invalid_indexes.each do |i|
|
||||
assert_raise(IndexError, NotImplementedError, "index=<#{i}>") do
|
||||
Readline::HISTORY.delete_at(i)
|
||||
end
|
||||
end
|
||||
|
||||
invalid_indexes = [100_000_000_000_000_000_000,
|
||||
-100_000_000_000_000_000_000]
|
||||
invalid_indexes.each do |i|
|
||||
assert_raise(RangeError, NotImplementedError, "index=<#{i}>") do
|
||||
Readline::HISTORY.delete_at(i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def push_history(num)
|
||||
lines = []
|
||||
num.times do |i|
|
||||
s = "a"
|
||||
i.times do
|
||||
s = s.succ
|
||||
end
|
||||
lines.push("#{i + 1}:#{s}")
|
||||
end
|
||||
Readline::HISTORY.push(*lines)
|
||||
return lines
|
||||
end
|
||||
|
||||
def assert_external_string_equal(expected, actual)
|
||||
assert_equal(expected, actual)
|
||||
assert_equal(get_default_internal_encoding, actual.encoding)
|
||||
end
|
||||
|
||||
def get_default_internal_encoding
|
||||
return Encoding.default_internal || Encoding.find("locale")
|
||||
end
|
||||
end
|
||||
|
||||
class TestReadlineHistory < Test::Unit::TestCase
|
||||
include BasetestReadlineHistory
|
||||
|
||||
def setup
|
||||
use_ext_readline
|
||||
super
|
||||
end
|
||||
end if defined?(::ReadlineSo) && defined?(::ReadlineSo::HISTORY) &&
|
||||
ENV["TEST_READLINE_OR_RELINE"] != "Reline" &&
|
||||
(
|
||||
begin
|
||||
ReadlineSo::HISTORY.clear
|
||||
rescue NotImplementedError
|
||||
false
|
||||
end
|
||||
)
|
||||
|
||||
class TestRelineAsReadlineHistory < Test::Unit::TestCase
|
||||
include BasetestReadlineHistory
|
||||
|
||||
def setup
|
||||
use_lib_reline
|
||||
super
|
||||
end
|
||||
|
||||
def teardown
|
||||
finish_using_lib_reline
|
||||
super
|
||||
end
|
||||
|
||||
def get_default_internal_encoding
|
||||
if RUBY_PLATFORM =~ /mswin|mingw/
|
||||
Encoding.default_internal || Encoding::UTF_8
|
||||
else
|
||||
Reline::IOGate.encoding
|
||||
end
|
||||
end
|
||||
end if defined?(Reline) && ENV["TEST_READLINE_OR_RELINE"] != "Readline"
|
Загрузка…
Ссылка в новой задаче