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 tests for error cases on #1791, #1807, and #1810 #1811

Merged
merged 1 commit into from
Nov 13, 2023
Merged
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
33 changes: 33 additions & 0 deletions test/prism/errors_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,39 @@ def test_symbol_in_hash
]
end

def test_while_endless_method
source = "while def f = g do end"
assert_errors expression(source), source, [
['Expected a predicate expression for the `while` statement', 22..22],
['Cannot parse the expression', 22..22],
['Expected an `end` to close the `while` statement', 22..22]
]
end

def test_match_plus
source = <<~RUBY
a in b + c
a => b + c
RUBY
message1 = 'Expected a newline or semicolon after the statement'
message2 = 'Cannot parse the expression'
assert_errors expression(source), source, [
[message1, 6..6],
[message2, 6..6],
[message1, 17..17],
[message2, 17..17],
]
end

def test_rational_number_with_exponential_portion
source = '1e1r; 1e1ri'
message = 'Expected a newline or semicolon after the statement'
assert_errors expression(source), source, [
[message, 3..3],
[message, 9..9]
]
end

private

def assert_errors(expected, source, errors, compare_ripper: RUBY_ENGINE == "ruby")
Expand Down