diff options
Diffstat (limited to 'test/reline/yamatanooroti/multiline_repl')
-rwxr-xr-x | test/reline/yamatanooroti/multiline_repl | 132 |
1 files changed, 123 insertions, 9 deletions
diff --git a/test/reline/yamatanooroti/multiline_repl b/test/reline/yamatanooroti/multiline_repl index 473d9d0f00..66bcf51e1a 100755 --- a/test/reline/yamatanooroti/multiline_repl +++ b/test/reline/yamatanooroti/multiline_repl @@ -1,14 +1,14 @@ #!/usr/bin/env ruby + +require 'bundler' +Bundler.require + require 'reline' require 'optparse' require_relative 'termination_checker' opt = OptionParser.new -opt.on('--prompt-list-cache-timeout VAL') { |v| - Reline::LineEditor.__send__(:remove_const, :PROMPT_LIST_CACHE_TIMEOUT) - Reline::LineEditor::PROMPT_LIST_CACHE_TIMEOUT = v.to_f -} opt.on('--dynamic-prompt') { Reline.prompt_proc = proc { |lines| lines.each_with_index.map { |l, i| @@ -27,8 +27,54 @@ opt.on('--broken-dynamic-prompt') { opt.on('--dynamic-prompt-returns-empty') { Reline.prompt_proc = proc { |l| [] } } +opt.on('--dynamic-prompt-with-newline') { + Reline.prompt_proc = proc { |lines| + range = lines.size > 1 ? (0..(lines.size - 2)) : (0..0) + lines[range].each_with_index.map { |l, i| + '[%04d\n]> ' % i + } + } +} +opt.on('--broken-dynamic-prompt-assert-no-escape-sequence') { + Reline.prompt_proc = proc { |lines| + has_escape_sequence = lines.join.include?("\e") + (lines.size + 1).times.map { |i| + has_escape_sequence ? 'error>' : '[%04d]> ' % i + } + } +} +opt.on('--color-bold') { + Reline.output_modifier_proc = ->(output, complete:){ + output.gsub(/./) { |c| "\e[1m#{c}\e[0m" } + } +} +opt.on('--dynamic-prompt-show-line') { + Reline.prompt_proc = proc { |lines| + lines.map { |l| + '[%4.4s]> ' % l + } + } +} + +def assert_auto_indent_params(lines, line_index, byte_pointer, is_newline) + raise 'Wrong lines type' unless lines.all?(String) + + line = lines[line_index] + raise 'Wrong line_index value' unless line + + # The condition `byte_pointer <= line.bytesize` is not satisfied. Maybe bug. + # Instead, loose constraint `byte_pointer <= line.bytesize + 1` seems to be satisfied when is_newline is false. + return if is_newline + + raise 'byte_pointer out of bounds' unless byte_pointer <= line.bytesize + 1 + raise 'Invalid byte_pointer' unless line.byteslice(0, byte_pointer).valid_encoding? +end + opt.on('--auto-indent') { - AutoIndent.new + Reline.auto_indent_proc = lambda do |lines, line_index, byte_pointer, is_newline| + assert_auto_indent_params(lines, line_index, byte_pointer, is_newline) + AutoIndent.calculate_indent(lines, line_index, byte_pointer, is_newline) + end } opt.on('--dialog VAL') { |v| Reline.add_dialog_proc(:simple_dialog, lambda { @@ -55,6 +101,15 @@ opt.on('--dialog VAL') { |v| natural to read and easy to write. RUBY + elsif v.include?('fullwidth') + contents = <<~RUBY.split("\n") + Rubyとは... + + オープンソースの動的なプログラミン + グ言語で、シンプルさと高い生産性を + 備えています。エレガントな文法を持 + ち、自然に読み書きができます。 + RUBY end if v.include?('scrollkey') dialog.trap_key = nil @@ -74,8 +129,14 @@ opt.on('--dialog VAL') { |v| if v.include?('scrollbar') scrollbar = true end - Reline::DialogRenderInfo.new(pos: cursor_pos, contents: contents, height: height, scrollbar: scrollbar) + if v.include?('alt-scrollbar') + scrollbar = true + end + Reline::DialogRenderInfo.new(pos: cursor_pos, contents: contents, height: height, scrollbar: scrollbar, face: :completion_dialog) }) + if v.include?('alt-scrollbar') + ENV['RELINE_ALT_SCROLLBAR'] = '1' + end } opt.on('--complete') { Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil| @@ -88,10 +149,64 @@ opt.on('--autocomplete') { %w{String Struct Symbol ScriptError SyntaxError Signal}.select{ |c| c.start_with?(target) } } } +opt.on('--autocomplete-empty') { + Reline.autocompletion = true + Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil| [] } +} opt.on('--autocomplete-long') { Reline.autocompletion = true Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil| - %w{String Struct Symbol StopIteration SystemCallError SystemExit SystemStackError ScriptError SyntaxError Signal SizedQueue Set SecureRandom Socket StringIO StringScanner Shellwords Syslog Singleton SDBM}.select{ |c| c.start_with?(target) } + %w{ + String + Struct + Symbol + StopIteration + SystemCallError + SystemExit + SystemStackError + ScriptError + SyntaxError + Signal + SizedQueue + Set + SecureRandom + Socket + StringIO + StringScanner + Shellwords + Syslog + Singleton + SDBM + }.select{ |c| c.start_with?(target) } + } +} +opt.on('--autocomplete-super-long') { + Reline.autocompletion = true + Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil| + c = +'A' + 2000.times.map{ s = "Str_#{c}"; c.succ!; s }.select{ |c| c.start_with?(target) } + } +} + +opt.on('--autocomplete-width-long') { + Reline.autocompletion = true + Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil| + %w{ + remove_instance_variable + respond_to? + ruby2_keywords + rand + readline + readlines + require + require_relative + raise + respond_to_missing? + redo + rescue + retry + return + }.select{ |c| c.start_with?(target) } } } opt.parse!(ARGV) @@ -104,8 +219,7 @@ end begin prompt = ENV['RELINE_TEST_PROMPT'] || 'prompt> ' puts 'Multiline REPL.' - checker = TerminationChecker.new - while code = Reline.readmultiline(prompt, true) { |code| checker.terminated?(code) } + while code = Reline.readmultiline(prompt, true) { |code| TerminationChecker.terminated?(code) } case code.chomp when 'exit', 'quit', 'q' exit 0 |