mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Specs cleanup
This commit is contained in:
parent
e6ebca7a5b
commit
8112dddc8f
24 changed files with 267 additions and 251 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue