summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2021-03-23 21:43:39 +0900
committeraycabta <aycabta@gmail.com>2021-03-24 15:43:27 +0900
commit758f2b35f93478c481902d9d3f8876216a5dcc4d (patch)
tree6d6515fbe13f246f503c1c5147d8eba4dce2f30b /test
parent4b33d860e84f0a5efeefbf8a68324801a0215a08 (diff)
[ruby/reline] Support preposing and postposing for Reline.completion_proc
https://github.com/ruby/reline/commit/1f469de90c
Diffstat (limited to 'test')
-rw-r--r--test/reline/test_string_processing.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/reline/test_string_processing.rb b/test/reline/test_string_processing.rb
index e76fa384f2..0e0ee9cc04 100644
--- a/test/reline/test_string_processing.rb
+++ b/test/reline/test_string_processing.rb
@@ -20,4 +20,58 @@ class Reline::LineEditor::StringProcessingTest < Reline::TestCase
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
+
+ def test_completion_proc_with_preposing_and_postposing
+ buf = ['def hoge', ' puts :aaa', 'end']
+
+ @line_editor.instance_variable_set(:@is_multiline, true)
+ @line_editor.instance_variable_set(:@buffer_of_lines, buf)
+ @line_editor.instance_variable_set(:@line, buf[1])
+ @line_editor.instance_variable_set(:@byte_pointer, 3)
+ @line_editor.instance_variable_set(:@cursor, 3)
+ @line_editor.instance_variable_set(:@cursor_max, 11)
+ @line_editor.instance_variable_set(:@line_index, 1)
+ @line_editor.instance_variable_set(:@completion_proc, proc { |target|
+ assert_equal('p', target)
+ })
+ @line_editor.__send__(:call_completion_proc)
+
+ @line_editor.instance_variable_set(:@is_multiline, true)
+ @line_editor.instance_variable_set(:@buffer_of_lines, buf)
+ @line_editor.instance_variable_set(:@line, buf[1])
+ @line_editor.instance_variable_set(:@byte_pointer, 6)
+ @line_editor.instance_variable_set(:@cursor, 6)
+ @line_editor.instance_variable_set(:@cursor_max, 11)
+ @line_editor.instance_variable_set(:@line_index, 1)
+ @line_editor.instance_variable_set(:@completion_proc, proc { |target, pre, post|
+ assert_equal('puts', target)
+ assert_equal("def hoge\n ", pre)
+ assert_equal(" :aaa\nend", post)
+ })
+ @line_editor.__send__(:call_completion_proc)
+
+ @line_editor.instance_variable_set(:@line, buf[0])
+ @line_editor.instance_variable_set(:@byte_pointer, 6)
+ @line_editor.instance_variable_set(:@cursor, 6)
+ @line_editor.instance_variable_set(:@cursor_max, 8)
+ @line_editor.instance_variable_set(:@line_index, 0)
+ @line_editor.instance_variable_set(:@completion_proc, proc { |target, pre, post|
+ assert_equal('ho', target)
+ assert_equal('def ', pre)
+ assert_equal("ge\n puts :aaa\nend", post)
+ })
+ @line_editor.__send__(:call_completion_proc)
+
+ @line_editor.instance_variable_set(:@line, buf[2])
+ @line_editor.instance_variable_set(:@byte_pointer, 1)
+ @line_editor.instance_variable_set(:@cursor, 1)
+ @line_editor.instance_variable_set(:@cursor_max, 3)
+ @line_editor.instance_variable_set(:@line_index, 2)
+ @line_editor.instance_variable_set(:@completion_proc, proc { |target, pre, post|
+ assert_equal('e', target)
+ assert_equal("def hoge\n puts :aaa\n", pre)
+ assert_equal('nd', post)
+ })
+ @line_editor.__send__(:call_completion_proc)
+ end
end