rb-readline 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +25 -0
- data/{README → README.rdoc} +8 -1
- data/Rakefile +5 -5
- data/examples/tinyirb.rb +11 -11
- data/lib/rb-readline.rb +16 -0
- data/lib/rbreadline.rb +8863 -8703
- data/lib/readline.rb +524 -520
- data/test/test_completion.rb +0 -2
- data/test/test_filename_completion_proc.rb +19 -1
- data/test/test_history.rb +29 -0
- data/test/test_rbreadline.rb +19 -5
- data/test/test_readline.rb +193 -152
- metadata +41 -58
data/test/test_completion.rb
CHANGED
@@ -68,8 +68,6 @@ class TestCompletion < Test::Unit::TestCase
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def test_make_quoted_replacement_calls_filename_quoting_function
|
71
|
-
match = RbReadline::SINGLE_MATCH
|
72
|
-
|
73
71
|
assert_equal "dir/with\\ space", make_quoted_replacement("dir/with space", RbReadline::SINGLE_MATCH, 0.chr)
|
74
72
|
end
|
75
73
|
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'fileutils'
|
3
3
|
require 'readline'
|
4
|
+
require "rbconfig"
|
4
5
|
require "#{File.expand_path(File.dirname(__FILE__))}/filesystem_completion_helper"
|
5
6
|
|
6
|
-
class
|
7
|
+
class TestFilenameCompletionProc < Test::Unit::TestCase
|
7
8
|
include FilesystemCompletionHelper
|
8
9
|
|
9
10
|
def setup
|
@@ -66,4 +67,21 @@ class TC_FILENAME_COMPLETION_PROC < Test::Unit::TestCase
|
|
66
67
|
def test_list_files_in_current_directory
|
67
68
|
assert_equal((Dir.entries(".") - %w( . .. )).sort, Readline::FILENAME_COMPLETION_PROC.call("").sort)
|
68
69
|
end
|
70
|
+
|
71
|
+
def test_listing_files_with_no_read_access
|
72
|
+
FileUtils.mkdir("test_no_access")
|
73
|
+
FileUtils.touch("test_no_access/123")
|
74
|
+
|
75
|
+
skip "chmod is noop in Windows" if windows?
|
76
|
+
|
77
|
+
FileUtils.chmod(0333, "test_no_access")
|
78
|
+
assert_nil Readline::FILENAME_COMPLETION_PROC.call("test_no_access/")
|
79
|
+
ensure
|
80
|
+
FileUtils.chmod(0775, "test_no_access")
|
81
|
+
FileUtils.rm_r("test_no_access")
|
82
|
+
end
|
83
|
+
|
84
|
+
def windows?
|
85
|
+
RbConfig::CONFIG["host_os"] =~ /mingw|mswin/
|
86
|
+
end
|
69
87
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "readline"
|
3
|
+
|
4
|
+
class TestHistory < Test::Unit::TestCase
|
5
|
+
|
6
|
+
# RbReadline::HISTORY_WORD_DELIMITERS.inspect
|
7
|
+
# => " \t\n;&()|<>"
|
8
|
+
# RbReadline::HISTORY_QUOTE_CHARACTERS = "\"'`"
|
9
|
+
# => "\"'`"
|
10
|
+
def test_history_arg_extract
|
11
|
+
assert_raise(RuntimeError) { RbReadline.history_arg_extract("!", "$", "one two three") }
|
12
|
+
assert_raise(RuntimeError) { RbReadline.history_arg_extract("$", "!", "one two three") }
|
13
|
+
|
14
|
+
assert_equal "one", RbReadline.history_arg_extract("$", "$", "one")
|
15
|
+
assert_equal "three", RbReadline.history_arg_extract("$", "$", "one two three")
|
16
|
+
assert_equal "two\\ three", RbReadline.history_arg_extract("$", "$", "one two\\ three")
|
17
|
+
assert_equal "three", RbReadline.history_arg_extract("$", "$", "one two;three")
|
18
|
+
assert_equal "two\\;three", RbReadline.history_arg_extract("$", "$", "one two\\;three")
|
19
|
+
|
20
|
+
assert_equal "'two three'", RbReadline.history_arg_extract("$", "$", "one 'two three'")
|
21
|
+
assert_equal "`two three`", RbReadline.history_arg_extract("$", "$", "one `two three`")
|
22
|
+
assert_equal "three\\'", RbReadline.history_arg_extract("$", "$", "one \\'two three\\'")
|
23
|
+
assert_equal "`one`", RbReadline.history_arg_extract("$", "$", "`one`")
|
24
|
+
|
25
|
+
assert_equal "three'", RbReadline.history_arg_extract("$", "$", "one two three'")
|
26
|
+
assert_equal "three", RbReadline.history_arg_extract("$", "$", "one two' three")
|
27
|
+
assert_equal "'two three '", RbReadline.history_arg_extract("$", "$", "one 'two three '")
|
28
|
+
end
|
29
|
+
end
|
data/test/test_rbreadline.rb
CHANGED
@@ -1,9 +1,23 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'rbreadline'
|
3
3
|
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
class TestRbReadline < Test::Unit::TestCase
|
5
|
+
def test_versions
|
6
|
+
assert_equal('5.2', RbReadline::RL_LIBRARY_VERSION)
|
7
|
+
assert_equal(0x0502, RbReadline::RL_READLINE_VERSION)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_rl_adjust_point
|
11
|
+
encoding_name = RbReadline.instance_variable_get(:@encoding_name)
|
12
|
+
RbReadline.instance_variable_set(:@encoding_name, Encoding.find('UTF-8'))
|
13
|
+
|
14
|
+
assert_equal(0, RbReadline._rl_adjust_point("a".force_encoding('ASCII-8BIT'), 0))
|
15
|
+
assert_equal(0, RbReadline._rl_adjust_point("a".force_encoding('ASCII-8BIT'), 1))
|
16
|
+
assert_equal(0, RbReadline._rl_adjust_point(("a" * 40).force_encoding('ASCII-8BIT'), 0))
|
17
|
+
assert_equal(0, RbReadline._rl_adjust_point(("a" * 40).force_encoding('ASCII-8BIT'), 40))
|
18
|
+
assert_equal(2, RbReadline._rl_adjust_point(("\u3042" * 10).force_encoding('ASCII-8BIT'), 1))
|
19
|
+
assert_equal(1, RbReadline._rl_adjust_point(("\u3042" * 15).force_encoding('ASCII-8BIT'), 38))
|
20
|
+
ensure
|
21
|
+
RbReadline.instance_variable_set(:@encoding_name, encoding_name)
|
22
|
+
end if defined?(Encoding)
|
9
23
|
end
|
data/test/test_readline.rb
CHANGED
@@ -1,168 +1,209 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'readline'
|
3
3
|
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
4
|
+
class TestReadline < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@proc = proc{ |s| ['alpha', 'beta'].grep( /^#{Regexp.escape(s)}/) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_version
|
10
|
+
assert_equal('5.2', Readline::VERSION)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_readline_basic
|
14
|
+
assert_respond_to(Readline, :readline)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_readline_expected_errors
|
18
|
+
assert_raise(ArgumentError){ Readline.readline }
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_input_basic
|
22
|
+
assert_respond_to(Readline, :input=)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_input
|
26
|
+
assert_nothing_raised{ Readline.input = $stdin }
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_output_basic
|
30
|
+
assert_respond_to(Readline, :output=)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_output
|
34
|
+
assert_nothing_raised{ Readline.output = $stdout }
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_completion_proc_get_basic
|
38
|
+
assert_respond_to(Readline, :completion_proc)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_completion_proc_set_basic
|
42
|
+
assert_respond_to(Readline, :completion_proc=)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_completion_proc
|
46
|
+
assert_nothing_raised{ Readline.completion_proc = @proc }
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_completion_case_fold_get_basic
|
50
|
+
assert_respond_to(Readline, :completion_case_fold)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_completion_case_fold_default
|
54
|
+
assert_equal(false, Readline.completion_case_fold) # default
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_completion_case_fold_set_basic
|
58
|
+
assert_respond_to(Readline, :completion_case_fold=)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_completion_case_fold_changed
|
62
|
+
assert_nothing_raised{ Readline.completion_case_fold = false }
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_completion_proc_expected_errors
|
66
|
+
assert_raise(ArgumentError){ Readline.completion_proc = 1 }
|
67
|
+
assert_raise(ArgumentError){ Readline.completion_proc = 'a' }
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_vi_editing_mode_basic
|
71
|
+
assert_respond_to(Readline, :vi_editing_mode)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_emacs_editing_mode_basic
|
75
|
+
assert_respond_to(Readline, :emacs_editing_mode)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_completion_append_character_get_basic
|
79
|
+
assert_respond_to(Readline, :completion_append_character)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_completion_append_character_get
|
83
|
+
assert_equal(' ', Readline.completion_append_character) # default
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_completion_append_character_set_basic
|
87
|
+
assert_respond_to(Readline, :completion_append_character=)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_completion_append_character_set
|
91
|
+
assert_nothing_raised{ Readline.completion_append_character }
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_completion_append_character
|
95
|
+
orig_char = Readline.completion_append_character
|
96
|
+
begin
|
97
|
+
[
|
98
|
+
[ "x", "x" ],
|
99
|
+
[ "xyx", "x" ],
|
100
|
+
[ " ", " " ],
|
101
|
+
[ "\t", "\t" ],
|
102
|
+
[ "", nil ],
|
103
|
+
].each do |data, expected|
|
104
|
+
Readline.completion_append_character = data
|
105
|
+
assert_equal(expected, Readline.completion_append_character,
|
106
|
+
"failed case: [#{data.inspect}, #{expected.inspect}]")
|
107
|
+
end
|
108
|
+
ensure
|
109
|
+
Readline.completion_append_character = orig_char
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_basic_word_break_characters_get_basic
|
114
|
+
assert_respond_to(Readline, :basic_word_break_characters)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_basic_word_break_characters_get
|
118
|
+
assert_equal(" \t\n\"\\'`@$><=|&{(", Readline.basic_word_break_characters)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_basic_word_break_characters_set_basic
|
122
|
+
assert_respond_to(Readline, :basic_word_break_characters=)
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_basic_word_break_characters_set
|
126
|
+
assert_nothing_raised{ Readline.basic_word_break_characters = " \t\n\"\\'`@$><=|&{(" }
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_basic_quote_characters_get_basic
|
130
|
+
assert_respond_to(Readline, :basic_quote_characters)
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_basic_quote_characters_get
|
134
|
+
assert_nothing_raised{ Readline.basic_quote_characters }
|
135
|
+
assert_equal("\"'", Readline.basic_quote_characters)
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_basic_quote_characters_set_basic
|
139
|
+
assert_respond_to(Readline, :basic_quote_characters=)
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_basic_quote_characters_set
|
143
|
+
assert_nothing_raised{ Readline.basic_quote_characters = "\"'" }
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_some_character_methods
|
147
|
+
expecteds = [ " ", " .,|\t", "" ]
|
148
|
+
[
|
149
|
+
:basic_word_break_characters,
|
150
|
+
:completer_word_break_characters,
|
151
|
+
:basic_quote_characters,
|
152
|
+
:completer_quote_characters,
|
153
|
+
:filename_quote_characters,
|
154
|
+
].each do |method|
|
155
|
+
begin
|
156
|
+
saved = Readline.send(method)
|
157
|
+
expecteds.each do |e|
|
158
|
+
Readline.send("#{method}=".to_sym, e)
|
159
|
+
assert_equal(e, Readline.send(method),
|
160
|
+
"failed case #{e.inspect} for method #{method}")
|
161
|
+
end
|
162
|
+
ensure
|
163
|
+
Readline.send("#{method}=".to_sym, saved) if saved
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_attempted_comp_func_returns_nil_when_no_completion_proc_set
|
169
|
+
assert_equal nil, Readline.readline_attempted_completion_function("12", 0, 1)
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_attempted_comp_func_case_folding
|
173
|
+
Readline.completion_proc = Proc.new do |word|
|
133
174
|
%w( 123456 123abc abc123 ).grep(/^#{word}/i)
|
134
|
-
|
175
|
+
end
|
135
176
|
|
136
|
-
|
177
|
+
Readline.completion_case_fold = true
|
137
178
|
|
138
|
-
|
179
|
+
assert_equal [ "123", "123456", "123abc", nil ], Readline.readline_attempted_completion_function("123", 0, 3)
|
139
180
|
|
140
|
-
|
181
|
+
assert_equal [ "123abc", nil, nil ], Readline.readline_attempted_completion_function("123A", 0, 3)
|
141
182
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
183
|
+
ensure
|
184
|
+
Readline.module_eval do
|
185
|
+
@completion_proc = nil
|
186
|
+
end
|
187
|
+
end
|
147
188
|
|
148
|
-
|
149
|
-
|
189
|
+
def test_attempted_comp_func_removes_replacement_from_possible_matches
|
190
|
+
Readline.completion_proc = Proc.new do |word|
|
150
191
|
%w( 123456 123abc abc123 ).grep(/^#{word}/)
|
151
|
-
|
192
|
+
end
|
152
193
|
|
153
|
-
|
194
|
+
assert_equal [ "123", "123456", "123abc", nil ], Readline.readline_attempted_completion_function("12", 0, 1)
|
154
195
|
|
155
|
-
|
196
|
+
assert_equal [ "123", "123456", "123abc", nil ], Readline.readline_attempted_completion_function("123", 0, 2)
|
156
197
|
|
157
|
-
|
198
|
+
assert_equal [ "123456", nil, nil ], Readline.readline_attempted_completion_function("1234", 0, 3)
|
158
199
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
200
|
+
ensure
|
201
|
+
Readline.module_eval do
|
202
|
+
@completion_proc = nil
|
203
|
+
end
|
204
|
+
end
|
164
205
|
|
165
|
-
|
166
|
-
|
167
|
-
|
206
|
+
def teardown
|
207
|
+
@proc = nil
|
208
|
+
end
|
168
209
|
end
|