Specs cleanup

This commit is contained in:
Sijawusz Pur Rahnama 2022-12-19 18:03:11 +01:00
parent e6ebca7a5b
commit 8112dddc8f
24 changed files with 267 additions and 251 deletions

View file

@ -41,15 +41,14 @@ module Ameba::AST
describe "#branch" do
it "returns the branch of the assignment" do
nodes = as_nodes %(
nodes = as_nodes <<-CRYSTAL
def method(a)
if a
a = 3 # --> Crystal::Expressions
puts a
end
end
)
CRYSTAL
scope = Scope.new nodes.def_nodes.first
variable = Variable.new(nodes.var_nodes.first, scope)
assignment = Assignment.new(nodes.assign_nodes.first, variable, scope)
@ -58,7 +57,7 @@ module Ameba::AST
end
it "returns inner branch" do
nodes = as_nodes %(
nodes = as_nodes <<-CRYSTAL
def method(a, b)
if a
if b
@ -66,7 +65,7 @@ module Ameba::AST
end
end
end
)
CRYSTAL
scope = Scope.new nodes.def_nodes.first
variable = Variable.new(nodes.var_nodes.first, scope)
assignment = Assignment.new(nodes.assign_nodes.first, variable, scope)
@ -75,12 +74,11 @@ module Ameba::AST
end
it "returns nil if assignment does not have a branch" do
nodes = as_nodes %(
nodes = as_nodes <<-CRYSTAL
def method(a)
a = 2
end
)
CRYSTAL
scope = Scope.new nodes.def_nodes.first
variable = Variable.new(nodes.var_nodes.first, scope)
assignment = Assignment.new(nodes.assign_nodes.first, variable, scope)
@ -90,12 +88,11 @@ module Ameba::AST
describe "#transformed?" do
it "returns false if the assignment is not transformed by the compiler" do
nodes = as_nodes %(
nodes = as_nodes <<-CRYSTAL
def method(a)
a = 2
end
)
CRYSTAL
scope = Scope.new nodes.def_nodes.first
variable = Variable.new(nodes.var_nodes.first, scope)
assignment = Assignment.new(nodes.assign_nodes.first, variable, scope)
@ -103,11 +100,10 @@ module Ameba::AST
end
it "returns true if the assignment is transformed by the compiler" do
nodes = as_nodes %(
nodes = as_nodes <<-CRYSTAL
array.each do |(a, b)|
end
)
CRYSTAL
scope = Scope.new nodes.block_nodes.first
variable = Variable.new(nodes.var_nodes.first, scope)
assignment = Assignment.new(nodes.assign_nodes.first, variable, scope)

View file

@ -79,12 +79,12 @@ module Ameba::AST
describe "#captured_by_block?" do
it "returns truthy if the variable is captured by block" do
nodes = as_nodes %(
nodes = as_nodes <<-CRYSTAL
def method
a = 2
3.times { |i| a = a + i }
end
)
CRYSTAL
scope = Scope.new nodes.def_nodes.first
var_node = nodes.var_nodes.first
scope.add_variable var_node
@ -95,12 +95,12 @@ module Ameba::AST
variable.captured_by_block?.should be_truthy
end
it "returns falsey if the variable is not captured by the block" do
scope = Scope.new as_node %(
it "returns falsy if the variable is not captured by the block" do
scope = Scope.new as_node <<-CRYSTAL
def method
a = 1
end
)
CRYSTAL
scope.add_variable Crystal::Var.new "a"
variable = scope.variables.first
variable.captured_by_block?.should be_falsey