summaryrefslogtreecommitdiffstats
path: root/test/language/ast/selector.rb
blob: c7dfeb2feace01c1b2cb9d1e20aa2b8f83fa99f3 (plain)
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
#!/usr/bin/env ruby
#
#  Created by Luke A. Kanies on 2006-12-22.
#  Copyright (c) 2006. All rights reserved.

$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/

require 'puppettest'
require 'puppettest/parsertesting'

class TestSelector < Test::Unit::TestCase
	include PuppetTest
	include PuppetTest::ParserTesting
	AST = Puppet::Parser::AST
    
    def test_evaluate
        scope = mkscope
        upperparam = nameobj("MYPARAM")
        lowerparam = nameobj("myparam")
        
        should = {"MYPARAM" => "upper", "myparam" => "lower"}
        
        maker = Proc.new do
            {
            :default => AST::ResourceParam.new(:param => AST::Default.new(:value => "default"), :value => FakeAST.new("default")),
            :lower => AST::ResourceParam.new(:param => FakeAST.new("myparam"), :value => FakeAST.new("lower")),
            :upper => AST::ResourceParam.new(:param => FakeAST.new("MYPARAM"), :value => FakeAST.new("upper")),
            }
            
        end
        
        # Start out case-sensitive
        Puppet[:casesensitive] = true
        
        %w{MYPARAM myparam}.each do |str|
            param = nameobj(str)
            params = maker.call()
            sel = AST::Selector.new(:param => param, :values => params.values)
            result = nil
            assert_nothing_raised { result = sel.evaluate(:scope => scope) }
            assert_equal(should[str], result, "did not case-sensitively match %s" % str)
        end
        
        # then insensitive
        Puppet[:casesensitive] = false
        
        %w{MYPARAM myparam}.each do |str|
            param = nameobj(str)
            params = maker.call()

            # Delete the upper value, since we don't want it to match
            # and it introduces a hash-ordering bug in testing.
            params.delete(:upper)
            sel = AST::Selector.new(:param => param, :values => params.values)
            result = nil
            assert_nothing_raised { result = sel.evaluate(:scope => scope) }
            assert_equal("lower", result, "did not case-insensitively match %s" % str)
        end
    end
end

# $Id$