Handle case when compiler reports incorrect node location

fixes #168
This commit is contained in:
Vitalii Elenhaupt 2020-10-23 10:41:17 +03:00
parent 9a42d14a1e
commit 44290a6a5d
No known key found for this signature in database
GPG key ID: CD0BF17825928BC0
4 changed files with 39 additions and 1 deletions

View file

@ -60,6 +60,24 @@ module Ameba::AST
" end",
])
end
it "does not report source of node which has incorrect location" do
s = %q(
module MyModule
macro conditional_error_for_inline_callbacks
\{%
raise ""
%}
end
macro before_save(x = nil)
end
end
)
node = as_nodes(s).nil_literal_nodes.first
source = subject.node_source node, s.split("\n")
source.should be_nil
end
end
describe "#flow_command?" do

View file

@ -95,6 +95,22 @@ module Ameba
end
)
it "does not report emtpy expression in macro" do
s = Source.new %q(
module MyModule
macro conditional_error_for_inline_callbacks
\{%
raise ""
%}
end
macro before_save(x = nil)
end
end
)
subject.catch(s).should be_valid
end
it "reports rule, location and message" do
s = Source.new %(
if ()

View file

@ -151,6 +151,7 @@ module Ameba
class TestNodeVisitor < Crystal::Visitor
NODES = [
Crystal::NilLiteral,
Crystal::Var,
Crystal::Assign,
Crystal::OpAssign,