Skip to content

Commit

Permalink
Fix RELINE_TEST_ENCODING
Browse files Browse the repository at this point in the history
It was not working because it was not environment variable.
  • Loading branch information
ima1zumi committed Nov 10, 2024
1 parent 4d90743 commit ee686fa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
27 changes: 17 additions & 10 deletions test/reline/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
end

module Reline
class <<self
class << self
def test_mode(ansi: false)
@original_iogate = IOGate

if ENV['RELINE_TEST_ENCODING']
encoding = Encoding.find(ENV['RELINE_TEST_ENCODING'])
if Reline.const_defined?(:RELINE_TEST_ENCODING) && RELINE_TEST_ENCODING.is_a?(Encoding)
encoding = RELINE_TEST_ENCODING
else
encoding = Encoding::UTF_8
end
Expand Down Expand Up @@ -88,21 +88,24 @@ def test_rubybin
class Reline::TestCase < Test::Unit::TestCase
private def convert_str(input, options = {}, normalized = nil)
return nil if input.nil?
input.chars.map { |c|
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
input = input.unicode_normalize(:nfc)
if normalized
options[:undef] = :replace
options[:replace] = '?'
if unicode?(input.encoding)
input = input.unicode_normalize(:nfc)
if normalized
options[:undef] = :replace
options[:replace] = '?'
end
normalized = true
retry
end
normalized = true
retry
input
end

def input_key_by_symbol(input)
Expand Down Expand Up @@ -171,4 +174,8 @@ def assert_key_binding(input, method_symbol, editing_modes = [:emacs, :vi_insert
assert_equal(method_symbol, @config.editing_mode.get(input.bytes))
end
end

private def unicode?(encoding)
[Encoding::UTF_8, Encoding::UTF_16BE, Encoding::UTF_16LE, Encoding::UTF_32BE, Encoding::UTF_32LE].include?(encoding)
end
end
7 changes: 4 additions & 3 deletions test/reline/test_key_actor_emacs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,7 @@ def test_ed_argument_digit_by_meta_num
end

def test_halfwidth_kana_width_dakuten
omit "This test is for UTF-8 but the locale is #{Reline.core.encoding}" if Reline.core.encoding != Encoding::UTF_8
input_raw_keys('ガギゲゴ')
assert_line_around_cursor('ガギゲゴ', '')
input_keys("\C-b\C-b", false)
Expand Down Expand Up @@ -1514,7 +1515,7 @@ def test_vi_editing_mode
def test_undo
input_keys("\C-_", false)
assert_line_around_cursor('', '')
input_keys("aあb\C-h\C-h\C-h", false)
input_keys("aあb\C-h\C-h\C-h".encode(@encoding), false)
assert_line_around_cursor('', '')
input_keys("\C-_", false)
assert_line_around_cursor('a', '')
Expand All @@ -1535,7 +1536,7 @@ def test_undo_with_cursor_position
assert_line_around_cursor('a', 'c')
input_keys("\C-_", false)
assert_line_around_cursor('ab', 'c')
input_keys("あいう\C-b\C-h", false)
input_keys("あいう\C-b\C-h".encode(@encoding), false)
assert_line_around_cursor('abあ', 'うc')
input_keys("\C-_", false)
assert_line_around_cursor('abあい', 'うc')
Expand Down Expand Up @@ -1580,7 +1581,7 @@ def test_undo_with_many_times
end

def test_redo
input_keys("aあb", false)
input_keys("aあb".encode(@encoding), false)
assert_line_around_cursor('aあb', '')
input_keys("\M-\C-_", false)
assert_line_around_cursor('aあb', '')
Expand Down

0 comments on commit ee686fa

Please sign in to comment.