Skip to content

Commit

Permalink
Add helper method to get instance variable value of Reline::Config
Browse files Browse the repository at this point in the history
  • Loading branch information
ima1zumi committed Sep 3, 2024
1 parent 8df94cc commit 7234444
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions test/reline/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ def teardown
ENV['INPUTRC'] = @inputrc_backup
end

def get_config_variable(variable)
@config.instance_variable_get(variable)
end

def additional_key_bindings(keymap_label)
@config.instance_variable_get(:@additional_key_bindings)[keymap_label].instance_variable_get(:@key_bindings)
get_config_variable(:@additional_key_bindings)[keymap_label].instance_variable_get(:@key_bindings)
end

def registered_key_bindings(keys)
Expand All @@ -38,15 +42,15 @@ def test_read_lines
set show-mode-in-prompt on
LINES

assert_equal true, @config.instance_variable_get(:@show_mode_in_prompt)
assert_equal true, get_config_variable(:@show_mode_in_prompt)
end

def test_read_lines_with_variable
@config.read_lines(<<~LINES.lines)
set disable-completion on
LINES

assert_equal true, @config.instance_variable_get(:@disable_completion)
assert_equal true, get_config_variable(:@disable_completion)
end

def test_string_value
Expand All @@ -55,7 +59,7 @@ def test_string_value
set emacs-mode-string Emacs
LINES

assert_equal 'Emacs', @config.instance_variable_get(:@emacs_mode_string)
assert_equal 'Emacs', get_config_variable(:@emacs_mode_string)
end

def test_string_value_with_brackets
Expand All @@ -64,7 +68,7 @@ def test_string_value_with_brackets
set emacs-mode-string [Emacs]
LINES

assert_equal '[Emacs]', @config.instance_variable_get(:@emacs_mode_string)
assert_equal '[Emacs]', get_config_variable(:@emacs_mode_string)
end

def test_string_value_with_brackets_and_quotes
Expand All @@ -73,7 +77,7 @@ def test_string_value_with_brackets_and_quotes
set emacs-mode-string "[Emacs]"
LINES

assert_equal '[Emacs]', @config.instance_variable_get(:@emacs_mode_string)
assert_equal '[Emacs]', get_config_variable(:@emacs_mode_string)
end

def test_string_value_with_parens
Expand All @@ -82,7 +86,7 @@ def test_string_value_with_parens
set emacs-mode-string (Emacs)
LINES

assert_equal '(Emacs)', @config.instance_variable_get(:@emacs_mode_string)
assert_equal '(Emacs)', get_config_variable(:@emacs_mode_string)
end

def test_string_value_with_parens_and_quotes
Expand All @@ -91,7 +95,7 @@ def test_string_value_with_parens_and_quotes
set emacs-mode-string "(Emacs)"
LINES

assert_equal '(Emacs)', @config.instance_variable_get(:@emacs_mode_string)
assert_equal '(Emacs)', get_config_variable(:@emacs_mode_string)
end

def test_encoding_is_ascii
Expand Down Expand Up @@ -169,7 +173,7 @@ def test_include
$include included_partial
LINES

assert_equal true, @config.instance_variable_get(:@show_mode_in_prompt)
assert_equal true, get_config_variable(:@show_mode_in_prompt)
end

def test_include_expand_path
Expand All @@ -184,7 +188,7 @@ def test_include_expand_path
$include ~/included_partial
LINES

assert_equal true, @config.instance_variable_get(:@show_mode_in_prompt)
assert_equal true, get_config_variable(:@show_mode_in_prompt)
ensure
ENV['HOME'] = home_backup
end
Expand All @@ -198,7 +202,7 @@ def test_if
$endif
LINES

assert_equal '(cmd)', @config.instance_variable_get(:@vi_cmd_mode_string)
assert_equal '(cmd)', get_config_variable(:@vi_cmd_mode_string)
end

def test_if_with_false
Expand All @@ -210,7 +214,7 @@ def test_if_with_false
$endif
LINES

assert_equal '[cmd]', @config.instance_variable_get(:@vi_cmd_mode_string)
assert_equal '[cmd]', get_config_variable(:@vi_cmd_mode_string)
end

def test_if_with_indent
Expand All @@ -224,7 +228,7 @@ def test_if_with_indent
$endif
LINES

assert_equal '(cmd)', @config.instance_variable_get(:@vi_cmd_mode_string)
assert_equal '(cmd)', get_config_variable(:@vi_cmd_mode_string)
end
end

Expand Down Expand Up @@ -446,7 +450,7 @@ def test_history_size
set history-size 5000
LINES

assert_equal 5000, @config.instance_variable_get(:@history_size)
assert_equal 5000, get_config_variable(:@history_size)
history = Reline::History.new(@config)
history << "a\n"
assert_equal 1, history.size
Expand Down Expand Up @@ -477,7 +481,7 @@ def test_inputrc_raw_value
set vi-ins-mode-string aaa aaa
set vi-cmd-mode-string bbb ccc # comment
LINES
assert_equal :vi_insert, @config.instance_variable_get(:@editing_mode_label)
assert_equal :vi_insert, get_config_variable(:@editing_mode_label)
assert_equal 'aaa aaa', @config.vi_ins_mode_string
assert_equal 'bbb ccc # comment', @config.vi_cmd_mode_string
end
Expand Down

0 comments on commit 7234444

Please sign in to comment.