Merge pull request #126 from huan/master

fix issue where single characters settings were not being saved.
This commit is contained in:
Morgan Haskel 2014-11-06 15:27:05 -08:00
commit 3f4ad49b8c
2 changed files with 17 additions and 9 deletions

View file

@ -6,8 +6,8 @@ module Util
class IniFile class IniFile
@@SECTION_REGEX = /^\s*\[([^\]]*)\]\s*$/ @@SECTION_REGEX = /^\s*\[([^\]]*)\]\s*$/
@@SETTING_REGEX = /^(\s*)([^\[#;][\w\d\.\\\/\-\s\[\]\']*[\w\d\.\\\/\-\]])([ \t]*=[ \t]*)([\S\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 = ' = ') def initialize(path, key_val_separator = ' = ')
@path = path @path = path

View file

@ -26,10 +26,12 @@ baz =
foo= foovalue2 foo= foovalue2
baz=bazvalue baz=bazvalue
; commented = out setting
#another comment #another comment
; yet another comment ; yet another comment
zot = multi word value zot = multi word value
xyzzy['thing1']['thing2']=xyzzyvalue xyzzy['thing1']['thing2']=xyzzyvalue
l=git log
EOS EOS
template.split("\n") template.split("\n")
} }
@ -45,13 +47,19 @@ baz=bazvalue
end end
it "should expose settings for sections" do it "should expose settings for sections" do
subject.get_value("section1", "foo").should == "foovalue" subject.get_settings("section1").should == {
subject.get_value("section1", "bar").should == "barvalue" "bar" => "barvalue",
subject.get_value("section1", "baz").should == "" "baz" => "",
subject.get_value("section2", "foo").should == "foovalue2" "foo" => "foovalue"
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_settings("section2").should == {
"baz" => "bazvalue",
"foo" => "foovalue2",
"l" => "git log",
"xyzzy['thing1']['thing2']" => "xyzzyvalue",
"zot" => "multi word value"
}
end end
end end