Skip to content

Commit

Permalink
support random order test.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ko1 committed Feb 28, 2020
1 parent 72c02aa commit f7be85a
Showing 1 changed file with 67 additions and 79 deletions.
146 changes: 67 additions & 79 deletions test/readline/test_readline.rb
Expand Up @@ -29,6 +29,7 @@ def teardown
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")
Expand Down Expand Up @@ -287,32 +288,6 @@ def test_completion_encoding
# 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
Expand Down Expand Up @@ -512,80 +487,93 @@ def test_setting_quoting_detection_proc
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
Expand Down

0 comments on commit f7be85a

Please sign in to comment.