Skip to content

Commit

Permalink
Formatter: consider consecutive macro literals when subformatting (#8034
Browse files Browse the repository at this point in the history
)

* Formatter: consider consecutive macro literals when subformatting

The lexer might produce consecutive macro literals instead of just a
single one, so when subformatting consider this case too.

* Formatter: correctly subformat comments

* Formatter: track def args when subformatting

* Formatter: consider content after comment when subformatting

* Formatter: consider nested macros when subformatting

* Run formatter

* fixup! Formatter: consider nested macros when subformatting
  • Loading branch information
asterite authored Aug 5, 2019
1 parent ea77acd commit fd0780c
Show file tree
Hide file tree
Showing 26 changed files with 881 additions and 736 deletions.
32 changes: 16 additions & 16 deletions spec/compiler/codegen/arithmetics_spec.cr
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
require "../../spec_helper"

{% if flag?(:darwin) %}
SupportedInts = [UInt8, UInt16, UInt32, UInt64, UInt128, Int8, Int16, Int32, Int64, Int128]
SupportedIntsConversions = {
to_i8: Int8, to_i16: Int16, to_i32: Int32, to_i64: Int64, to_i128: Int128,
to_u8: UInt8, to_u16: UInt16, to_u32: UInt32, to_u64: UInt64, to_u128: UInt128,
}
SupportedInts = [UInt8, UInt16, UInt32, UInt64, UInt128, Int8, Int16, Int32, Int64, Int128]
SupportedIntsConversions = {
to_i8: Int8, to_i16: Int16, to_i32: Int32, to_i64: Int64, to_i128: Int128,
to_u8: UInt8, to_u16: UInt16, to_u32: UInt32, to_u64: UInt64, to_u128: UInt128,
}

PreviewOverflowFlags = ["preview_overflow"]
PreviewOverflowFlags = ["preview_overflow"]
{% else %}
# Skip Int128 and UInt128 on linux platforms due to compiler-rt dependency.
# PreviewOverflowFlags includes compiler_rt flag to support Int64 overflow
# detection in 32 bits platforms.
SupportedInts = [UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64]
SupportedIntsConversions = {
to_i8: Int8, to_i16: Int16, to_i32: Int32, to_i64: Int64,
to_u8: UInt8, to_u16: UInt16, to_u32: UInt32, to_u64: UInt64,
}

PreviewOverflowFlags = ["preview_overflow", "compiler_rt"]
# Skip Int128 and UInt128 on linux platforms due to compiler-rt dependency.
# PreviewOverflowFlags includes compiler_rt flag to support Int64 overflow
# detection in 32 bits platforms.
SupportedInts = [UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64]
SupportedIntsConversions = {
to_i8: Int8, to_i16: Int16, to_i32: Int32, to_i64: Int64,
to_u8: UInt8, to_u16: UInt16, to_u32: UInt32, to_u64: UInt64,
}

PreviewOverflowFlags = ["preview_overflow", "compiler_rt"]
{% end %}

describe "Code gen: arithmetics primitives" do
Expand Down
20 changes: 10 additions & 10 deletions spec/compiler/codegen/thread_local_spec.cr
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require "../../spec_helper"

{% if !flag?(:openbsd) %}
describe "Codegen: thread local" do
it "works with class variables" do
run(%(
describe "Codegen: thread local" do
it "works with class variables" do
run(%(
require "prelude"
class Foo
Expand All @@ -22,10 +22,10 @@ describe "Codegen: thread local" do
Foo.var
)).to_i.should eq(123)
end
end

it "works with class variable in main thread" do
run(%(
it "works with class variable in main thread" do
run(%(
require "prelude"
class Foo
Expand All @@ -39,10 +39,10 @@ describe "Codegen: thread local" do
Foo.a
)).to_i.should eq(123)
end
end

it "compiles with class variable referenced from initializer" do
run(%(
it "compiles with class variable referenced from initializer" do
run(%(
require "prelude"
class Foo
Expand All @@ -61,6 +61,6 @@ describe "Codegen: thread local" do
0
))
end
end
end
{% end %}
72 changes: 72 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,78 @@ describe Crystal::Formatter do
{% end %}
CODE

assert_format <<-BEFORE,
{% if z %}
class Foo
end
{% end %}
BEFORE
<<-AFTER
{% if z %}
class Foo
end
{% end %}
AFTER

assert_format <<-CODE
{% if true %}
# x
{% end %}
CODE

assert_format <<-CODE
{% if true %}
# x
# y
{% end %}
CODE

assert_format <<-CODE
{% if true %}
# x
#
{% end %}
# ```
# x
# ```
CODE

assert_format <<-CODE
def foo(x)
{% if true %}
x = x + 2
{% end %}
end
CODE

assert_format <<-CODE
def foo(x)
{% if true %}
# comment
Foo = 1
B = 2
{% end %}
end
CODE

assert_format <<-CODE
def foo(x)
{% if true %}
\\{% if true %}
x = 1
\\{% else %}
x = 2
\\{% end %}
\\{% for x in y %}
x = 1
\\{% end %}
\\{{x}}
\\{% x %}
{% end %}
end
CODE

it "gives proper line number in syntax error inside macro" do
source = <<-CODE
a = 1
Expand Down
Loading

0 comments on commit fd0780c

Please sign in to comment.