Skip to content

Commit

Permalink
Remove invalid encoding string "\M-[char]" from test code, remove unu…
Browse files Browse the repository at this point in the history
…sed code/arg/options
  • Loading branch information
tompng committed Jan 1, 2025
1 parent e6eb5d2 commit 0692782
Show file tree
Hide file tree
Showing 3 changed files with 330 additions and 346 deletions.
40 changes: 12 additions & 28 deletions test/reline/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,44 +86,28 @@ def test_rubybin
end

class Reline::TestCase < Test::Unit::TestCase
private def convert_str(input, options = {}, normalized = nil)
private def convert_str(input)
return nil if input.nil?
input = input.chars.map { |c|
if Reline::Unicode::EscapedChars.include?(c.ord)
c
else
c.encode(@line_editor.encoding, Encoding::UTF_8, **options)
end
}.join
rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError
if unicode?(input.encoding)
input = input.unicode_normalize(:nfc)
if normalized
options[:undef] = :replace
options[:replace] = '?'
end
normalized = true
retry
input.encode(@line_editor.encoding, Encoding::UTF_8)
rescue Encoding::UndefinedConversionError
return input unless unicode?(input.encoding)

input = input.unicode_normalize(:nfc)
begin
input.encode(@line_editor.encoding, Encoding::UTF_8)
rescue Encoding::UndefinedConversionError
input.encode(@line_editor.encoding, Encoding::UTF_8, undef: :replace, replace: '?')
end
input
end

def input_key_by_symbol(method_symbol, char: nil, csi: false)
char ||= csi ? "\e[A" : "\C-a"
@line_editor.input_key(Reline::Key.new(char, method_symbol, false))
end

def input_keys(input, convert = true)
# Reline does not support convert-meta, but test data includes \M-char. It should be converted to ESC+char.
# Note that mixing unicode chars and \M-char is not recommended. "\M-C\M-\C-A" is a single unicode character.
input = input.chars.map do |c|
c.valid_encoding? ? c : "\e#{(c.bytes[0] & 0x7f).chr}"
end.join
input_raw_keys(input, convert)
end
def input_keys(input)
input = convert_str(input)

def input_raw_keys(input, convert = true)
input = convert_str(input) if convert
key_stroke = Reline::KeyStroke.new(@config, @encoding)
input_bytes = input.bytes
until input_bytes.empty?
Expand Down
Loading

0 comments on commit 0692782

Please sign in to comment.