Skip to content

Commit

Permalink
Fix HEREDOC error message grammar (crystal-lang#5887)
Browse files Browse the repository at this point in the history
* Fix HEREDOC error message grammar

* Update parser_spec.cr
  • Loading branch information
wooster0 authored and RX14 committed Mar 29, 2018
1 parent 4927ecc commit 0424b22
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions spec/compiler/parser/parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1202,12 +1202,12 @@ describe "Parser" do
it_parses "<<-HERE1; <<-HERE2\nHERE1\nHERE2", ["".string_interpolation, "".string_interpolation] of ASTNode
it_parses "<<-HERE1; <<-HERE2\nhere1\nHERE1\nHERE2", ["here1".string_interpolation, "".string_interpolation] of ASTNode
it_parses "<<-HERE1; <<-HERE2\nHERE1\nhere2\nHERE2", ["".string_interpolation, "here2".string_interpolation] of ASTNode
assert_syntax_error "<<-HERE\n One\nwrong\n Zero\n HERE", "heredoc line must have an indent greater or equal than 2", 3, 1
assert_syntax_error "<<-HERE\n One\n wrong\n Zero\n HERE", "heredoc line must have an indent greater or equal than 2", 3, 1
assert_syntax_error "<<-HERE\n One\n \#{1}\n Zero\n HERE", "heredoc line must have an indent greater or equal than 2", 3, 1
assert_syntax_error "<<-HERE\n One\n \#{1}\n wrong\n HERE", "heredoc line must have an indent greater or equal than 2", 4, 1
assert_syntax_error "<<-HERE\n One\n \#{1}\n wrong\#{1}\n HERE", "heredoc line must have an indent greater or equal than 2", 4, 1
assert_syntax_error "<<-HERE\n One\n \#{1}\n HERE", "heredoc line must have an indent greater or equal than 2", 2, 1
assert_syntax_error "<<-HERE\n One\nwrong\n Zero\n HERE", "heredoc line must have an indent greater than or equal to 2", 3, 1
assert_syntax_error "<<-HERE\n One\n wrong\n Zero\n HERE", "heredoc line must have an indent greater than or equal to 2", 3, 1
assert_syntax_error "<<-HERE\n One\n \#{1}\n Zero\n HERE", "heredoc line must have an indent greater than or equal to 2", 3, 1
assert_syntax_error "<<-HERE\n One\n \#{1}\n wrong\n HERE", "heredoc line must have an indent greater than or equal to 2", 4, 1
assert_syntax_error "<<-HERE\n One\n \#{1}\n wrong\#{1}\n HERE", "heredoc line must have an indent greater than or equal to 2", 4, 1
assert_syntax_error "<<-HERE\n One\n \#{1}\n HERE", "heredoc line must have an indent greater than or equal to 2", 2, 1
assert_syntax_error %("\#{<<-HERE}"\nHERE), "heredoc cannot be used inside interpolation"
assert_syntax_error %("foo" "bar")

Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/syntax/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2022,7 +2022,7 @@ module Crystal
if remove_indent
line = current_line.to_s
if (line.size < indent) || !line.each_char.first(indent).all?(&.ascii_whitespace?)
raise "heredoc line must have an indent greater or equal than #{indent}", line_number, 1
raise "heredoc line must have an indent greater than or equal to #{indent}", line_number, 1
else
line = line[indent..-1]
end
Expand Down Expand Up @@ -2071,7 +2071,7 @@ module Crystal
line[indent..-1]
end
else
raise "heredoc line must have an indent greater or equal than #{indent}", line_number, 1
raise "heredoc line must have an indent greater than or equal to #{indent}", line_number, 1
end
end

Expand Down

0 comments on commit 0424b22

Please sign in to comment.