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

[ruby/irb] fix reserved words and completion for them

6184b227ad
This commit is contained in:
Nobuhiro IMAI 2020-02-12 19:16:12 +09:00 committed by aycabta
parent 38f1e84c37
commit 961630126b
2 changed files with 15 additions and 2 deletions

View file

@ -17,11 +17,12 @@ module IRB
# Set of reserved words used by Ruby, you should not use these for # Set of reserved words used by Ruby, you should not use these for
# constants or variables # constants or variables
ReservedWords = %w[ ReservedWords = %w[
__ENCODING__ __LINE__ __FILE__
BEGIN END BEGIN END
alias and alias and
begin break begin break
case class case class
def defined do def defined? do
else elsif end ensure else elsif end ensure
false for false for
if in if in
@ -255,7 +256,7 @@ module IRB
else else
candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s} candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s}
conditions |= ReservedWords candidates |= ReservedWords
if doc_namespace if doc_namespace
candidates.find{ |i| i == input } candidates.find{ |i| i == input }

View file

@ -35,5 +35,17 @@ module TestIRB
def test_complete_symbol_failure def test_complete_symbol_failure
assert_nil(IRB::InputCompletor::PerfectMatchedProc.(":aiueo", bind: binding)) assert_nil(IRB::InputCompletor::PerfectMatchedProc.(":aiueo", bind: binding))
end end
def test_complete_reserved_words
candidates = IRB::InputCompletor.retrieve_completion_data("de", bind: binding)
%w[def defined?].each do |word|
assert_include candidates, word
end
candidates = IRB::InputCompletor.retrieve_completion_data("__", bind: binding)
%w[__ENCODING__ __LINE__ __FILE__].each do |word|
assert_include candidates, word
end
end
end end
end end