mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Rework valid_expression? as complete_expression?
This commit is contained in:
parent
05fbdaac3b
commit
a04c5f488a
3 changed files with 7 additions and 7 deletions
|
@ -113,7 +113,7 @@ class Pry
|
|||
eval_string << Array(code.each_line.to_a[range]).join
|
||||
end
|
||||
|
||||
run "show-input" if !_pry_.valid_expression?(eval_string)
|
||||
run "show-input" if !_pry_.complete_expression?(eval_string)
|
||||
end
|
||||
|
||||
command "hist", "Show and replay Readline history. Type `hist --help` for more info. Aliases: history" do |*args|
|
||||
|
|
|
@ -259,7 +259,7 @@ class Pry
|
|||
output.puts "Error: #{e.message}"
|
||||
end
|
||||
|
||||
break if valid_expression?(eval_string)
|
||||
break if complete_expression?(eval_string)
|
||||
end
|
||||
|
||||
@suppress_output = true if eval_string =~ /;\Z/ || eval_string.empty?
|
||||
|
@ -544,9 +544,9 @@ class Pry
|
|||
# @return [Boolean] Whether or not the code is a complete Ruby expression.
|
||||
# @raise [SyntaxError] Any SyntaxError that does not represent incompleteness.
|
||||
# @example
|
||||
# valid_expression?("class Hello") #=> false
|
||||
# valid_expression?("class Hello; end") #=> true
|
||||
def valid_expression?(str)
|
||||
# complete_expression?("class Hello") #=> false
|
||||
# complete_expression?("class Hello; end") #=> true
|
||||
def complete_expression?(str)
|
||||
if defined?(Rubinius::Melbourne19) && RUBY_VERSION =~ /^1\.9/
|
||||
Rubinius::Melbourne19.parse_string(str, Pry.eval_path)
|
||||
elsif defined?(Rubinius::Melbourne)
|
||||
|
|
|
@ -216,11 +216,11 @@ describe Pry do
|
|||
end
|
||||
end
|
||||
|
||||
describe "valid_expression?" do
|
||||
describe "complete_expression?" do
|
||||
it "should not mutate the input!" do
|
||||
clean = "puts <<-FOO\nhi\nFOO\n"
|
||||
a = clean.dup
|
||||
Pry.new.valid_expression?(a)
|
||||
Pry.new.complete_expression?(a)
|
||||
a.should == clean
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue