mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
parent
0002c36fae
commit
4f185db0a2
10 changed files with 404 additions and 39 deletions
|
@ -8,14 +8,14 @@ module Ameba::AST
|
|||
|
||||
describe "#initialize" do
|
||||
it "creates a new assignment with node and var" do
|
||||
assignment = Assignment.new(node, variable)
|
||||
assignment = Assignment.new(node, variable, scope)
|
||||
assignment.node.should_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "#reference=" do
|
||||
it "creates a new reference" do
|
||||
assignment = Assignment.new(node, variable)
|
||||
assignment = Assignment.new(node, variable, scope)
|
||||
assignment.referenced = true
|
||||
assignment.referenced?.should be_true
|
||||
end
|
||||
|
@ -23,18 +23,18 @@ module Ameba::AST
|
|||
|
||||
describe "delegation" do
|
||||
it "delegates locations" do
|
||||
assignment = Assignment.new(node, variable)
|
||||
assignment = Assignment.new(node, variable, scope)
|
||||
assignment.location.should eq node.location
|
||||
assignment.end_location.should eq node.end_location
|
||||
end
|
||||
|
||||
it "delegates to_s" do
|
||||
assignment = Assignment.new(node, variable)
|
||||
assignment = Assignment.new(node, variable, scope)
|
||||
assignment.to_s.should eq node.to_s
|
||||
end
|
||||
|
||||
it "delegates scope" do
|
||||
assignment = Assignment.new(node, variable)
|
||||
assignment = Assignment.new(node, variable, scope)
|
||||
assignment.scope.should eq variable.scope
|
||||
end
|
||||
end
|
||||
|
@ -52,7 +52,7 @@ module Ameba::AST
|
|||
|
||||
scope = Scope.new nodes.def_nodes.first
|
||||
variable = Variable.new(nodes.var_nodes.first, scope)
|
||||
assignment = Assignment.new(nodes.assign_nodes.first, variable)
|
||||
assignment = Assignment.new(nodes.assign_nodes.first, variable, scope)
|
||||
assignment.branch.should_not be_nil
|
||||
assignment.branch.not_nil!.node.class.should eq Crystal::Expressions
|
||||
end
|
||||
|
@ -69,7 +69,7 @@ module Ameba::AST
|
|||
)
|
||||
scope = Scope.new nodes.def_nodes.first
|
||||
variable = Variable.new(nodes.var_nodes.first, scope)
|
||||
assignment = Assignment.new(nodes.assign_nodes.first, variable)
|
||||
assignment = Assignment.new(nodes.assign_nodes.first, variable, scope)
|
||||
assignment.branch.should_not be_nil
|
||||
assignment.branch.not_nil!.node.class.should eq Crystal::Assign
|
||||
end
|
||||
|
@ -83,7 +83,7 @@ module Ameba::AST
|
|||
|
||||
scope = Scope.new nodes.def_nodes.first
|
||||
variable = Variable.new(nodes.var_nodes.first, scope)
|
||||
assignment = Assignment.new(nodes.assign_nodes.first, variable)
|
||||
assignment = Assignment.new(nodes.assign_nodes.first, variable, scope)
|
||||
assignment.branch.should be_nil
|
||||
end
|
||||
end
|
||||
|
@ -98,7 +98,7 @@ module Ameba::AST
|
|||
|
||||
scope = Scope.new nodes.def_nodes.first
|
||||
variable = Variable.new(nodes.var_nodes.first, scope)
|
||||
assignment = Assignment.new(nodes.assign_nodes.first, variable)
|
||||
assignment = Assignment.new(nodes.assign_nodes.first, variable, scope)
|
||||
assignment.transformed?.should be_false
|
||||
end
|
||||
|
||||
|
@ -110,7 +110,7 @@ module Ameba::AST
|
|||
|
||||
scope = Scope.new nodes.block_nodes.first
|
||||
variable = Variable.new(nodes.var_nodes.first, scope)
|
||||
assignment = Assignment.new(nodes.assign_nodes.first, variable)
|
||||
assignment = Assignment.new(nodes.assign_nodes.first, variable, scope)
|
||||
assignment.transformed?.should be_true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -47,14 +47,14 @@ module Ameba::AST
|
|||
|
||||
it "assigns the variable (creates a new assignment)" do
|
||||
variable = Variable.new(var_node, scope)
|
||||
variable.assign(assign_node)
|
||||
variable.assign(assign_node, scope)
|
||||
variable.assignments.any?.should be_true
|
||||
end
|
||||
|
||||
it "can create multiple assignments" do
|
||||
variable = Variable.new(var_node, scope)
|
||||
variable.assign(assign_node)
|
||||
variable.assign(assign_node)
|
||||
variable.assign(assign_node, scope)
|
||||
variable.assign(assign_node, scope)
|
||||
variable.assignments.size.should eq 2
|
||||
end
|
||||
end
|
||||
|
@ -62,10 +62,19 @@ module Ameba::AST
|
|||
describe "#reference" do
|
||||
it "references the existed assignment" do
|
||||
variable = Variable.new(var_node, scope)
|
||||
variable.assign(as_node "foo=1")
|
||||
variable.assign(as_node("foo=1"), scope)
|
||||
variable.reference(var_node, scope)
|
||||
variable.references.any?.should be_true
|
||||
end
|
||||
|
||||
it "adds a reference to the scope" do
|
||||
scope = Scope.new as_node "foo = 1"
|
||||
variable = Variable.new(var_node, scope)
|
||||
variable.assign(as_node("foo=1"), scope)
|
||||
variable.reference(var_node, scope)
|
||||
scope.references.size.should eq 1
|
||||
scope.references.first.node.to_s.should eq "foo"
|
||||
end
|
||||
end
|
||||
|
||||
describe "#captured_by_block?" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue