summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2020-02-28 14:28:24 (GMT)
committerKoichi Sasada <ko1@atdot.net>2020-02-28 14:32:56 (GMT)
commitf7be85a2b7b2f1e3485c6da8fb990ac47059ae12 (patch)
tree296a6768ecaaa399b0a9e660e0df32d8ad15614a
parent72c02aa4b79731c7f25c9267f74b347f1946c704 (diff)
support random order test.
test_readline: HISTORY should be empty. test_using_quoting_detection_proc: test_using_quoting_detection_proc_with_multibyte_input: Readline.completer_quote_characters= and Readline.completer_word_break_characters= doesn't accept nil, so skip if previous values are nil.
-rw-r--r--test/readline/test_readline.rb146
1 files changed, 67 insertions, 79 deletions
diff --git a/test/readline/test_readline.rb b/test/readline/test_readline.rb
index 0cab809..fa93376 100644
--- a/test/readline/test_readline.rb
+++ b/test/readline/test_readline.rb
@@ -29,6 +29,7 @@ module BasetestReadline
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")
@@ -287,32 +288,6 @@ module BasetestReadline
# filename_quote_characters
# special_prefixes
def test_some_characters_methods
- method_names = [
- "basic_word_break_characters",
- "completer_word_break_characters",
- "basic_quote_characters",
- "completer_quote_characters",
- "filename_quote_characters",
- "special_prefixes",
- ]
- method_names.each do |method_name|
- begin
- begin
- enc = get_default_internal_encoding
- saved = Readline.send(method_name.to_sym)
- expecteds = [" ", " .,|\t", ""]
- expecteds.each do |e|
- Readline.send((method_name + "=").to_sym, e)
- res = Readline.send(method_name.to_sym)
- assert_equal(e, res)
- assert_equal(enc, res.encoding, "Readline.#{method_name} should be #{enc.name}")
- end
- ensure
- Readline.send((method_name + "=").to_sym, saved) if saved
- end
- rescue NotImplementedError
- end
- end
end
def test_closed_outstream
@@ -512,80 +487,93 @@ module BasetestReadline
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.
+ skip unless saved_completer_quote_characters
+ skip unless saved_completer_word_break_characters
+
return unless Readline.respond_to?(:quoting_detection_proc=)
- passed_text = nil
- line = nil
+ 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
+ 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)
+ stdin.write("first second\\ third\t")
+ stdin.flush
+ line = Readline.readline('> ', false)
+ end
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
+ 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
- omit 'temporary omit for random order'
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.
+ skip unless saved_completer_quote_characters
+ skip 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
- passed_text = nil
- escaped_char_indexes = []
- line = nil
+ 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
+ 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)
+ stdin.write("\u3042\u3093 second\\ third\t")
+ stdin.flush
+ line = Readline.readline('> ', false)
+ end
end
- end
- assert_equal([10], escaped_char_indexes)
- assert_equal('second\\ third', passed_text)
- assert_equal("\u3042\u3093 completion", line)
- ensure
- Readline.completer_quote_characters = saved_completer_quote_characters if saved_completer_quote_characters
- Readline.completer_word_break_characters = saved_completer_word_break_characters if saved_completer_word_break_characters
+ 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