Skip to content

Commit

Permalink
Fix formatting of lib's fun starting with uppercase letter
Browse files Browse the repository at this point in the history
  • Loading branch information
bew authored and matiasgarciaisaia committed Jan 25, 2018
1 parent 0ebc173 commit b793876
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,9 @@ describe Crystal::Formatter do
assert_format "lib Foo\nend"
assert_format "lib Foo\ntype Foo = Bar\nend", "lib Foo\n type Foo = Bar\nend"
assert_format "lib Foo\nfun foo\nend", "lib Foo\n fun foo\nend"
assert_format "lib Foo\n fun Bar\nend"
assert_format "lib Foo\n fun bar = Bar\nend"
assert_format "lib Foo\n fun Foo = Bar\nend"
assert_format "lib Foo\nfun foo : Int32\nend", "lib Foo\n fun foo : Int32\nend"
assert_format "lib Foo\nfun foo() : Int32\nend", "lib Foo\n fun foo : Int32\nend"
assert_format "lib Foo\nfun foo () : Int32\nend", "lib Foo\n fun foo : Int32\nend"
Expand Down
8 changes: 5 additions & 3 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,7 @@ module Crystal
def visit(node : FunDef)
write_keyword :fun, " "

check :IDENT
check :IDENT, :CONST
write node.name
next_token_skip_space

Expand Down Expand Up @@ -4573,8 +4573,10 @@ module Crystal
raise "expecting keyword #{keywords.join " or "}, not `#{@token.type}, #{@token.value}`, at #{@token.location}" unless keywords.any? { |k| @token.keyword?(k) }
end

def check(token_type)
raise "expecting #{token_type}, not `#{@token.type}, #{@token.value}`, at #{@token.location}" unless @token.type == token_type
def check(*token_types)
unless token_types.includes? @token.type
raise "expecting #{token_types.join " or "}, not `#{@token.type}, #{@token.value}`, at #{@token.location}"
end
end

def check_end
Expand Down

0 comments on commit b793876

Please sign in to comment.