Sha256: 7d803c6b1ef1cf00304aa6e1fab40747a9b5515299ffbf111adbe6b6b2cceec8

Contents?: true

Size: 1.48 KB

Versions: 6

Compression:

Stored size: 1.48 KB

Contents

#! /usr/bin/env ruby

require File.dirname(__FILE__) + '/../../../spec_helper'

describe "the split function" do

    before :each do
        @scope = Puppet::Parser::Scope.new()
    end

    it "should exist" do
        Puppet::Parser::Functions.function("split").should == "function_split"
    end

    it "should raise a ParseError if there is less than 2 arguments" do
        lambda { @scope.function_split(["foo"]) }.should(
		raise_error(Puppet::ParseError))
    end

    it "should raise a ParseError if there is more than 2 arguments" do
        lambda { @scope.function_split(["foo", "bar", "gazonk"]) }.should(
		raise_error(Puppet::ParseError))
    end

    it "should raise a RegexpError if the regexp is malformed" do
        lambda { @scope.function_split(["foo", "("]) }.should(
		raise_error(RegexpError))
    end


    it "should handle simple string without metacharacters" do
	result = @scope.function_split([ "130;236;254;10", ";"])
	result.should(eql(["130", "236", "254", "10"]))
    end

    it "should handle simple regexps" do
	result = @scope.function_split([ "130.236;254.;10", "[.;]+"])
	result.should(eql(["130", "236", "254", "10"]))
    end

    it "should handle groups" do
	result = @scope.function_split([ "130.236;254.;10", "([.;]+)"])
	result.should(eql(["130", ".", "236", ";", "254", ".;", "10"]))
    end

    it "should handle simple string without metacharacters" do
	result = @scope.function_split([ "130.236.254.10", ";"])
	result.should(eql(["130.236.254.10"]))
    end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
puppet-0.25.5 spec/unit/parser/functions/split.rb
puppet-0.25.4 spec/unit/parser/functions/split.rb
puppet-0.25.3 spec/unit/parser/functions/split.rb
puppet-0.25.2 spec/unit/parser/functions/split.rb
puppet-0.25.1 spec/unit/parser/functions/split.rb
puppet-0.25.0 spec/unit/parser/functions/split.rb