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

Lines ending with $\ are not incomplete. #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions lib/method_source/code_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def complete_expression?(str)
eval("BEGIN{throw :valid}\n#{str}")
end

# Assert that a line which ends with a , or \ is incomplete.
str !~ /[,\\]\s*\z/
# Assert that a line which ends with a , or \ but not with $\ is incomplete.
str !~ /(,|[^\$]\\)\s*\z/
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would use (?:...) in order not to create a captured group.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I suspect this change might break $$. Could you please check?

Copy link
Author

Choose a reason for hiding this comment

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

MethodSource.complete_expression?('$$') was true before this patch and is also true after this patch.

rescue IncompleteExpression
false
ensure
Expand Down
4 changes: 4 additions & 0 deletions test/test_code_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@
}.should.raise(SyntaxError)
end
end

it "should consider as complete lines ending with $\\" do
@tester.complete_expression?('$\\').should == true
end
end