File: ast_spec.rb

package info (click to toggle)
puppet 3.7.2-4%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 18,912 kB
  • ctags: 13,168
  • sloc: ruby: 210,410; sh: 2,050; xml: 1,554; lisp: 300; makefile: 142; python: 108; sql: 103; yacc: 72
file content (76 lines) | stat: -rwxr-xr-x 2,089 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#! /usr/bin/env ruby
require 'spec_helper'

require 'puppet/parser/ast'

describe Puppet::Parser::AST do
  it "should have a doc accessor" do
    ast = Puppet::Parser::AST.new({})
    ast.should respond_to(:doc)
  end

  it "should have a use_docs accessor to indicate it wants documentation" do
    ast = Puppet::Parser::AST.new({})
    ast.should respond_to(:use_docs)
  end

  [ Puppet::Parser::AST::Collection, Puppet::Parser::AST::Else,
    Puppet::Parser::AST::Function, Puppet::Parser::AST::IfStatement,
    Puppet::Parser::AST::Resource, Puppet::Parser::AST::ResourceDefaults,
    Puppet::Parser::AST::ResourceOverride, Puppet::Parser::AST::VarDef
  ].each do |k|
    it "#{k}.use_docs should return true" do
      ast = k.new({})
      ast.use_docs.should be_true
    end
  end

  describe "when initializing" do
    it "should store the doc argument if passed" do
      ast = Puppet::Parser::AST.new(:doc => "documentation")
      ast.doc.should == "documentation"
    end
  end

end

describe 'AST Generic Child' do
  let(:scope) { stub 'scope' }

  class Evaluateable < Puppet::Parser::AST
    attr_accessor :value
    def safeevaluate(*options)
      return value
    end
  end

  def ast_node_of(value)
    Evaluateable.new(:value => value)
  end

  describe "when evaluate_match is called" do
    it "matches when the values are equal" do
      ast_node_of('value').evaluate_match('value', scope).should be_true
    end

    it "matches in a case insensitive manner" do
      ast_node_of('vALue').evaluate_match('vALuE', scope).should be_true
    end

    it "matches strings that represent numbers" do
      ast_node_of("23").evaluate_match(23, scope).should be_true
    end

    it "matches numbers against strings that represent numbers" do
      ast_node_of(23).evaluate_match("23", scope).should be_true
    end

    it "matches undef if value is an empty string" do
      ast_node_of('').evaluate_match(:undef, scope).should be_true
    end

    it "matches '' if value is undef" do
      ast_node_of(:undef).evaluate_match('', scope).should be_true
    end
  end
end