94 lines
2.0 KiB
Go
94 lines
2.0 KiB
Go
package camfish
|
|
|
|
import "reflect"
|
|
import "testing"
|
|
|
|
func TestParseINI_LF(test *testing.T) {
|
|
ini, err := ParseINI("input",
|
|
`thing= " Quoted string!!!!! "
|
|
Other-Thing = askdjlksajd
|
|
|
|
number = 3849
|
|
# comment
|
|
#also a comment
|
|
[section0]
|
|
value=1
|
|
|
|
[section1.a]
|
|
#dkjsaf
|
|
value=7
|
|
|
|
`)
|
|
if err != nil {
|
|
test.Fatal(err)
|
|
}
|
|
|
|
test.Log("INI:")
|
|
test.Log(ini)
|
|
if ini.Get("thing") != "\tQuoted string!!!!! " {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
if ini.Get("other-thing") != "askdjlksajd" {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
if ini.Get("number") != "3849" {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
if ini.Get("section0.value") != "1" {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
if ini.Get("section1.a.value") != "7" {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
}
|
|
|
|
func TestParseINI_CRLF(test *testing.T) {
|
|
ini, err := ParseINI("input", "thing= \"\tQuoted string!!!!! \"\r\nOther-Thing = askdjlksajd\r\n\r\nnumber = 3849\r\n# comment\r\n #also a comment\r\n[section0]\r\nvalue=1\r\n\r\n[section1.a]\r\n#dkjsaf\r\nvalue=7\r\n")
|
|
if err != nil {
|
|
test.Fatal(err)
|
|
}
|
|
|
|
test.Log("INI:")
|
|
test.Log(ini)
|
|
if ini.Get("thing") != "\tQuoted string!!!!! " {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
if ini.Get("other-thing") != "askdjlksajd" {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
if ini.Get("number") != "3849" {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
if ini.Get("section0.value") != "1" {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
if ini.Get("section1.a.value") != "7" {
|
|
test.Fatal("value is not correct")
|
|
}
|
|
}
|
|
|
|
func TestMergeINI(test *testing.T) {
|
|
iv := func(value string) iniValue {
|
|
return iniValue { value: value }
|
|
}
|
|
|
|
ini := mergeINI(iniConfig {
|
|
"foo": []iniValue { iv("bar") },
|
|
"baz": []iniValue { iv("something") },
|
|
},
|
|
iniConfig {
|
|
"baz": []iniValue { iv("value 1"), iv("value 2") },
|
|
},
|
|
iniConfig {
|
|
"thing": []iniValue { iv("????") },
|
|
});
|
|
test.Log(ini)
|
|
if !reflect.DeepEqual(ini, iniConfig {
|
|
"foo": []iniValue { iv("bar") },
|
|
"baz": []iniValue { iv("value 1"), iv("value 2") },
|
|
"thing": []iniValue { iv("????") },
|
|
}) {
|
|
test.Fatal("not equal")
|
|
}
|
|
}
|