2019-07-16 08:26:30 -04:00
|
|
|
require_relative 'helper'
|
2021-10-11 04:30:02 -04:00
|
|
|
require 'reline'
|
2021-10-11 04:49:54 -04:00
|
|
|
require 'stringio'
|
2019-07-16 08:26:30 -04:00
|
|
|
|
|
|
|
class Reline::Test < Reline::TestCase
|
2019-11-19 19:13:42 -05:00
|
|
|
class DummyCallbackObject
|
|
|
|
def call; end
|
|
|
|
end
|
|
|
|
|
2019-07-16 08:26:30 -04:00
|
|
|
def setup
|
2020-05-12 18:25:57 -04:00
|
|
|
Reline.output_modifier_proc = nil
|
|
|
|
Reline.completion_proc = nil
|
|
|
|
Reline.prompt_proc = nil
|
|
|
|
Reline.auto_indent_proc = nil
|
|
|
|
Reline.pre_input_hook = nil
|
|
|
|
Reline.dig_perfect_match_proc = nil
|
2019-07-16 08:26:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
Reline.test_reset
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_completion_append_character
|
2020-05-13 23:27:13 -04:00
|
|
|
completion_append_character = 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
|
|
|
|
|
|
|
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)
|
2020-01-18 15:22:24 -05:00
|
|
|
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)
|
2020-01-18 15:22:24 -05:00
|
|
|
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)
|
2020-01-18 15:22:24 -05:00
|
|
|
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)
|
2020-05-13 23:27:13 -04:00
|
|
|
ensure
|
|
|
|
Reline.completion_append_character = completion_append_character
|
2019-07-16 08:26:30 -04:00
|
|
|
end
|
|
|
|
|
2022-06-28 09:08:50 -04:00
|
|
|
def test_dialog_color_configuration
|
|
|
|
# defaults
|
2022-06-28 09:39:56 -04:00
|
|
|
assert_equal(:cyan, Reline.dialog_default_bg_color)
|
|
|
|
assert_equal(:white, Reline.dialog_default_fg_color)
|
2022-07-21 06:15:39 -04:00
|
|
|
assert_equal(:magenta, Reline.dialog_highlight_bg_color)
|
|
|
|
assert_equal(:white, Reline.dialog_highlight_fg_color)
|
2022-06-28 09:39:56 -04:00
|
|
|
|
|
|
|
Reline.dialog_default_bg_color = :black
|
|
|
|
assert_equal(:black, Reline.dialog_default_bg_color)
|
|
|
|
assert_equal(40, Reline.dialog_default_bg_color_sequence)
|
|
|
|
|
|
|
|
Reline.dialog_default_fg_color = :white
|
|
|
|
assert_equal(:white, Reline.dialog_default_fg_color)
|
|
|
|
assert_equal(37, Reline.dialog_default_fg_color_sequence)
|
|
|
|
|
2022-07-21 06:15:39 -04:00
|
|
|
Reline.dialog_highlight_bg_color = :white
|
|
|
|
assert_equal(:white, Reline.dialog_highlight_bg_color)
|
|
|
|
assert_equal(47, Reline.dialog_highlight_bg_color_sequence)
|
2022-06-28 09:39:56 -04:00
|
|
|
|
2022-07-21 06:15:39 -04:00
|
|
|
Reline.dialog_highlight_fg_color = :black
|
|
|
|
assert_equal(:black, Reline.dialog_highlight_fg_color)
|
|
|
|
assert_equal(30, Reline.dialog_highlight_fg_color_sequence)
|
2022-06-28 09:39:56 -04:00
|
|
|
|
|
|
|
# test value validation
|
|
|
|
assert_raise(ArgumentError) do
|
2022-07-21 06:15:39 -04:00
|
|
|
Reline.dialog_highlight_fg_color = :foo
|
2022-06-28 09:39:56 -04:00
|
|
|
end
|
2022-06-28 09:08:50 -04:00
|
|
|
end
|
|
|
|
|
2019-07-16 08:26:30 -04:00
|
|
|
def test_basic_word_break_characters
|
2020-05-13 23:27:13 -04:00
|
|
|
basic_word_break_characters = Reline.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)
|
2020-01-18 15:22:24 -05:00
|
|
|
assert_equal(get_reline_encoding, Reline.basic_word_break_characters.encoding)
|
2020-05-13 23:27:13 -04:00
|
|
|
ensure
|
|
|
|
Reline.basic_word_break_characters = basic_word_break_characters
|
2019-07-16 08:26:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_completer_word_break_characters
|
2020-05-13 23:27:13 -04:00
|
|
|
completer_word_break_characters = Reline.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)
|
2020-01-18 15:22:24 -05:00
|
|
|
assert_equal(get_reline_encoding, Reline.completer_word_break_characters.encoding)
|
2021-03-24 01:25:06 -04:00
|
|
|
|
|
|
|
assert_nothing_raised { Reline.completer_word_break_characters = '' }
|
2020-05-13 23:27:13 -04:00
|
|
|
ensure
|
|
|
|
Reline.completer_word_break_characters = completer_word_break_characters
|
2019-07-16 08:26:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_basic_quote_characters
|
2020-05-13 23:27:13 -04:00
|
|
|
basic_quote_characters = Reline.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)
|
2020-01-18 15:22:24 -05:00
|
|
|
assert_equal(get_reline_encoding, Reline.basic_quote_characters.encoding)
|
2020-05-13 23:27:13 -04:00
|
|
|
ensure
|
|
|
|
Reline.basic_quote_characters = basic_quote_characters
|
2019-07-16 08:26:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_completer_quote_characters
|
2020-05-13 23:27:13 -04:00
|
|
|
completer_quote_characters = Reline.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)
|
2020-01-18 15:22:24 -05:00
|
|
|
assert_equal(get_reline_encoding, Reline.completer_quote_characters.encoding)
|
2021-03-24 01:25:06 -04:00
|
|
|
|
|
|
|
assert_nothing_raised { Reline.completer_quote_characters = '' }
|
2020-05-13 23:27:13 -04:00
|
|
|
ensure
|
|
|
|
Reline.completer_quote_characters = completer_quote_characters
|
2019-07-16 08:26:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_filename_quote_characters
|
2020-05-13 23:27:13 -04:00
|
|
|
filename_quote_characters = Reline.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)
|
2020-01-18 15:22:24 -05:00
|
|
|
assert_equal(get_reline_encoding, Reline.filename_quote_characters.encoding)
|
2020-05-13 23:27:13 -04:00
|
|
|
ensure
|
|
|
|
Reline.filename_quote_characters = filename_quote_characters
|
2019-07-16 08:26:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_special_prefixes
|
2020-05-13 23:27:13 -04:00
|
|
|
special_prefixes = Reline.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)
|
2020-01-18 15:22:24 -05:00
|
|
|
assert_equal(get_reline_encoding, Reline.special_prefixes.encoding)
|
2020-05-13 23:27:13 -04:00
|
|
|
ensure
|
|
|
|
Reline.special_prefixes = special_prefixes
|
2019-07-16 08:26:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_completion_case_fold
|
2020-05-13 23:27:13 -04:00
|
|
|
completion_case_fold = Reline.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)
|
2020-05-13 23:27:13 -04:00
|
|
|
ensure
|
|
|
|
Reline.completion_case_fold = completion_case_fold
|
2019-07-16 08:26:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_completion_proc
|
2021-12-29 05:29:30 -05:00
|
|
|
omit unless Reline.completion_proc == nil
|
2020-03-01 23:42:35 -05:00
|
|
|
# Another test can set Reline.completion_proc
|
|
|
|
|
|
|
|
# assert_equal(nil, Reline.completion_proc)
|
2019-07-16 08:26:30 -04:00
|
|
|
|
2021-12-20 00:39:27 -05:00
|
|
|
dummy_proc = proc {}
|
|
|
|
Reline.completion_proc = dummy_proc
|
|
|
|
assert_equal(dummy_proc, 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" }
|
2019-11-19 19:13:42 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
2021-12-20 00:39:27 -05:00
|
|
|
dummy_proc = proc {}
|
|
|
|
Reline.output_modifier_proc = dummy_proc
|
|
|
|
assert_equal(dummy_proc, 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" }
|
2019-11-19 19:13:42 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
2021-12-20 00:39:27 -05:00
|
|
|
dummy_proc = proc {}
|
|
|
|
Reline.prompt_proc = dummy_proc
|
|
|
|
assert_equal(dummy_proc, 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" }
|
2019-11-19 19:13:42 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
2021-12-20 00:39:27 -05:00
|
|
|
dummy_proc = proc {}
|
|
|
|
Reline.auto_indent_proc = dummy_proc
|
|
|
|
assert_equal(dummy_proc, 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" }
|
2019-11-19 19:13:42 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
2021-12-20 00:39:27 -05:00
|
|
|
dummy_proc = proc {}
|
|
|
|
Reline.pre_input_hook = dummy_proc
|
|
|
|
assert_equal(dummy_proc, 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
|
|
|
|
2021-12-20 00:39:27 -05:00
|
|
|
dummy_proc = proc {}
|
|
|
|
Reline.dig_perfect_match_proc = dummy_proc
|
|
|
|
assert_equal(dummy_proc, 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" }
|
2019-11-19 19:13:42 -05:00
|
|
|
|
|
|
|
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
|
2021-10-11 04:14:22 -04:00
|
|
|
assert_equal('', Reline.line_buffer)
|
2021-10-11 04:16:31 -04:00
|
|
|
assert_equal(0, Reline.point)
|
2021-10-11 04:14:22 -04:00
|
|
|
Reline.insert_text('abc')
|
|
|
|
assert_equal('abc', Reline.line_buffer)
|
2021-10-11 04:16:31 -04:00
|
|
|
assert_equal(3, Reline.point)
|
2019-07-16 08:26:30 -04:00
|
|
|
end
|
|
|
|
|
2021-10-11 04:28:43 -04:00
|
|
|
def test_delete_text
|
|
|
|
assert_equal('', Reline.line_buffer)
|
|
|
|
assert_equal(0, Reline.point)
|
|
|
|
Reline.insert_text('abc')
|
|
|
|
assert_equal('abc', Reline.line_buffer)
|
|
|
|
assert_equal(3, Reline.point)
|
|
|
|
Reline.delete_text()
|
|
|
|
assert_equal('', Reline.line_buffer)
|
|
|
|
assert_equal(0, Reline.point)
|
|
|
|
Reline.insert_text('abc')
|
|
|
|
Reline.delete_text(1)
|
|
|
|
assert_equal('a', Reline.line_buffer)
|
|
|
|
assert_equal(1, Reline.point)
|
|
|
|
Reline.insert_text('defghi')
|
|
|
|
Reline.delete_text(2, 2)
|
|
|
|
assert_equal('adghi', Reline.line_buffer)
|
|
|
|
assert_equal(5, Reline.point)
|
|
|
|
end
|
|
|
|
|
2021-10-11 04:49:54 -04:00
|
|
|
def test_set_input_and_output
|
2019-07-16 08:26:30 -04:00
|
|
|
assert_raise(TypeError) do
|
|
|
|
Reline.input = "This is not a file."
|
|
|
|
end
|
|
|
|
assert_raise(TypeError) do
|
|
|
|
Reline.output = "This is not a file."
|
|
|
|
end
|
2021-10-12 13:07:16 -04:00
|
|
|
|
2021-10-12 06:05:18 -04:00
|
|
|
input, to_write = IO.pipe
|
|
|
|
to_read, output = IO.pipe
|
2021-10-12 13:07:16 -04:00
|
|
|
unless Reline.__send__(:input=, input)
|
|
|
|
omit "Setting to input is not effective on #{Reline::IOGate}"
|
|
|
|
end
|
|
|
|
Reline.output = output
|
|
|
|
|
2021-10-11 04:49:54 -04:00
|
|
|
to_write.write "a\n"
|
|
|
|
result = Reline.readline
|
|
|
|
to_write.close
|
|
|
|
read_text = to_read.read_nonblock(100)
|
|
|
|
assert_equal('a', result)
|
|
|
|
refute(read_text.empty?)
|
2021-10-12 06:05:18 -04:00
|
|
|
ensure
|
|
|
|
input&.close
|
|
|
|
output&.close
|
|
|
|
to_read&.close
|
2019-07-16 08:26:30 -04:00
|
|
|
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
|
|
|
|
|
2021-12-17 00:16:59 -05:00
|
|
|
def test_add_dialog_proc
|
2021-12-20 00:39:27 -05:00
|
|
|
dummy_proc = proc {}
|
|
|
|
Reline.add_dialog_proc(:test_proc, dummy_proc)
|
2021-12-20 00:36:37 -05:00
|
|
|
d = Reline.dialog_proc(:test_proc)
|
2021-12-20 00:39:27 -05:00
|
|
|
assert_equal(dummy_proc, d.dialog_proc)
|
2021-12-17 00:16:59 -05:00
|
|
|
|
2021-12-20 00:44:26 -05:00
|
|
|
dummy_proc_2 = proc {}
|
|
|
|
Reline.add_dialog_proc(:test_proc, dummy_proc_2)
|
|
|
|
d = Reline.dialog_proc(:test_proc)
|
|
|
|
assert_equal(dummy_proc_2, d.dialog_proc)
|
|
|
|
|
2021-12-17 00:16:59 -05:00
|
|
|
l = lambda {}
|
|
|
|
Reline.add_dialog_proc(:test_lambda, l)
|
2021-12-20 00:36:37 -05:00
|
|
|
d = Reline.dialog_proc(:test_lambda)
|
|
|
|
assert_equal(l, d.dialog_proc)
|
2021-12-20 00:34:15 -05:00
|
|
|
|
|
|
|
assert_equal(nil, Reline.dialog_proc(:test_nothing))
|
2021-12-17 00:16:59 -05:00
|
|
|
|
|
|
|
assert_raise(ArgumentError) { Reline.add_dialog_proc(:error, 42) }
|
|
|
|
assert_raise(ArgumentError) { Reline.add_dialog_proc(:error, 'hoge') }
|
|
|
|
assert_raise(ArgumentError) { Reline.add_dialog_proc('error', proc {} ) }
|
|
|
|
|
|
|
|
dummy = DummyCallbackObject.new
|
|
|
|
Reline.add_dialog_proc(:dummy, dummy)
|
2021-12-20 00:36:37 -05:00
|
|
|
d = Reline.dialog_proc(:dummy)
|
|
|
|
assert_equal(dummy, d.dialog_proc)
|
2021-12-17 00:16:59 -05:00
|
|
|
end
|
|
|
|
|
2021-12-20 00:44:50 -05:00
|
|
|
def test_add_dialog_proc_with_context
|
|
|
|
dummy_proc = proc {}
|
|
|
|
array = Array.new
|
|
|
|
Reline.add_dialog_proc(:test_proc, dummy_proc, array)
|
|
|
|
d = Reline.dialog_proc(:test_proc)
|
|
|
|
assert_equal(dummy_proc, d.dialog_proc)
|
|
|
|
assert_equal(array, d.context)
|
|
|
|
|
|
|
|
Reline.add_dialog_proc(:test_proc, dummy_proc, nil)
|
|
|
|
d = Reline.dialog_proc(:test_proc)
|
|
|
|
assert_equal(dummy_proc, d.dialog_proc)
|
|
|
|
assert_equal(nil, d.context)
|
|
|
|
end
|
|
|
|
|
2019-07-16 08:26:30 -04:00
|
|
|
def test_readmultiline
|
2019-11-10 02:00:41 -05:00
|
|
|
# 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
|
2019-11-10 02:00:41 -05:00
|
|
|
# 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_read_io
|
|
|
|
# TODO in Reline::Core
|
|
|
|
end
|
|
|
|
|
2022-09-01 01:14:46 -04:00
|
|
|
def test_dumb_terminal
|
|
|
|
lib = File.expand_path("../../lib", __dir__)
|
|
|
|
out = IO.popen([{"TERM"=>"dumb"}, "ruby", "-I#{lib}", "-rreline", "-e", "p Reline::IOGate"], &:read)
|
|
|
|
assert_equal("Reline::GeneralIO", out.chomp)
|
|
|
|
end
|
|
|
|
|
2020-01-18 15:22:24 -05:00
|
|
|
def get_reline_encoding
|
2021-06-21 09:08:13 -04:00
|
|
|
if encoding = Reline::IOGate.encoding
|
2021-04-19 23:00:08 -04:00
|
|
|
encoding
|
|
|
|
elsif RUBY_PLATFORM =~ /mswin|mingw/
|
|
|
|
Encoding::UTF_8
|
|
|
|
else
|
|
|
|
Encoding::default_external
|
|
|
|
end
|
2020-01-18 15:22:24 -05:00
|
|
|
end
|
2019-07-16 08:26:30 -04:00
|
|
|
end
|