Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for reset_variables in Reline::Config #741

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/reline/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ def reset_variables
@keyseq_timeout = 500
@test_mode = false
@autocompletion = false
@convert_meta = true if seven_bit_encoding?(Reline::IOGate.encoding)
@convert_meta = seven_bit_encoding?(Reline::IOGate.encoding)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it would be better to use true/false instead of nil and true, so I made the change.

@loaded = false
@enable_bracketed_paste = true
@show_mode_in_prompt = false
@default_inputrc_path = nil
end

def editing_mode
Expand Down
40 changes: 24 additions & 16 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 All @@ -105,7 +109,7 @@ def test_encoding_is_ascii
def test_encoding_is_not_ascii
@config = Reline::Config.new

assert_equal nil, @config.convert_meta
assert_equal false, @config.convert_meta
end

def test_invalid_keystroke
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 Expand Up @@ -576,5 +580,9 @@ def test_reload
File.write(inputrc, "set emacs-mode-string ?")
@config.reload
assert_equal '?', @config.emacs_mode_string

File.write(inputrc, "")
@config.reload
assert_equal '@', @config.emacs_mode_string
end
end
Loading