From 5fbf63ce789b015da9abb95d7e9fbbf4a44ba7d1 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Fri, 12 Jun 2009 22:39:33 +1000 Subject: Updated split function and add split function unit tests (courtesy of Thomas Bellman) --- spec/unit/parser/functions/inline_template.rb | 0 spec/unit/parser/functions/regsubst.rb | 0 spec/unit/parser/functions/split.rb | 51 +++++++++++++++++++++++++++ spec/unit/parser/functions/sprintf.rb | 0 spec/unit/parser/functions/template.rb | 0 5 files changed, 51 insertions(+) mode change 100644 => 100755 spec/unit/parser/functions/inline_template.rb mode change 100644 => 100755 spec/unit/parser/functions/regsubst.rb create mode 100755 spec/unit/parser/functions/split.rb mode change 100644 => 100755 spec/unit/parser/functions/sprintf.rb mode change 100644 => 100755 spec/unit/parser/functions/template.rb (limited to 'spec/unit/parser/functions') diff --git a/spec/unit/parser/functions/inline_template.rb b/spec/unit/parser/functions/inline_template.rb old mode 100644 new mode 100755 diff --git a/spec/unit/parser/functions/regsubst.rb b/spec/unit/parser/functions/regsubst.rb old mode 100644 new mode 100755 diff --git a/spec/unit/parser/functions/split.rb b/spec/unit/parser/functions/split.rb new file mode 100755 index 000000000..8aa031d19 --- /dev/null +++ b/spec/unit/parser/functions/split.rb @@ -0,0 +1,51 @@ +#! /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 diff --git a/spec/unit/parser/functions/sprintf.rb b/spec/unit/parser/functions/sprintf.rb old mode 100644 new mode 100755 diff --git a/spec/unit/parser/functions/template.rb b/spec/unit/parser/functions/template.rb old mode 100644 new mode 100755 -- cgit