2018-05-03 15:57:47 +00:00
|
|
|
require "../../spec_helper"
|
|
|
|
|
|
|
|
module Ameba::AST
|
|
|
|
describe Branchable do
|
|
|
|
describe "#initialize" do
|
|
|
|
it "creates a new branchable" do
|
2022-12-19 17:03:11 +00:00
|
|
|
branchable = Branchable.new as_node "a = 2 if true"
|
2018-05-03 15:57:47 +00:00
|
|
|
branchable.node.should_not be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "delegation" do
|
|
|
|
it "delegates to_s to @node" do
|
2022-12-19 17:03:11 +00:00
|
|
|
node = as_node "a = 2 if true"
|
2018-05-03 15:57:47 +00:00
|
|
|
branchable = Branchable.new node
|
|
|
|
branchable.to_s.should eq node.to_s
|
|
|
|
end
|
|
|
|
|
2018-11-24 17:38:13 +00:00
|
|
|
it "delegates locations to @node" do
|
2022-12-19 17:03:11 +00:00
|
|
|
node = as_node "a = 2 if true"
|
2018-05-03 15:57:47 +00:00
|
|
|
branchable = Branchable.new node
|
|
|
|
branchable.location.should eq node.location
|
2018-11-24 17:38:13 +00:00
|
|
|
branchable.end_location.should eq node.end_location
|
2018-05-03 15:57:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#loop?" do
|
|
|
|
it "returns true if it is a while loop" do
|
2022-12-19 17:03:11 +00:00
|
|
|
branchable = Branchable.new as_node "while true; a = 2; end"
|
2018-05-03 15:57:47 +00:00
|
|
|
branchable.loop?.should be_true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true if it is the until loop" do
|
2022-12-19 17:03:11 +00:00
|
|
|
branchable = Branchable.new as_node "until false; a = 2; end"
|
2018-05-03 15:57:47 +00:00
|
|
|
branchable.loop?.should be_true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true if it is loop" do
|
2022-12-19 17:03:11 +00:00
|
|
|
branchable = Branchable.new as_node "loop {}"
|
2018-05-03 15:57:47 +00:00
|
|
|
branchable.loop?.should be_true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false otherwise" do
|
2022-12-19 17:03:11 +00:00
|
|
|
branchable = Branchable.new as_node "a = 2 if true"
|
2018-05-03 15:57:47 +00:00
|
|
|
branchable.loop?.should be_false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|