Skip to content

Commit ee686fa

Browse files
committed
Fix RELINE_TEST_ENCODING
It was not working because it was not environment variable.
1 parent 4d90743 commit ee686fa

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

test/reline/helper.rb

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
end
2020

2121
module Reline
22-
class <<self
22+
class << self
2323
def test_mode(ansi: false)
2424
@original_iogate = IOGate
2525

26-
if ENV['RELINE_TEST_ENCODING']
27-
encoding = Encoding.find(ENV['RELINE_TEST_ENCODING'])
26+
if Reline.const_defined?(:RELINE_TEST_ENCODING) && RELINE_TEST_ENCODING.is_a?(Encoding)
27+
encoding = RELINE_TEST_ENCODING
2828
else
2929
encoding = Encoding::UTF_8
3030
end
@@ -88,21 +88,24 @@ def test_rubybin
8888
class Reline::TestCase < Test::Unit::TestCase
8989
private def convert_str(input, options = {}, normalized = nil)
9090
return nil if input.nil?
91-
input.chars.map { |c|
91+
input = input.chars.map { |c|
9292
if Reline::Unicode::EscapedChars.include?(c.ord)
9393
c
9494
else
9595
c.encode(@line_editor.encoding, Encoding::UTF_8, **options)
9696
end
9797
}.join
9898
rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError
99-
input = input.unicode_normalize(:nfc)
100-
if normalized
101-
options[:undef] = :replace
102-
options[:replace] = '?'
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
103107
end
104-
normalized = true
105-
retry
108+
input
106109
end
107110

108111
def input_key_by_symbol(input)
@@ -171,4 +174,8 @@ def assert_key_binding(input, method_symbol, editing_modes = [:emacs, :vi_insert
171174
assert_equal(method_symbol, @config.editing_mode.get(input.bytes))
172175
end
173176
end
177+
178+
private def unicode?(encoding)
179+
[Encoding::UTF_8, Encoding::UTF_16BE, Encoding::UTF_16LE, Encoding::UTF_32BE, Encoding::UTF_32LE].include?(encoding)
180+
end
174181
end

test/reline/test_key_actor_emacs.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,7 @@ def test_ed_argument_digit_by_meta_num
14821482
end
14831483

14841484
def test_halfwidth_kana_width_dakuten
1485+
omit "This test is for UTF-8 but the locale is #{Reline.core.encoding}" if Reline.core.encoding != Encoding::UTF_8
14851486
input_raw_keys('ガギゲゴ')
14861487
assert_line_around_cursor('ガギゲゴ', '')
14871488
input_keys("\C-b\C-b", false)
@@ -1514,7 +1515,7 @@ def test_vi_editing_mode
15141515
def test_undo
15151516
input_keys("\C-_", false)
15161517
assert_line_around_cursor('', '')
1517-
input_keys("aあb\C-h\C-h\C-h", false)
1518+
input_keys("aあb\C-h\C-h\C-h".encode(@encoding), false)
15181519
assert_line_around_cursor('', '')
15191520
input_keys("\C-_", false)
15201521
assert_line_around_cursor('a', '')
@@ -1535,7 +1536,7 @@ def test_undo_with_cursor_position
15351536
assert_line_around_cursor('a', 'c')
15361537
input_keys("\C-_", false)
15371538
assert_line_around_cursor('ab', 'c')
1538-
input_keys("あいう\C-b\C-h", false)
1539+
input_keys("あいう\C-b\C-h".encode(@encoding), false)
15391540
assert_line_around_cursor('abあ', 'うc')
15401541
input_keys("\C-_", false)
15411542
assert_line_around_cursor('abあい', 'うc')
@@ -1580,7 +1581,7 @@ def test_undo_with_many_times
15801581
end
15811582

15821583
def test_redo
1583-
input_keys("aあb", false)
1584+
input_keys("aあb".encode(@encoding), false)
15841585
assert_line_around_cursor('aあb', '')
15851586
input_keys("\M-\C-_", false)
15861587
assert_line_around_cursor('aあb', '')

0 commit comments

Comments
 (0)