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
|
#! /usr/bin/env ruby
require 'spec_helper'
require 'puppet/pops'
require 'puppet/pops/evaluator/evaluator_impl'
# relative to this spec file (./) does not work as this file is loaded by rspec
require File.join(File.dirname(__FILE__), '/evaluator_rspec_helper')
describe 'Puppet::Pops::Evaluator::EvaluatorImpl' do
include EvaluatorRspecHelper
context "When evaluator performs string interpolation" do
it "should interpolate a bare word as a variable name, \"${var}\"" do
a_block = block(var('a').set(10), string('value is ', text(fqn('a')), ' yo'))
evaluate(a_block).should == "value is 10 yo"
end
it "should interpolate a variable in a text expression, \"${$var}\"" do
a_block = block(var('a').set(10), string('value is ', text(var(fqn('a'))), ' yo'))
evaluate(a_block).should == "value is 10 yo"
end
it "should interpolate a variable, \"$var\"" do
a_block = block(var('a').set(10), string('value is ', var(fqn('a')), ' yo'))
evaluate(a_block).should == "value is 10 yo"
end
it "should interpolate any expression in a text expression, \"${$var*2}\"" do
a_block = block(var('a').set(5), string('value is ', text(var(fqn('a')) * 2) , ' yo'))
evaluate(a_block).should == "value is 10 yo"
end
it "should interpolate any expression without a text expression, \"${$var*2}\"" do
# there is no concrete syntax for this, but the parser can generate this simpler
# equivalent form where the expression is not wrapped in a TextExpression
a_block = block(var('a').set(5), string('value is ', var(fqn('a')) * 2 , ' yo'))
evaluate(a_block).should == "value is 10 yo"
end
# TODO: Add function call tests - Pending implementation of calls in the evaluator
end
end
|