8000 Refactor utf-8 strings and invalid strings in test code (#800) · ruby/reline@f09e7b1 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit f09e7b1

Browse files
authored
Refactor utf-8 strings and invalid strings in test code (#800)
* Remove invalid encoding string "\M-[char]" from test code, remove unused code/arg/options * Omit unicode unnoralized input test in non-utf8 testcase * Remove helper method and constant no longer used in testcode * Change key binding test to use realistic bytes instead of invalid byte sequence * Remove invalid byte sequence input from rendering test yamatanooroti handles invalid byte sequence input "\M-[char]" and converts it to "\e[char]" We don't need to use these invalid byte sequence and rely on the hack implemented in yamatanooroti
1 parent c5d5c44 commit f09e7b1

File tree

6 files changed

+364
-372
lines changed

6 files changed

+364
-372
lines changed

lib/reline/unicode.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class Reline::Unicode
3434
0x1F => '^_', # C-_ C-7
3535
0x7F => '^?', # C-? C-8
3636
}
37-
EscapedChars = EscapedPairs.keys.map(&:chr)
3837

3938
NON_PRINTING_START = "\1"
4039
NON_PRINTING_END = "\2"

test/reline/helper.rb

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -86,44 +86,22 @@ def test_rubybin
8686
end
8787

8888
class Reline::TestCase < Test::Unit::TestCase
89-
private def convert_str(input, options = {}, normalized = nil)
90-
return nil if input.nil?
91-
input = input.chars.map { |c|
92-
if Reline::Unicode::EscapedChars.include?(c.ord)
93-
c
94-
else
95-
c.encode(@line_editor.encoding, Encoding::UTF_8, **options)
96-
end
97-
}.join
98-
rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError
99-
if unicode?(input.encoding)
100-
input = input.unicode_normalize(:nfc)
101-
if normalized
102-
options[:undef] = :replace
103-
options[:replace] = '?'
104-
end
105-
normalized = true
106-
retry
107-
end
108-
input
89+
private def convert_str(input)
90+
input.encode(@line_editor.encoding, Encoding::UTF_8)
91+
end
92+
93+
def omit_unless_utf8
94+
omit "This test is for UTF-8 but the locale is #{Reline.core.encoding}" if Reline.core.encoding != Encoding::UTF_8
10995
end
11096

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

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

125-
def input_raw_keys(input, convert = true)
126-
input = convert_str(input) if convert
127105
key_stroke = Reline::KeyStroke.new(@config, @encoding)
128106
input_bytes = input.bytes
129107
until input_bytes.empty?
@@ -177,8 +155,4 @@ def assert_key_binding(input, method_symbol, editing_modes = [:emacs, :vi_insert
177155
assert_equal(method_symbol, @config.editing_mode.get(input.bytes))
178156
end
179157
end
180-
181-
private def unicode?(encoding)
182-
[Encoding::UTF_8, Encoding::UTF_16BE, Encoding::UTF_16LE, Encoding::UTF_32BE, Encoding::UTF_32LE].include?(encoding)
183-
end
184158
end

0 commit comments

Comments
 (0)
0