Skip to content
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion samples/sdl/raytracer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ scene = Scene.new(
],
[
Light.new(Vec3.new(-10.0, 20.0, 30.0), Vec3.new(2.0, 2.0, 2.0)),
]
],
)

SDL.init
Expand Down
2 changes: 1 addition & 1 deletion samples/text_raytracer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ scene = [

ray = Ray.new(
Vector.new(0.0, 0.0, 0.0),
Vector.new((fi - fw/2.0)/fw, (fj - fh/2.0)/fh, 1.0).normalize
Vector.new((fi - fw/2.0)/fw, (fj - fh/2.0)/fh, 1.0).normalize,
)

hit = nil
Expand Down
2 changes: 1 addition & 1 deletion scripts/github-changelog.cr
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def query_prs(api_token, repository, milestone : String, cursor : String?)
body: {query: query, variables: variables}.to_json,
headers: HTTP::Headers{
"Authorization" => "bearer #{api_token}",
}
},
)
unless response.success?
abort "GitHub API response: #{response.status}\n#{response.body}"
Expand Down
2 changes: 1 addition & 1 deletion spec/compiler/crystal/tools/init_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ end

private def run_init_project(skeleton_type, name, author, email, github_name, dir = name)
Crystal::Init::InitProject.new(
Crystal::Init::Config.new(skeleton_type, name, dir, author, email, github_name, true)
Crystal::Init::Config.new(skeleton_type, name, dir, author, email, github_name, true),
).run
end

Expand Down
2 changes: 1 addition & 1 deletion spec/compiler/ffi/ffi_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ describe Crystal::FFI::CallInterface do
j: 8,
f: 9.0,
d: 10.0,
p: pointerof(pointer_value).as(Void*)
p: pointerof(pointer_value).as(Void*),
)).as(Void*),
Pointer(Void).null,
]
Expand Down
59 changes: 36 additions & 23 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe Crystal::Formatter do
assert_format "[\n1,\n\n2]", "[\n 1,\n\n 2,\n]"
assert_format "[ # foo\n 1,\n]"
assert_format "Set{ # foo\n 1,\n}"
assert_format "begin\n array[\n 0 # Zero\n ]\nend"
assert_format "begin\n array[\n 0 # Zero\n ]\nend", "begin\n array[\n 0, # Zero\n ]\nend"
assert_format "begin\n array[\n 0, # Zero\n ]\nend"
assert_format "[\n # foo\n] of String"
assert_format "[\n# foo\n] of String", "[\n # foo\n] of String"
Expand Down Expand Up @@ -459,7 +459,7 @@ describe Crystal::Formatter do
CRYSTAL
module M
@[MyAnn(
1
1,
)]
end
CRYSTAL
Expand Down Expand Up @@ -508,8 +508,8 @@ describe Crystal::Formatter do
assert_format "::foo(1, 2)"
assert_format "args.any? &.name.baz"
assert_format "foo(\n 1, 2)", "foo(\n 1, 2)"
assert_format "foo(\n1,\n 2 \n)", "foo(\n 1,\n 2\n)"
assert_format "foo(\n1,\n\n 2 \n)", "foo(\n 1,\n\n 2\n)"
assert_format "foo(\n1,\n 2 \n)", "foo(\n 1,\n 2,\n)"
assert_format "foo(\n1,\n\n 2 \n)", "foo(\n 1,\n\n 2,\n)"
assert_format "foo(\n 1,\n # 2,\n 3,\n)"
assert_format "foo(\n 1,\n # 2,\n # 3,\n)"
assert_format "foo 1,\n2", "foo 1,\n 2"
Expand All @@ -518,7 +518,7 @@ describe Crystal::Formatter do
assert_format "foo bar:baz, qux:other", "foo bar: baz, qux: other"
assert_format "foo(\n 1, 2, &block)", "foo(\n 1, 2, &block)"
assert_format "foo(\n 1, 2,\n&block)", "foo(\n 1, 2,\n &block)"
assert_format "foo(\n 1,\n 2\n) do\n 1\nend"
assert_format "foo(\n 1,\n 2\n) do\n 1\nend", "foo(\n 1,\n 2,\n) do\n 1\nend"
assert_format "foo 1, a: 1,\nb: 2,\nc: 3,\n&block", "foo 1, a: 1,\n b: 2,\n c: 3,\n &block"
assert_format "foo 1, do\n2\nend", "foo 1 do\n 2\nend"
assert_format "a.b &.[c]?\n1"
Expand All @@ -536,7 +536,7 @@ describe Crystal::Formatter do
assert_format "foo.% bar"
assert_format "foo.bar(&.%(baz))"
assert_format "foo.bar(&.% baz)"
assert_format "if 1\n foo(\n bar\n # comment\n )\nend"
assert_format "if 1\n foo(\n bar\n # comment\n )\nend", "if 1\n foo(\n bar,\n # comment\n )\nend"
assert_format "if 1\n foo(\n bar,\n # comment\n )\nend"

assert_format "foo.bar\n.baz", "foo.bar\n .baz"
Expand Down Expand Up @@ -1848,7 +1848,7 @@ describe Crystal::Formatter do
assert_format "[\n a(), # b\n]", "[\n a(), # b\n]"
assert_format "[\n a(),\n]", "[\n a(),\n]"
assert_format "if 1\n[\n a() # b\n]\nend", "if 1\n [\n a(), # b\n ]\nend"
assert_format "foo(\n# x\n1,\n\n# y\nz: 2\n)", "foo(\n # x\n 1,\n\n # y\n z: 2\n)"
assert_format "foo(\n# x\n1,\n\n# y\nz: 2\n)", "foo(\n # x\n 1,\n\n # y\n z: 2,\n)"
assert_format "foo(\n# x\n1,\n\n# y\nz: 2,\n\n# a\nb: 3)", "foo(\n # x\n 1,\n\n # y\n z: 2,\n\n # a\n b: 3)"
assert_format "foo(\n 1, # hola\n2, # chau\n )", "foo(\n 1, # hola\n 2, # chau\n)"
assert_format "foo (1)", "foo(1)"
Expand Down Expand Up @@ -1886,7 +1886,7 @@ describe Crystal::Formatter do
assert_format "case 1\nwhen 2\n 3\n # foo\nelse\n 4\n # bar\nend"
assert_format "1 #=> 2", "1 # => 2"
assert_format "1 #=>2", "1 # => 2"
assert_format "foo(\n [\n 1,\n 2,\n ],\n [\n 3,\n 4,\n ]\n)"
assert_format "foo(\n [\n 1,\n 2,\n ],\n [\n 3,\n 4,\n ]\n)", "foo(\n [\n 1,\n 2,\n ],\n [\n 3,\n 4,\n ],\n)"
assert_format "begin\n %w(\n one two\n three four\n )\nend"
assert_format "%w(\n one two\n three four\n)"
assert_format "a = %w(\n one two\n three four\n)"
Expand All @@ -1904,8 +1904,8 @@ describe Crystal::Formatter do
assert_format "foo(1, 2, {\n foo: 1,\n bar: 2,\n})"
assert_format "a = foo(1, 2, {\n foo: 1,\n bar: 2,\n})"
assert_format "foo([\n 1,\n bar do\n end,\n [\n 2,\n ],\n])"
assert_format "foo(bar(\n 1,\n baz(\n 2,\n 3,\n )\n))"
assert_format "foo(bar(\n 1,\n baz(2,\n 3,\n )\n))", "foo(bar(\n 1,\n baz(2,\n 3,\n )\n))"
assert_format "foo(bar(\n 1,\n baz(\n 2,\n 3,\n )\n))", "foo(bar(\n 1,\n baz(\n 2,\n 3,\n ),\n))"
assert_format "foo(bar(\n 1,\n baz(2,\n 3,\n )\n))", "foo(bar(\n 1,\n baz(2,\n 3,\n ),\n))"
assert_format "foo({\n 1 => 2,\n 3 => {\n 4 => 5,\n },\n})"
assert_format "foo([\n 1, 2,\n 3, 4,\n])"
assert_format "foo(baz(x, y) do\n 1 + 2\nend)"
Expand Down Expand Up @@ -1962,7 +1962,7 @@ describe Crystal::Formatter do
assert_format "begin\nend\n\n# a\n", "begin\n\nend\n\n# a"
assert_format "begin\n 1\nend\n\n1\n", "begin\n 1\nend\n\n1"
assert_format "{\n \"a\" => 1, \"b\" => 2,\n \"foo\" => 3, \"bar\" => 4,\n \"coconio\" => 5, \"lala\" => 6,\n}\n", "{\n \"a\" => 1, \"b\" => 2,\n \"foo\" => 3, \"bar\" => 4,\n \"coconio\" => 5, \"lala\" => 6,\n}"
assert_format "if 1\n foo(\n 1,\n 2 # lala\n )\nend\n", "if 1\n foo(\n 1,\n 2 # lala\n )\nend"
assert_format "if 1\n foo(\n 1,\n 2 # lala\n )\nend\n", "if 1\n foo(\n 1,\n 2, # lala\n )\nend"
assert_format "case foo\nwhen 1\n # A\nelse\n# B\nend\n", "case foo\nwhen 1\n # A\nelse\n # B\nend"
assert_format "return 1\n# end"
assert_format "case\n# hello\nwhen 1\n 2\nend"
Expand Down Expand Up @@ -2282,8 +2282,8 @@ describe Crystal::Formatter do
assert_format "def a\n {\n 1, # x\n # y\n }\nend"
assert_format "def a\n [\n 1, # x\n # y\n ]\nend"
assert_format "def a\n b(\n 1, # x\n # y\n )\nend"
assert_format "def a\n b(\n 1, # x\n # y\n 2\n )\nend"
assert_format "def a\n b(\n a: 1, # x\n # y\n b: 2\n )\nend"
assert_format "def a\n b(\n 1, # x\n # y\n 2\n )\nend", "def a\n b(\n 1, # x\n # y\n 2,\n )\nend"
assert_format "def a\n b(\n a: 1, # x\n # y\n b: 2\n )\nend", "def a\n b(\n a: 1, # x\n # y\n b: 2,\n )\nend"
assert_format "def a\n b(\n 1, # x\n # y\n a: 1, # x\n # y\n b: 2 # z\n )\nend"

assert_format "def foo(a, **b : Int32)\nend"
Expand Down Expand Up @@ -2390,36 +2390,36 @@ describe Crystal::Formatter do
" <<-FOO\n" +
" hello \n" +
" FOO\n" +
"end"
"end",
)
assert_format(
"{% verbatim do %}\n" +
" <<-FOO\n" +
" hello \n" +
" FOO\n" +
"{% end %}"
"{% end %}",
)
assert_format(
"{% if true %}\n" +
" <<-FOO\n" +
" hello \n" +
" FOO\n" +
"{% end %}"
"{% end %}",
)
assert_format(
"{% for a in %w() %}\n" +
" <<-FOO\n" +
" hello \n" +
" FOO\n" +
"{% end %}"
"{% end %}",
)
assert_format(
"macro foo\n" +
" {{x}}" +
" <<-FOO\n" +
" hello \n" +
" FOO\n" +
"end"
"end",
)

# But remove trailing space in macro expression.
Expand All @@ -2437,7 +2437,7 @@ describe Crystal::Formatter do
" 42\n" +
" }} \n" +
" 2 \n" +
"end"
"end",
)

# #7443
Expand Down Expand Up @@ -2468,13 +2468,26 @@ describe Crystal::Formatter do
# #7614
assert_format "@[ Foo ]\ndef foo\nend", "@[Foo]\ndef foo\nend"
assert_format "@[ Foo(foo: 1) ]\ndef foo\nend", "@[Foo(foo: 1)]\ndef foo\nend"
assert_format "@[Foo(\n foo: 1\n)]\ndef foo\nend"
assert_format "@[Foo(\n foo: 1\n)]\ndef foo\nend", "@[Foo(\n foo: 1,\n)]\ndef foo\nend"
assert_format "@[Foo(\n foo: 1,\n)]\ndef foo\nend"

# #7550
assert_format "foo\n .bar(\n 1\n )"
assert_format "foo\n .bar\n .baz(\n 1\n )"
assert_format "foo.bar\n .baz(\n 1\n )"
assert_format "foo\n .bar(\n 1\n )", "foo\n .bar(\n 1,\n )"
assert_format "foo\n .bar\n .baz(\n 1\n )", "foo\n .bar\n .baz(\n 1,\n )"
assert_format "foo.bar\n .baz(\n 1\n )", "foo.bar\n .baz(\n 1,\n )"

# #17018
assert_format "foo(\n 1,\n bar: 2\n)", "foo(\n 1,\n bar: 2,\n)"
assert_format "foo(\n bar: 1\n)", "foo(\n bar: 1,\n)"
assert_format "foo(\n bar: 1 # fox\n)", "foo(\n bar: 1, # fox\n)"
assert_format "foo(\n 1 # fox\n)", "foo(\n 1, # fox\n)"
assert_format "foo(\n 1\n)", "foo(\n 1,\n)"
assert_format "foo(\n 1,\n &block\n)"
assert_format "foo \\\n 1,\n bar: 2"
assert_format "foo \\\n 1"
assert_format "foo(\n 1,\n bar: <<-HEREDOC\n foo\n HEREDOC\n)"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Shouldn't we add a comma here?

Suggested change
assert_format "foo(\n 1,\n bar: <<-HEREDOC\n foo\n HEREDOC\n)"
assert_format "foo(\n 1,\n bar: <<-HEREDOC\n foo\n HEREDOC\n)", "foo(\n 1,\n bar: <<-HEREDOC,\n foo\n HEREDOC\n)"

Btw. we might want to use heredocs for the strings to makes the examples easier to read.

assert_format "foo(\n bar: <<-HEREDOC\n foo\n HEREDOC\n)"
assert_format "foo(\n <<-HEREDOC\n foo\n HEREDOC\n)"

assert_format <<-CRYSTAL,
def foo
Expand Down
38 changes: 19 additions & 19 deletions spec/compiler/macro/macro_methods_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ module Crystal
it "#each" do
assert_macro(
%({% begin %}{% values = [] of Nil %}{% [1, 2, 3].each { |v| values << v } %}{{values}}{% end %}),
%([1, 2, 3])
%([1, 2, 3]),
)
end

Expand All @@ -860,7 +860,7 @@ module Crystal
it "builds the correct array" do
assert_macro(
%({% begin %}{% values = [] of Nil %}{% [1, 2, 3].each_with_index { |v, idx| values << (v + idx) } %}{{values}}{% end %}),
%([1, 3, 5])
%([1, 3, 5]),
)
end
end
Expand All @@ -869,7 +869,7 @@ module Crystal
it "builds the correct array" do
assert_macro(
%({% begin %}{% values = [] of Nil %}{% [1, 2, 3].each_with_index { |v| values << v } %}{{values}}{% end %}),
%([1, 2, 3])
%([1, 2, 3]),
)
end
end
Expand All @@ -878,7 +878,7 @@ module Crystal
it "builds the correct array" do
assert_macro(
%({% begin %}{% values = [] of Nil %}{% [1, 2, 3].each_with_index { |_, idx| values << idx } %}{{values}}{% end %}),
%([0, 1, 2])
%([0, 1, 2]),
)
end
end
Expand All @@ -887,7 +887,7 @@ module Crystal
it "builds the correct array" do
assert_macro(
%({% begin %}{% values = [] of Nil %}{% [1, 2, 3].each_with_index { values << 7 } %}{{values}}{% end %}),
%([7, 7, 7])
%([7, 7, 7]),
)
end
end
Expand Down Expand Up @@ -1174,7 +1174,7 @@ module Crystal
it "builds the correct array" do
assert_macro(
%({% begin %}{% values = [] of Nil %}{% {"k1" => "v1", "k2" => "v2"}.each { |k, v| values << {k, v} } %}{{values}}{% end %}),
%([{"k1", "v1"}, {"k2", "v2"}])
%([{"k1", "v1"}, {"k2", "v2"}]),
)
end
end
Expand All @@ -1183,7 +1183,7 @@ module Crystal
it "builds the correct array" do
assert_macro(
%({% begin %}{% values = [] of Nil %}{% {"k1" => "v1", "k2" => "v2"}.each { |k| values << k } %}{{values}}{% end %}),
%(["k1", "k2"])
%(["k1", "k2"]),
)
end
end
Expand All @@ -1192,7 +1192,7 @@ module Crystal
it "builds the correct array" do
assert_macro(
%({% begin %}{% values = [] of Nil %}{% {"k1" => "v1", "k2" => "v2"}.each { |_, v| values << v } %}{{values}}{% end %}),
%(["v1", "v2"])
%(["v1", "v2"]),
)
end
end
Expand All @@ -1201,7 +1201,7 @@ module Crystal
it "builds the correct array" do
assert_macro(
%({% begin %}{% values = [] of Nil %}{% {"k1" => "v1", "k2" => "v2"}.each { values << {"k3", "v3"} } %}{{values}}{% end %}),
%([{"k3", "v3"}, {"k3", "v3"}])
%([{"k3", "v3"}, {"k3", "v3"}]),
)
end
end
Expand Down Expand Up @@ -1303,7 +1303,7 @@ module Crystal
it "builds the correct array" do
assert_macro(
%({% begin %}{% values = [] of Nil %}{% {k1: "v1", k2: "v2"}.each { |k, v| values << {k, v} } %}{{values}}{% end %}),
%([{k1, "v1"}, {k2, "v2"}])
%([{k1, "v1"}, {k2, "v2"}]),
)
end
end
Expand All @@ -1312,7 +1312,7 @@ module Crystal
it "builds the correct array" do
assert_macro(
%({% begin %}{% values = [] of Nil %}{% {k1: "v1", k2: "v2"}.each { |k| values << k } %}{{values}}{% end %}),
%([k1, k2])
%([k1, k2]),
)
end
end
Expand All @@ -1321,7 +1321,7 @@ module Crystal
it "builds the correct array" do
assert_macro(
%({% begin %}{% values = [] of Nil %}{% {k1: "v1", k2: "v2"}.each { |_, v| values << v } %}{{values}}{% end %}),
%(["v1", "v2"])
%(["v1", "v2"]),
)
end
end
Expand All @@ -1330,7 +1330,7 @@ module Crystal
it "builds the correct array" do
assert_macro(
%({% begin %}{% values = [] of Nil %}{% {k1: "v1", k2: "v2"}.each { values << {"k3", "v3"} } %}{{values}}{% end %}),
%([{"k3", "v3"}, {"k3", "v3"}])
%([{"k3", "v3"}, {"k3", "v3"}]),
)
end
end
Expand Down Expand Up @@ -1454,7 +1454,7 @@ module Crystal
it "#each" do
assert_macro(
%({% begin %}{% values = [] of Nil %}{% {1, 2, 3}.each { |v| values << v } %}{{values}}{% end %}),
%([1, 2, 3])
%([1, 2, 3]),
)
end

Expand All @@ -1463,7 +1463,7 @@ module Crystal
it "builds the correct array" do
assert_macro(
%({% begin %}{% values = [] of Nil %}{% {1, 2, 3}.each_with_index { |v, idx| values << (v + idx) } %}{{values}}{% end %}),
%([1, 3, 5])
%([1, 3, 5]),
)
end
end
Expand All @@ -1472,7 +1472,7 @@ module Crystal
it "builds the correct array" do
assert_macro(
%({% begin %}{% values = [] of Nil %}{% {1, 2, 3}.each_with_index { |v| values << v } %}{{values}}{% end %}),
%([1, 2, 3])
%([1, 2, 3]),
)
end
end
Expand All @@ -1481,7 +1481,7 @@ module Crystal
it "builds the correct array" do
assert_macro(
%({% begin %}{% values = [] of Nil %}{% {1, 2, 3}.each_with_index { |_, idx| values << idx } %}{{values}}{% end %}),
%([0, 1, 2])
%([0, 1, 2]),
)
end
end
Expand All @@ -1490,7 +1490,7 @@ module Crystal
it "builds the correct array" do
assert_macro(
%({% begin %}{% values = [] of Nil %}{% {1, 2, 3}.each_with_index { values << 7 } %}{{values}}{% end %}),
%([7, 7, 7])
%([7, 7, 7]),
)
end
end
Expand Down Expand Up @@ -3480,7 +3480,7 @@ module Crystal
it "#each" do
assert_macro(
%({% begin %}{% values = [] of Nil %}{% (1..3).each { |v| values << v } %}{{values}}{% end %}),
%([1, 2, 3])
%([1, 2, 3]),
)
end
end
Expand Down
Loading
Loading