mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
AST Util
This commit is contained in:
parent
dcc0be892a
commit
6a81a648e3
8 changed files with 56 additions and 13 deletions
|
@ -1,10 +1,10 @@
|
|||
require "../spec_helper"
|
||||
require "../../spec_helper"
|
||||
|
||||
module Ameba
|
||||
module Ameba::AST
|
||||
rule = DummyRule.new
|
||||
source = Source.new ""
|
||||
|
||||
describe "AST Traverse" do
|
||||
describe "Traverse" do
|
||||
{% for name in NODE_VISITORS %}
|
||||
describe "{{name}}" do
|
||||
it "allow to visit {{name}} node" do
|
39
spec/ameba/ast/util_spec.cr
Normal file
39
spec/ameba/ast/util_spec.cr
Normal file
|
@ -0,0 +1,39 @@
|
|||
require "../../spec_helper"
|
||||
|
||||
module Ameba::AST
|
||||
struct Test
|
||||
include Util
|
||||
end
|
||||
|
||||
subject = Test.new
|
||||
|
||||
describe Util do
|
||||
describe "#literal?" do
|
||||
[
|
||||
Crystal::ArrayLiteral.new,
|
||||
Crystal::BoolLiteral.new(false),
|
||||
Crystal::CharLiteral.new('a'),
|
||||
Crystal::HashLiteral.new,
|
||||
Crystal::NamedTupleLiteral.new,
|
||||
Crystal::NilLiteral.new,
|
||||
Crystal::NumberLiteral.new(42),
|
||||
Crystal::RegexLiteral.new(Crystal::NilLiteral.new),
|
||||
Crystal::StringLiteral.new(""),
|
||||
Crystal::SymbolLiteral.new(""),
|
||||
Crystal::TupleLiteral.new([] of Crystal::ASTNode),
|
||||
Crystal::RangeLiteral.new(
|
||||
Crystal::NilLiteral.new,
|
||||
Crystal::NilLiteral.new,
|
||||
true),
|
||||
].each do |literal|
|
||||
it "returns true if node is #{literal}" do
|
||||
subject.literal?(literal).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
it "returns false if node is not a literal" do
|
||||
subject.literal?(Crystal::Nop).should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue