Skip to content

Commit

Permalink
modify test to compare to a hash which better tests the state of each…
Browse files Browse the repository at this point in the history
… setting

also update @@COMMENTED_SETTING_REGEX to be roughly equal to "(\s*)[#;]+" + @@SETTING_REGEX
  • Loading branch information
doboy committed Sep 12, 2014
1 parent cb85148 commit 4415779
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/puppet/util/ini_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class IniFile

@@SECTION_REGEX = /^\s*\[([^\]]*)\]\s*$/
@@SETTING_REGEX = /^(\s*)([\w\d\.\\\/\-\s\[\]\']*[\w\d\.\\\/\-\]])([ \t]*=[ \t]*)([\S\s]*?)\s*$/
@@COMMENTED_SETTING_REGEX = /^(\s*)[#;]+(\s*)([^\[]*[\w\d\.\\\/\-]+[\w\d\.\\\/\-\[\]\']+)([ \t]*=[ \t]*)([\S\s]*?)\s*$/
@@COMMENTED_SETTING_REGEX = /^(\s*)[#;]+(\s*)([\w\d\.\\\/\-\s\[\]\']*[\w\d\.\\\/\-\]])([ \t]*=[ \t]*)([\S\s]*?)\s*$/

def initialize(path, key_val_separator = ' = ')
@path = path
Expand Down
22 changes: 14 additions & 8 deletions spec/unit/puppet/util/ini_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
foo= foovalue2
baz=bazvalue
; commented = out setting
#another comment
; yet another comment
zot = multi word value
Expand All @@ -46,14 +47,19 @@
end

it "should expose settings for sections" do
subject.get_value("section1", "foo").should == "foovalue"
subject.get_value("section1", "bar").should == "barvalue"
subject.get_value("section1", "baz").should == ""
subject.get_value("section2", "foo").should == "foovalue2"
subject.get_value("section2", "baz").should == "bazvalue"
subject.get_value("section2", "zot").should == "multi word value"
subject.get_value("section2", "xyzzy['thing1']['thing2']").should == "xyzzyvalue"
subject.get_value("section2", "l").should == "git log"
subject.get_settings("section1").should == {
"bar" => "barvalue",
"baz" => "",
"foo" => "foovalue"
}

subject.get_settings("section2").should == {
"baz" => "bazvalue",
"foo" => "foovalue2",
"l" => "git log",
"xyzzy['thing1']['thing2']" => "xyzzyvalue",
"zot" => "multi word value"
}
end

end
Expand Down

0 comments on commit 4415779

Please sign in to comment.