Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2d799c7e3b35
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 493236002676
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Dec 22, 2017

  1. Copy the full SHA
    910b555 View commit details
  2. Add formatter spec for uppercased fun call

    bew authored and RX14 committed Dec 22, 2017
    Copy the full SHA
    4932360 View commit details
Showing with 11 additions and 3 deletions.
  1. +6 −0 spec/compiler/formatter/formatter_spec.cr
  2. +5 −3 src/compiler/crystal/tools/formatter.cr
6 changes: 6 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
@@ -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"
@@ -603,6 +606,9 @@ describe Crystal::Formatter do
assert_format "lib Foo\nstruct Foo\nx , y , z : Int32\nend\nend", "lib Foo\n struct Foo\n x, y, z : Int32\n end\nend"
assert_format "lib Foo\nunion Foo\nend\nend", "lib Foo\n union Foo\n end\nend"

assert_format "SomeLib.UppercasedFunCall"
assert_format "SomeLib.UppercasedFunCall 1, 2"

assert_format "enum Foo\nend"
assert_format "enum Foo\nA \nend", "enum Foo\n A\nend"
assert_format "enum Foo\nA = 1\nend", "enum Foo\n A = 1\nend"
8 changes: 5 additions & 3 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
@@ -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

@@ -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