From 15d241e138480e6eee0c9a4b660e5568fe60ada7 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Tue, 14 Nov 2023 03:03:17 +0100 Subject: [PATCH] Add spec for `AST::Util#{static,dynamic}_literal?` --- spec/ameba/ast/util_spec.cr | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/spec/ameba/ast/util_spec.cr b/spec/ameba/ast/util_spec.cr index ea3cb8d2..56169fed 100644 --- a/spec/ameba/ast/util_spec.cr +++ b/spec/ameba/ast/util_spec.cr @@ -36,6 +36,43 @@ module Ameba::AST end end + describe "#static/dynamic_literal?" do + [ + Crystal::ArrayLiteral.new, + Crystal::ArrayLiteral.new([Crystal::StringLiteral.new("foo")] of Crystal::ASTNode), + 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::StringLiteral.new("")), + Crystal::StringLiteral.new("foo"), + Crystal::SymbolLiteral.new("foo"), + Crystal::TupleLiteral.new([] of Crystal::ASTNode), + Crystal::TupleLiteral.new([Crystal::StringLiteral.new("foo")] of Crystal::ASTNode), + Crystal::RangeLiteral.new( + Crystal::NumberLiteral.new(0), + Crystal::NumberLiteral.new(10), + true), + ].each do |literal| + it "properly identifies static node #{literal}" do + subject.static_literal?(literal).should be_true + subject.dynamic_literal?(literal).should be_false + end + end + + [ + Crystal::ArrayLiteral.new([Crystal::Path.new(%w[IO])] of Crystal::ASTNode), + Crystal::TupleLiteral.new([Crystal::Path.new(%w[IO])] of Crystal::ASTNode), + ].each do |literal| + it "properly identifies dynamic node #{literal}" do + subject.dynamic_literal?(literal).should be_true + subject.static_literal?(literal).should be_false + end + end + end + describe "#node_source" do it "returns original source of the node" do s = <<-CRYSTAL