diff --git a/spec/compiler/formatter/formatter_spec.cr b/spec/compiler/formatter/formatter_spec.cr index 28d2a8a4ef59..6ea82782d924 100644 --- a/spec/compiler/formatter/formatter_spec.cr +++ b/spec/compiler/formatter/formatter_spec.cr @@ -932,6 +932,9 @@ describe Crystal::Formatter do 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)" + assert_format "foo (1), 2" + assert_format "foo (1; 2)" assert_format "def foo(\n\n#foo\nx,\n\n#bar\nz\n)\nend", "def foo(\n # foo\n x,\n\n # bar\n z\n)\nend" assert_format "def foo(\nx, #foo\nz #bar\n)\nend", "def foo(\n x, # foo\n z # bar\n)\nend" assert_format "a = 1;;; b = 2", "a = 1; b = 2" diff --git a/spec/compiler/lexer/lexer_spec.cr b/spec/compiler/lexer/lexer_spec.cr index ae7f2a39c60b..83915fca0aa1 100644 --- a/spec/compiler/lexer/lexer_spec.cr +++ b/spec/compiler/lexer/lexer_spec.cr @@ -525,36 +525,36 @@ describe "Lexer" do lexer = Lexer.new ":a!=:a" token = lexer.next_token token.type.should eq(:SYMBOL) - token.value.should eq ("a") + token.value.should eq("a") token = lexer.next_token token.type.should eq(:"!=") token = lexer.next_token token.type.should eq(:SYMBOL) - token.value.should eq ("a") + token.value.should eq("a") end it "lexes symbol followed by ==" do lexer = Lexer.new ":a==:a" token = lexer.next_token token.type.should eq(:SYMBOL) - token.value.should eq ("a") + token.value.should eq("a") token = lexer.next_token token.type.should eq(:"==") token = lexer.next_token token.type.should eq(:SYMBOL) - token.value.should eq ("a") + token.value.should eq("a") end it "lexes symbol followed by ===" do lexer = Lexer.new ":a===:a" token = lexer.next_token token.type.should eq(:SYMBOL) - token.value.should eq ("a") + token.value.should eq("a") token = lexer.next_token token.type.should eq(:"===") token = lexer.next_token token.type.should eq(:SYMBOL) - token.value.should eq ("a") + token.value.should eq("a") end it "lexes != after identifier (#4815)" do diff --git a/spec/std/big/big_decimal_spec.cr b/spec/std/big/big_decimal_spec.cr index 05957fa6ece8..3129ee1fda64 100644 --- a/spec/std/big/big_decimal_spec.cr +++ b/spec/std/big/big_decimal_spec.cr @@ -219,32 +219,32 @@ describe BigDecimal do end it "can be converted from other types" do - 1.to_big_d.should eq (BigDecimal.new(1)) - "1.5".to_big_d.should eq (BigDecimal.new(15, 1)) - "+1.5".to_big_d.should eq (BigDecimal.new(15, 1)) - BigInt.new(15).to_big_d.should eq (BigDecimal.new(15, 0)) - 1.5.to_big_d.should eq (BigDecimal.new(15, 1)) - 1.5.to_big_f.to_big_d.should eq (BigDecimal.new(15, 1)) + 1.to_big_d.should eq(BigDecimal.new(1)) + "1.5".to_big_d.should eq(BigDecimal.new(15, 1)) + "+1.5".to_big_d.should eq(BigDecimal.new(15, 1)) + BigInt.new(15).to_big_d.should eq(BigDecimal.new(15, 0)) + 1.5.to_big_d.should eq(BigDecimal.new(15, 1)) + 1.5.to_big_f.to_big_d.should eq(BigDecimal.new(15, 1)) 1.5.to_big_r.to_big_d.should eq(BigDecimal.new(15, 1)) end it "can be converted from scientific notation" do - "10.01e1".to_big_d.should eq (BigDecimal.new("100.1")) - "10.01e-1".to_big_d.should eq (BigDecimal.new("1.001")) - "6.033e2".to_big_d.should eq (BigDecimal.new("603.3")) - "603.3e-2".to_big_d.should eq (BigDecimal.new("6.033")) - "-0.123e12".to_big_d.should eq (BigDecimal.new("-123000000000")) - "0.123e12".to_big_d.should eq (BigDecimal.new("123000000000")) - "0.123e+12".to_big_d.should eq (BigDecimal.new("123000000000")) - "-0.123e-7".to_big_d.should eq (BigDecimal.new("-0.0000000123")) - "-0.1e-7".to_big_d.should eq (BigDecimal.new("-0.00000001")) - "0.1e-7".to_big_d.should eq (BigDecimal.new("0.00000001")) - "1.0e-8".to_big_d.should eq (BigDecimal.new("0.00000001")) - "10e-8".to_big_d.should eq (BigDecimal.new("0.0000001")) - "1.0e+8".to_big_d.should eq (BigDecimal.new("100000000")) - "10e+8".to_big_d.should eq (BigDecimal.new("1000000000")) - "10E+8".to_big_d.should eq (BigDecimal.new("1000000000")) - "10E8".to_big_d.should eq (BigDecimal.new("1000000000")) + "10.01e1".to_big_d.should eq(BigDecimal.new("100.1")) + "10.01e-1".to_big_d.should eq(BigDecimal.new("1.001")) + "6.033e2".to_big_d.should eq(BigDecimal.new("603.3")) + "603.3e-2".to_big_d.should eq(BigDecimal.new("6.033")) + "-0.123e12".to_big_d.should eq(BigDecimal.new("-123000000000")) + "0.123e12".to_big_d.should eq(BigDecimal.new("123000000000")) + "0.123e+12".to_big_d.should eq(BigDecimal.new("123000000000")) + "-0.123e-7".to_big_d.should eq(BigDecimal.new("-0.0000000123")) + "-0.1e-7".to_big_d.should eq(BigDecimal.new("-0.00000001")) + "0.1e-7".to_big_d.should eq(BigDecimal.new("0.00000001")) + "1.0e-8".to_big_d.should eq(BigDecimal.new("0.00000001")) + "10e-8".to_big_d.should eq(BigDecimal.new("0.0000001")) + "1.0e+8".to_big_d.should eq(BigDecimal.new("100000000")) + "10e+8".to_big_d.should eq(BigDecimal.new("1000000000")) + "10E+8".to_big_d.should eq(BigDecimal.new("1000000000")) + "10E8".to_big_d.should eq(BigDecimal.new("1000000000")) end it "is comparable with other types" do diff --git a/spec/std/concurrent_spec.cr b/spec/std/concurrent_spec.cr index 644c79310aa8..c58578744050 100644 --- a/spec/std/concurrent_spec.cr +++ b/spec/std/concurrent_spec.cr @@ -76,7 +76,7 @@ describe "concurrent" do spawn do 3.times do |i| sleep 40.milliseconds - chan.send (i + 1) + chan.send(i + 1) end end spawn do diff --git a/spec/std/enum_spec.cr b/spec/std/enum_spec.cr index 3342fc37b6a8..cb37acbe5ea8 100644 --- a/spec/std/enum_spec.cr +++ b/spec/std/enum_spec.cr @@ -195,7 +195,7 @@ describe Enum do end it "for private enum" do - PrivateEnum.from_value(0).should eq (PrivateEnum::FOO) + PrivateEnum.from_value(0).should eq(PrivateEnum::FOO) end end diff --git a/spec/std/mime_spec.cr b/spec/std/mime_spec.cr index b2eefecb4974..389ef20a69c9 100644 --- a/spec/std/mime_spec.cr +++ b/spec/std/mime_spec.cr @@ -123,22 +123,22 @@ describe MIME do it "parses media types" do MIME.init(load_defaults: false) MIME.register(".parse-media-type1", "text/html; charset=utf-8") - MIME.extensions("text/html").should contain (".parse-media-type1") + MIME.extensions("text/html").should contain(".parse-media-type1") MIME.register(".parse-media-type2", "text/html; foo = bar; bar= foo ;") - MIME.extensions("text/html").should contain (".parse-media-type2") + MIME.extensions("text/html").should contain(".parse-media-type2") MIME.register(".parse-media-type3", "foo/bar") - MIME.extensions("foo/bar").should contain (".parse-media-type3") + MIME.extensions("foo/bar").should contain(".parse-media-type3") MIME.register(".parse-media-type4", " form-data ; name=foo") - MIME.extensions("form-data").should contain (".parse-media-type4") + MIME.extensions("form-data").should contain(".parse-media-type4") MIME.register(".parse-media-type41", %(FORM-DATA;name="foo")) - MIME.extensions("form-data").should contain (".parse-media-type41") + MIME.extensions("form-data").should contain(".parse-media-type41") MIME.register(".parse-media-type5", %( FORM-DATA ; name="foo")) - MIME.extensions("form-data").should contain (".parse-media-type5") + MIME.extensions("form-data").should contain(".parse-media-type5") expect_raises ArgumentError, "Invalid media type" do MIME.register(".parse-media-type6", ": inline; attachment; filename=foo.html") diff --git a/spec/std/string_spec.cr b/spec/std/string_spec.cr index 3863a1ef4ea7..e37646a69150 100644 --- a/spec/std/string_spec.cr +++ b/spec/std/string_spec.cr @@ -1020,57 +1020,57 @@ describe "String" do describe "partition" do describe "by char" do - it { "hello".partition('h').should eq ({"", "h", "ello"}) } - it { "hello".partition('o').should eq ({"hell", "o", ""}) } - it { "hello".partition('l').should eq ({"he", "l", "lo"}) } - it { "hello".partition('x').should eq ({"hello", "", ""}) } + it { "hello".partition('h').should eq({"", "h", "ello"}) } + it { "hello".partition('o').should eq({"hell", "o", ""}) } + it { "hello".partition('l').should eq({"he", "l", "lo"}) } + it { "hello".partition('x').should eq({"hello", "", ""}) } end describe "by string" do - it { "hello".partition("h").should eq ({"", "h", "ello"}) } - it { "hello".partition("o").should eq ({"hell", "o", ""}) } - it { "hello".partition("l").should eq ({"he", "l", "lo"}) } - it { "hello".partition("ll").should eq ({"he", "ll", "o"}) } - it { "hello".partition("x").should eq ({"hello", "", ""}) } + it { "hello".partition("h").should eq({"", "h", "ello"}) } + it { "hello".partition("o").should eq({"hell", "o", ""}) } + it { "hello".partition("l").should eq({"he", "l", "lo"}) } + it { "hello".partition("ll").should eq({"he", "ll", "o"}) } + it { "hello".partition("x").should eq({"hello", "", ""}) } end describe "by regex" do - it { "hello".partition(/h/).should eq ({"", "h", "ello"}) } - it { "hello".partition(/o/).should eq ({"hell", "o", ""}) } - it { "hello".partition(/l/).should eq ({"he", "l", "lo"}) } - it { "hello".partition(/ll/).should eq ({"he", "ll", "o"}) } - it { "hello".partition(/.l/).should eq ({"h", "el", "lo"}) } - it { "hello".partition(/.h/).should eq ({"hello", "", ""}) } - it { "hello".partition(/h./).should eq ({"", "he", "llo"}) } - it { "hello".partition(/o./).should eq ({"hello", "", ""}) } - it { "hello".partition(/.o/).should eq ({"hel", "lo", ""}) } - it { "hello".partition(/x/).should eq ({"hello", "", ""}) } + it { "hello".partition(/h/).should eq({"", "h", "ello"}) } + it { "hello".partition(/o/).should eq({"hell", "o", ""}) } + it { "hello".partition(/l/).should eq({"he", "l", "lo"}) } + it { "hello".partition(/ll/).should eq({"he", "ll", "o"}) } + it { "hello".partition(/.l/).should eq({"h", "el", "lo"}) } + it { "hello".partition(/.h/).should eq({"hello", "", ""}) } + it { "hello".partition(/h./).should eq({"", "he", "llo"}) } + it { "hello".partition(/o./).should eq({"hello", "", ""}) } + it { "hello".partition(/.o/).should eq({"hel", "lo", ""}) } + it { "hello".partition(/x/).should eq({"hello", "", ""}) } end end describe "rpartition" do describe "by char" do - it { "hello".rpartition('l').should eq ({"hel", "l", "o"}) } - it { "hello".rpartition('o').should eq ({"hell", "o", ""}) } - it { "hello".rpartition('h').should eq ({"", "h", "ello"}) } + it { "hello".rpartition('l').should eq({"hel", "l", "o"}) } + it { "hello".rpartition('o').should eq({"hell", "o", ""}) } + it { "hello".rpartition('h').should eq({"", "h", "ello"}) } end describe "by string" do - it { "hello".rpartition("l").should eq ({"hel", "l", "o"}) } - it { "hello".rpartition("x").should eq ({"", "", "hello"}) } - it { "hello".rpartition("o").should eq ({"hell", "o", ""}) } - it { "hello".rpartition("h").should eq ({"", "h", "ello"}) } - it { "hello".rpartition("ll").should eq ({"he", "ll", "o"}) } - it { "hello".rpartition("lo").should eq ({"hel", "lo", ""}) } - it { "hello".rpartition("he").should eq ({"", "he", "llo"}) } + it { "hello".rpartition("l").should eq({"hel", "l", "o"}) } + it { "hello".rpartition("x").should eq({"", "", "hello"}) } + it { "hello".rpartition("o").should eq({"hell", "o", ""}) } + it { "hello".rpartition("h").should eq({"", "h", "ello"}) } + it { "hello".rpartition("ll").should eq({"he", "ll", "o"}) } + it { "hello".rpartition("lo").should eq({"hel", "lo", ""}) } + it { "hello".rpartition("he").should eq({"", "he", "llo"}) } end describe "by regex" do - it { "hello".rpartition(/.l/).should eq ({"he", "ll", "o"}) } - it { "hello".rpartition(/ll/).should eq ({"he", "ll", "o"}) } - it { "hello".rpartition(/.o/).should eq ({"hel", "lo", ""}) } - it { "hello".rpartition(/.e/).should eq ({"", "he", "llo"}) } - it { "hello".rpartition(/l./).should eq ({"hel", "lo", ""}) } + it { "hello".rpartition(/.l/).should eq({"he", "ll", "o"}) } + it { "hello".rpartition(/ll/).should eq({"he", "ll", "o"}) } + it { "hello".rpartition(/.o/).should eq({"hel", "lo", ""}) } + it { "hello".rpartition(/.e/).should eq({"", "he", "llo"}) } + it { "hello".rpartition(/l./).should eq({"hel", "lo", ""}) } end end diff --git a/spec/std/yaml/serialization_spec.cr b/spec/std/yaml/serialization_spec.cr index 1c29d95e738e..5d386a199eba 100644 --- a/spec/std/yaml/serialization_spec.cr +++ b/spec/std/yaml/serialization_spec.cr @@ -66,7 +66,7 @@ describe "YAML serialization" do end it "can parse string that looks like a number" do - String.from_yaml(%(1.2)).should eq ("1.2") + String.from_yaml(%(1.2)).should eq("1.2") end it "does Path.from_yaml" do diff --git a/src/compiler/crystal/tools/formatter.cr b/src/compiler/crystal/tools/formatter.cr index 59b7b4dd65fa..e2eeb57894cb 100644 --- a/src/compiler/crystal/tools/formatter.cr +++ b/src/compiler/crystal/tools/formatter.cr @@ -2662,6 +2662,16 @@ module Crystal # so we remove the space between "as" and "(". skip_space if special_call + # If the call has a single argument which is a parenthesized `Expressions`, + # we skip whitespace between the method name and the arg. The parenthesized + # arg is transformed into a call with parenthesis: `foo (a)` becomes `foo(a)`. + if node.args.size == 1 && + !node.named_args && !node.block_arg && !node.block && + (expressions = node.args[0].as?(Expressions)) && + expressions.keyword == :"(" && expressions.expressions.size == 1 + skip_space + end + if @token.type == :"(" slash_is_regex! next_token