From e67523acaf96e4607fd081a1811406bdc7c9c6c4 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Wed, 26 Feb 2025 00:43:58 +0100 Subject: [PATCH] Add spec --- spec/compiler/parser/parser_spec.cr | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/spec/compiler/parser/parser_spec.cr b/spec/compiler/parser/parser_spec.cr index 69ac1ab452da..32a3de84b62e 100644 --- a/spec/compiler/parser/parser_spec.cr +++ b/spec/compiler/parser/parser_spec.cr @@ -2822,6 +2822,32 @@ module Crystal else_node_location.line_number.should eq 7 end + it "sets the correct location for MacroExpressions in a MacroFor" do + parser = Parser.new <<-CR + {% for key in %w[foo bar] %} + {{key}} + {% end %} + CR + + node = parser.parse.should be_a MacroFor + location = node.location.should_not be_nil + location.line_number.should eq 1 + location.column_number.should eq 1 + + body_node = node.body.should be_a Expressions + body_node_location = body_node.location.should_not be_nil + body_node_location.line_number.should eq 1 + body_node_location = body_node.end_location.should_not be_nil + body_node_location.line_number.should eq 3 + + then_node_location = body_node.expressions[1].location.should_not be_nil + then_node_location.line_number.should eq 2 + then_node_location.column_number.should eq 3 + then_node_location = body_node.expressions[1].end_location.should_not be_nil + then_node_location.line_number.should eq 2 + then_node_location.column_number.should eq 8 + end + it "sets correct location of Begin within another node" do parser = Parser.new(<<-CR) macro finished