1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/reline/test_reline.rb

278 lines
7.6 KiB
Ruby
Raw Normal View History

2019-07-16 08:26:30 -04:00
require_relative 'helper'
require "reline"
class Reline::Test < Reline::TestCase
class DummyCallbackObject
def call; end
end
2019-07-16 08:26:30 -04:00
def setup
end
def teardown
Reline.test_reset
end
def test_completion_append_character
2019-10-02 06:56:55 -04:00
assert_equal(nil, Reline.completion_append_character)
2019-07-16 08:26:30 -04:00
Reline.completion_append_character = ""
2019-10-02 06:56:55 -04:00
assert_equal(nil, Reline.completion_append_character)
2019-07-16 08:26:30 -04:00
2019-08-18 03:07:20 -04:00
Reline.completion_append_character = "a".encode(Encoding::ASCII)
2019-10-02 06:56:55 -04:00
assert_equal("a", Reline.completion_append_character)
assert_equal(get_reline_encoding, Reline.completion_append_character.encoding)
2019-07-16 08:26:30 -04:00
2019-08-18 03:07:20 -04:00
Reline.completion_append_character = "ba".encode(Encoding::ASCII)
2019-10-02 06:56:55 -04:00
assert_equal("b", Reline.completion_append_character)
assert_equal(get_reline_encoding, Reline.completion_append_character.encoding)
2019-07-16 08:26:30 -04:00
2019-08-18 03:07:20 -04:00
Reline.completion_append_character = "cba".encode(Encoding::ASCII)
2019-10-02 06:56:55 -04:00
assert_equal("c", Reline.completion_append_character)
assert_equal(get_reline_encoding, Reline.completion_append_character.encoding)
2019-07-16 08:26:30 -04:00
Reline.completion_append_character = nil
2019-10-02 06:56:55 -04:00
assert_equal(nil, Reline.completion_append_character)
2019-07-16 08:26:30 -04:00
end
def test_basic_word_break_characters
2019-10-02 06:56:55 -04:00
assert_equal(" \t\n`><=;|&{(", Reline.basic_word_break_characters)
2019-07-16 08:26:30 -04:00
2019-08-18 03:07:20 -04:00
Reline.basic_word_break_characters = "[".encode(Encoding::ASCII)
2019-10-02 06:56:55 -04:00
assert_equal("[", Reline.basic_word_break_characters)
assert_equal(get_reline_encoding, Reline.basic_word_break_characters.encoding)
2019-07-16 08:26:30 -04:00
end
def test_completer_word_break_characters
2019-10-02 06:56:55 -04:00
assert_equal(" \t\n`><=;|&{(", Reline.completer_word_break_characters)
2019-07-16 08:26:30 -04:00
2019-08-18 03:07:20 -04:00
Reline.completer_word_break_characters = "[".encode(Encoding::ASCII)
2019-10-02 06:56:55 -04:00
assert_equal("[", Reline.completer_word_break_characters)
assert_equal(get_reline_encoding, Reline.completer_word_break_characters.encoding)
2019-07-16 08:26:30 -04:00
end
def test_basic_quote_characters
2019-10-02 06:56:55 -04:00
assert_equal('"\'', Reline.basic_quote_characters)
2019-07-16 08:26:30 -04:00
2019-08-18 03:07:20 -04:00
Reline.basic_quote_characters = "`".encode(Encoding::ASCII)
2019-10-02 06:56:55 -04:00
assert_equal("`", Reline.basic_quote_characters)
assert_equal(get_reline_encoding, Reline.basic_quote_characters.encoding)
2019-07-16 08:26:30 -04:00
end
def test_completer_quote_characters
2019-10-02 06:56:55 -04:00
assert_equal('"\'', Reline.completer_quote_characters)
2019-07-16 08:26:30 -04:00
2019-08-18 03:07:20 -04:00
Reline.completer_quote_characters = "`".encode(Encoding::ASCII)
2019-10-02 06:56:55 -04:00
assert_equal("`", Reline.completer_quote_characters)
assert_equal(get_reline_encoding, Reline.completer_quote_characters.encoding)
2019-07-16 08:26:30 -04:00
end
def test_filename_quote_characters
2019-10-02 06:56:55 -04:00
assert_equal('', Reline.filename_quote_characters)
2019-07-16 08:26:30 -04:00
2019-08-18 03:07:20 -04:00
Reline.filename_quote_characters = "\'".encode(Encoding::ASCII)
2019-10-02 06:56:55 -04:00
assert_equal("\'", Reline.filename_quote_characters)
assert_equal(get_reline_encoding, Reline.filename_quote_characters.encoding)
2019-07-16 08:26:30 -04:00
end
def test_special_prefixes
2019-10-02 06:56:55 -04:00
assert_equal('', Reline.special_prefixes)
2019-07-16 08:26:30 -04:00
2019-08-18 03:07:20 -04:00
Reline.special_prefixes = "\'".encode(Encoding::ASCII)
2019-10-02 06:56:55 -04:00
assert_equal("\'", Reline.special_prefixes)
assert_equal(get_reline_encoding, Reline.special_prefixes.encoding)
2019-07-16 08:26:30 -04:00
end
def test_completion_case_fold
2019-10-02 06:56:55 -04:00
assert_equal(nil, Reline.completion_case_fold)
2019-07-16 08:26:30 -04:00
Reline.completion_case_fold = true
2019-10-02 06:56:55 -04:00
assert_equal(true, Reline.completion_case_fold)
2019-07-16 08:26:30 -04:00
2019-08-18 03:07:20 -04:00
Reline.completion_case_fold = "hoge".encode(Encoding::ASCII)
2019-10-02 06:56:55 -04:00
assert_equal("hoge", Reline.completion_case_fold)
2019-07-16 08:26:30 -04:00
end
def test_completion_proc
skip unless Reline.completion_proc == nil
# Another test can set Reline.completion_proc
# assert_equal(nil, Reline.completion_proc)
2019-07-16 08:26:30 -04:00
p = proc {}
Reline.completion_proc = p
2019-10-02 06:56:55 -04:00
assert_equal(p, Reline.completion_proc)
2019-07-16 08:26:30 -04:00
l = lambda {}
Reline.completion_proc = l
2019-10-02 06:56:55 -04:00
assert_equal(l, Reline.completion_proc)
2019-07-16 08:26:30 -04:00
assert_raise(ArgumentError) { Reline.completion_proc = 42 }
assert_raise(ArgumentError) { Reline.completion_proc = "hoge" }
dummy = DummyCallbackObject.new
Reline.completion_proc = dummy
assert_equal(dummy, Reline.completion_proc)
2019-07-16 08:26:30 -04:00
end
def test_output_modifier_proc
2019-10-02 06:56:55 -04:00
assert_equal(nil, Reline.output_modifier_proc)
2019-07-16 08:26:30 -04:00
p = proc {}
Reline.output_modifier_proc = p
2019-10-02 06:56:55 -04:00
assert_equal(p, Reline.output_modifier_proc)
2019-07-16 08:26:30 -04:00
l = lambda {}
Reline.output_modifier_proc = l
2019-10-02 06:56:55 -04:00
assert_equal(l, Reline.output_modifier_proc)
2019-07-16 08:26:30 -04:00
assert_raise(ArgumentError) { Reline.output_modifier_proc = 42 }
assert_raise(ArgumentError) { Reline.output_modifier_proc = "hoge" }
dummy = DummyCallbackObject.new
Reline.output_modifier_proc = dummy
assert_equal(dummy, Reline.output_modifier_proc)
2019-07-16 08:26:30 -04:00
end
def test_prompt_proc
2019-10-02 06:56:55 -04:00
assert_equal(nil, Reline.prompt_proc)
2019-07-16 08:26:30 -04:00
p = proc {}
Reline.prompt_proc = p
2019-10-02 06:56:55 -04:00
assert_equal(p, Reline.prompt_proc)
2019-07-16 08:26:30 -04:00
l = lambda {}
Reline.prompt_proc = l
2019-10-02 06:56:55 -04:00
assert_equal(l, Reline.prompt_proc)
2019-07-16 08:26:30 -04:00
assert_raise(ArgumentError) { Reline.prompt_proc = 42 }
assert_raise(ArgumentError) { Reline.prompt_proc = "hoge" }
dummy = DummyCallbackObject.new
Reline.prompt_proc = dummy
assert_equal(dummy, Reline.prompt_proc)
2019-07-16 08:26:30 -04:00
end
def test_auto_indent_proc
2019-10-02 06:56:55 -04:00
assert_equal(nil, Reline.auto_indent_proc)
2019-07-16 08:26:30 -04:00
p = proc {}
Reline.auto_indent_proc = p
2019-10-02 06:56:55 -04:00
assert_equal(p, Reline.auto_indent_proc)
2019-07-16 08:26:30 -04:00
l = lambda {}
Reline.auto_indent_proc = l
2019-10-02 06:56:55 -04:00
assert_equal(l, Reline.auto_indent_proc)
2019-07-16 08:26:30 -04:00
assert_raise(ArgumentError) { Reline.auto_indent_proc = 42 }
assert_raise(ArgumentError) { Reline.auto_indent_proc = "hoge" }
dummy = DummyCallbackObject.new
Reline.auto_indent_proc = dummy
assert_equal(dummy, Reline.auto_indent_proc)
2019-07-16 08:26:30 -04:00
end
def test_pre_input_hook
2019-10-02 06:56:55 -04:00
assert_equal(nil, Reline.pre_input_hook)
2019-07-16 08:26:30 -04:00
p = proc {}
Reline.pre_input_hook = p
2019-10-02 06:56:55 -04:00
assert_equal(p, Reline.pre_input_hook)
2019-07-16 08:26:30 -04:00
l = lambda {}
Reline.pre_input_hook = l
2019-10-02 06:56:55 -04:00
assert_equal(l, Reline.pre_input_hook)
2019-07-16 08:26:30 -04:00
end
def test_dig_perfect_match_proc
2019-10-02 06:56:55 -04:00
assert_equal(nil, Reline.dig_perfect_match_proc)
2019-07-16 08:26:30 -04:00
p = proc {}
Reline.dig_perfect_match_proc = p
2019-10-02 06:56:55 -04:00
assert_equal(p, Reline.dig_perfect_match_proc)
2019-07-16 08:26:30 -04:00
l = lambda {}
Reline.dig_perfect_match_proc = l
2019-10-02 06:56:55 -04:00
assert_equal(l, Reline.dig_perfect_match_proc)
2019-07-16 08:26:30 -04:00
assert_raise(ArgumentError) { Reline.dig_perfect_match_proc = 42 }
assert_raise(ArgumentError) { Reline.dig_perfect_match_proc = "hoge" }
dummy = DummyCallbackObject.new
Reline.dig_perfect_match_proc = dummy
assert_equal(dummy, Reline.dig_perfect_match_proc)
2019-07-16 08:26:30 -04:00
end
def test_insert_text
# TODO
end
def test_line_buffer
# TODO
end
def test_point
# TODO
end
def test_input=
# TODO
assert_raise(TypeError) do
Reline.input = "This is not a file."
end
end
def test_output=
# TODO
assert_raise(TypeError) do
Reline.output = "This is not a file."
end
end
def test_vi_editing_mode
Reline.vi_editing_mode
2019-10-02 06:56:55 -04:00
assert_equal(Reline::KeyActor::ViInsert, Reline.send(:core).config.editing_mode.class)
2019-07-16 08:26:30 -04:00
end
def test_emacs_editing_mode
Reline.emacs_editing_mode
2019-10-02 06:56:55 -04:00
assert_equal(Reline::KeyActor::Emacs, Reline.send(:core).config.editing_mode.class)
2019-07-16 08:26:30 -04:00
end
def test_editing_mode
# TODO
end
def test_readmultiline
# readmultiline is module function
2019-11-13 01:22:39 -05:00
assert_include(Reline.methods, :readmultiline)
assert_include(Reline.private_instance_methods, :readmultiline)
2019-07-16 08:26:30 -04:00
end
def test_readline
# readline is module function
2019-11-13 01:22:39 -05:00
assert_include(Reline.methods, :readline)
assert_include(Reline.private_instance_methods, :readline)
2019-07-16 08:26:30 -04:00
end
def test_inner_readline
# TODO in Reline::Core
end
def test_read_io
# TODO in Reline::Core
end
def test_read_escaped_key
# TODO in Reline::Core
end
def test_may_req_ambiguous_char_width
# TODO in Reline::Core
end
def get_reline_encoding
RUBY_PLATFORM =~ /mswin|mingw/ ? Encoding::UTF_8 : Encoding::default_external
end
2019-07-16 08:26:30 -04:00
end