Skip to content

Commit

Permalink
Fix bug related to empty expressions
Browse files Browse the repository at this point in the history
Update other specs to use new format
  • Loading branch information
Blacksmoke16 committed Dec 23, 2024
1 parent 86e8959 commit 0f32ebd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
11 changes: 6 additions & 5 deletions spec/compiler/crystal/tools/expand_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe "expand" do
{% end %}
CRYSTAL

assert_expand_simple code, "1\n2\n3\n"
assert_expand_simple code, "1\n\n2\n\n3\n"
end

it "expands macro control {% for %} with cursor inside it" do
Expand All @@ -167,7 +167,7 @@ describe "expand" do
{% end %}
CRYSTAL

assert_expand_simple code, "1\n2\n3\n"
assert_expand_simple code, "1\n\n2\n\n3\n"
end

it "expands macro control {% for %} with cursor at end of it" do
Expand All @@ -177,7 +177,7 @@ describe "expand" do
‸{% end %}
CRYSTAL

assert_expand_simple code, "1\n2\n3\n"
assert_expand_simple code, "1\n\n2\n\n3\n"
end

it "expands macro control {% for %} with indent" do
Expand All @@ -195,7 +195,7 @@ describe "expand" do
{% end %}
CRYSTAL

assert_expand_simple code, original: original, expanded: "1\n2\n3\n"
assert_expand_simple code, original: original, expanded: "1\n\n2\n\n3\n"
end

it "expands simple macro" do
Expand Down Expand Up @@ -258,7 +258,7 @@ describe "expand" do
‸foo
CRYSTAL

assert_expand_simple code, original: "foo", expanded: %("if true"\n"1"\n"2"\n"3"\n)
assert_expand_simple code, original: "foo", expanded: %("if true"\n\n\n"1"\n\n"2"\n\n"3"\n)
end

it "expands macros with 2 level" do
Expand Down Expand Up @@ -615,6 +615,7 @@ describe "expand" do
def hello_str
"hello"
end
# symbol of hello
def hello_sym
:hello
Expand Down
6 changes: 6 additions & 0 deletions spec/compiler/semantic/restrictions_augmenter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ describe "Semantic: restrictions augmenter" do
class Baz
end
end
@x : Bar::Baz
def initialize(value : ::Foo::Bar::Baz)
@x = value
end
Expand Down Expand Up @@ -110,7 +112,9 @@ describe "Semantic: restrictions augmenter" do
class Baz
end
end
@x : Bar::Baz
def initialize(value : Bar::Baz)
@x = value
end
Expand Down Expand Up @@ -400,8 +404,10 @@ describe "Semantic: restrictions augmenter" do
macro foo
{{ yield }}
end
class Foo
end
class Bar
@x : Foo
def initialize(value : ::Foo)
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/syntax/to_s.cr
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ module Crystal
if @inside_macro > 0
node.expressions.each &.accept self
else
last_node = node.expressions.first
last_node = nil

node.expressions.each_with_index do |exp, i|
unless exp.nop?
self.write_extra_newlines last_node.end_location, exp.location do
self.write_extra_newlines((last_node || exp).end_location, exp.location) do
append_indent unless node.keyword.paren? && i == 0
exp.accept self
newline unless node.keyword.paren? && i == node.expressions.size - 1
Expand Down

0 comments on commit 0f32ebd

Please sign in to comment.