Skip to content

Commit

Permalink
Format: fix formatter bug on nesting begin/end
Browse files Browse the repository at this point in the history
  • Loading branch information
makenowjust authored and jhass committed Apr 5, 2018
1 parent 8c737a0 commit ef85244
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ describe Crystal::Formatter do
assert_format "begin; 1; end", "begin\n 1\nend"
assert_format "begin\n1\n2\n3\nend", "begin\n 1\n 2\n 3\nend"
assert_format "begin\n1 ? 2 : 3\nend", "begin\n 1 ? 2 : 3\nend"
assert_format "begin\n begin\n\n end\nend"
assert_format "begin\n ()\nend"

assert_format "def foo \n end", "def foo\nend"
assert_format "def foo\n1\nend", "def foo\n 1\nend"
Expand Down
1 change: 1 addition & 0 deletions spec/compiler/parser/to_s_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,5 @@ describe "ASTNode#to_s" do
expect_to_s %(foo(1, (2 + 3), bar: (4 + 5)))
expect_to_s %(if (1 + 2\n3)\n 4\nend)
expect_to_s "%x(whoami)", "`whoami`"
expect_to_s %(begin\n ()\nend)
end
2 changes: 1 addition & 1 deletion src/compiler/crystal/syntax/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ module Crystal
exps = parse_expressions
node, end_location = parse_exception_handler exps
node.end_location = end_location
if !node.is_a?(ExceptionHandler) && !node.is_a?(Expressions)
if !node.is_a?(ExceptionHandler) && (!node.is_a?(Expressions) || node.keyword)
node = Expressions.new([node]).at(node).at_end(node)
end
node.keyword = :begin if node.is_a?(Expressions)
Expand Down

0 comments on commit ef85244

Please sign in to comment.