aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2019-11-21 07:28:18 +0900
committeraycabta <aycabta@gmail.com>2019-11-21 07:28:18 +0900
commit8f1062127e40767240aa0a0fe18fd48687bc04e9 (patch)
tree9dc2003ea6a66ba1e35e62e8d3265ad207e85697
parent9131e62f1862a1736d37d934cda603dc91b2c831 (diff)
downloadruby-8f1062127e40767240aa0a0fe18fd48687bc04e9.tar.gz
Add test/reline/test_string_processing.rb
-rw-r--r--test/reline/test_string_processing.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/reline/test_string_processing.rb b/test/reline/test_string_processing.rb
new file mode 100644
index 0000000000..4df0363848
--- /dev/null
+++ b/test/reline/test_string_processing.rb
@@ -0,0 +1,23 @@
+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)
+ @line_editor.reset(@prompt, @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