Sha256: 66894d0a990a73e8e5a6ebed36284d8e62fc4ab6244ccba3aab909577d28a5f3

Contents?: true

Size: 1.58 KB

Versions: 128

Compression:

Stored size: 1.58 KB

Contents

#! /usr/bin/env ruby
require 'spec_helper'
require 'puppet/pops'
require_relative 'parser_rspec_helper'

describe "egrammar parsing of site expression" do
  include ParserRspecHelper

  context "when parsing 'site'" do
    it "an empty body is allowed" do
      prog = "site { }"
      ast = "(site ())"
      expect(dump(parse(prog))).to eq(ast)
    end

    it "a body with one expression is allowed" do
      prog = "site { $x = 1 }"
      ast = "(site (block\n  (= $x 1)\n))"
      expect(dump(parse(prog))).to eq(ast)
    end

    it "a body with more than one expression is allowed" do
      prog = "site { $x = 1 $y = 2}"
      ast = "(site (block\n  (= $x 1)\n  (= $y 2)\n))"
      expect(dump(parse(prog))).to eq(ast)
    end
  end

  context 'When parsing collections containing application management specific keywords' do
    %w(application site produces consumes).each do |keyword|
      it "allows the keyword '#{keyword}' in a list" do
        expect(dump(parse("$a = [#{keyword}]"))).to(eq("(= $a ([] '#{keyword}'))"))
      end

      it "allows the keyword '#{keyword}' as a key in a hash" do
        expect(dump(parse("$a = {#{keyword}=>'x'}"))).to(eq("(= $a ({} ('#{keyword}' 'x')))"))
      end

      it "allows the keyword '#{keyword}' as a value in a hash" do
        expect(dump(parse("$a = {'x'=>#{keyword}}"))).to(eq("(= $a ({} ('x' '#{keyword}')))"))
      end

      it "allows the keyword '#{keyword}' as an attribute name" do
        expect(dump(parse("foo { 'x': #{keyword} => 'value' } "))).to eql("(resource foo\n  ('x'\n    (#{keyword} => 'value')))")
      end
    end
  end
end

Version data entries

128 entries across 128 versions & 1 rubygems

Version Path
puppet-6.0.3 spec/unit/pops/parser/parse_site_spec.rb
puppet-6.0.3-x86-mingw32 spec/unit/pops/parser/parse_site_spec.rb
puppet-6.0.3-x64-mingw32 spec/unit/pops/parser/parse_site_spec.rb
puppet-6.0.3-universal-darwin spec/unit/pops/parser/parse_site_spec.rb
puppet-5.5.7 spec/unit/pops/parser/parse_site_spec.rb
puppet-5.5.7-x86-mingw32 spec/unit/pops/parser/parse_site_spec.rb
puppet-5.5.7-x64-mingw32 spec/unit/pops/parser/parse_site_spec.rb
puppet-5.5.7-universal-darwin spec/unit/pops/parser/parse_site_spec.rb
puppet-6.0.2 spec/unit/pops/parser/parse_site_spec.rb
puppet-6.0.2-x86-mingw32 spec/unit/pops/parser/parse_site_spec.rb
puppet-6.0.2-x64-mingw32 spec/unit/pops/parser/parse_site_spec.rb
puppet-6.0.2-universal-darwin spec/unit/pops/parser/parse_site_spec.rb
puppet-6.0.1 spec/unit/pops/parser/parse_site_spec.rb
puppet-6.0.1-x86-mingw32 spec/unit/pops/parser/parse_site_spec.rb
puppet-6.0.1-x64-mingw32 spec/unit/pops/parser/parse_site_spec.rb
puppet-6.0.1-universal-darwin spec/unit/pops/parser/parse_site_spec.rb
puppet-6.0.0 spec/unit/pops/parser/parse_site_spec.rb
puppet-6.0.0-x86-mingw32 spec/unit/pops/parser/parse_site_spec.rb
puppet-6.0.0-x64-mingw32 spec/unit/pops/parser/parse_site_spec.rb
puppet-6.0.0-universal-darwin spec/unit/pops/parser/parse_site_spec.rb