mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
f8ea2860b0
The command prompt on Windows always uses Unicode to take input and print output but most Reline implementation depends on Encoding.default_external. This commit introduces an abstracted structure about the encoding of Reline.
23 lines
810 B
Ruby
23 lines
810 B
Ruby
require_relative 'helper'
|
|
|
|
class Reline::LineEditor::StringProcessingTest < Reline::TestCase
|
|
def setup
|
|
Reline.send(:test_mode)
|
|
@prompt = '> '
|
|
@config = Reline::Config.new
|
|
Reline::HISTORY.instance_variable_set(:@config, @config)
|
|
@encoding = (RELINE_TEST_ENCODING rescue Encoding.default_external)
|
|
@line_editor = Reline::LineEditor.new(@config, @encoding)
|
|
@line_editor.reset(@prompt, encoding: @encoding)
|
|
end
|
|
|
|
def test_calculate_width
|
|
width = @line_editor.send(:calculate_width, 'Ruby string')
|
|
assert_equal('Ruby string'.size, width)
|
|
end
|
|
|
|
def test_calculate_width_with_escape_sequence
|
|
width = @line_editor.send(:calculate_width, "\1\e[31m\2RubyColor\1\e[34m\2 default string \1\e[m\2>", true)
|
|
assert_equal('RubyColor default string >'.size, width)
|
|
end
|
|
end
|