mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
6475c2bb25
* AST::Visitor -> AST::NodeVisitor * Scope & ScopeVisitor * Useless assignment rule * Instance vars and useless assignments * Multiple assigns one by one * Support outer scope * Variable used in the useless assignment * Support OpAssign & MultiAssign * Captured by block * Variable, Assignment, Reference & Refactoring * Variable has references, Assignment can be referenced * Branch entity * Handle useless assignments in branches * Handle assignments in a loop * Handle branch equality * Handle special var `$?` assignment * Improve captured by block stuff * Avoid assignments in property definitions (UselessAssign rule reports an warning) * Support MacroIf and MacroFor branches * Handle assignments with shadowed vars in inner scopes * Add method arguments as scope variables * Handle case if branch is blank * Top level scope * Handle case when branch is nop?
48 lines
1.3 KiB
Crystal
48 lines
1.3 KiB
Crystal
require "../../spec_helper"
|
|
|
|
module Ameba::AST
|
|
describe Branchable do
|
|
describe "#initialize" do
|
|
it "creates a new branchable" do
|
|
branchable = Branchable.new as_node %(a = 2 if true)
|
|
branchable.node.should_not be_nil
|
|
end
|
|
end
|
|
|
|
describe "delegation" do
|
|
it "delegates to_s to @node" do
|
|
node = as_node %(a = 2 if true)
|
|
branchable = Branchable.new node
|
|
branchable.to_s.should eq node.to_s
|
|
end
|
|
|
|
it "delegates location to @node" do
|
|
node = as_node %(a = 2 if true)
|
|
branchable = Branchable.new node
|
|
branchable.location.should eq node.location
|
|
end
|
|
end
|
|
|
|
describe "#loop?" do
|
|
it "returns true if it is a while loop" do
|
|
branchable = Branchable.new as_node %(while true; a = 2; end)
|
|
branchable.loop?.should be_true
|
|
end
|
|
|
|
it "returns true if it is the until loop" do
|
|
branchable = Branchable.new as_node %(until false; a = 2; end)
|
|
branchable.loop?.should be_true
|
|
end
|
|
|
|
it "returns true if it is loop" do
|
|
branchable = Branchable.new as_node %(loop {})
|
|
branchable.loop?.should be_true
|
|
end
|
|
|
|
it "returns false otherwise" do
|
|
branchable = Branchable.new as_node %(a = 2 if true)
|
|
branchable.loop?.should be_false
|
|
end
|
|
end
|
|
end
|
|
end
|