Fix unpacking empty list
Add a test for unpacking empty list properties and fix a bug that
resulted in nil slice instead of an empty slice.
diff --git a/unpack.go b/unpack.go
index e188d6f..445a8c6 100644
--- a/unpack.go
+++ b/unpack.go
@@ -293,7 +293,7 @@
}
}
- var list []string
+ list := []string{}
for _, value := range property.Value.ListValue {
if value.Type != parser.String {
// The parser should not produce this.
diff --git a/unpack_test.go b/unpack_test.go
index 393631c..0b31efc 100644
--- a/unpack_test.go
+++ b/unpack_test.go
@@ -59,13 +59,18 @@
{`
m {
stuff: ["asdf", "jkl;", "qwert",
- "uiop", "bnm,"]
+ "uiop", "bnm,"],
+ empty: []
}
`,
struct {
Stuff []string
+ Empty []string
+ Nil []string
}{
Stuff: []string{"asdf", "jkl;", "qwert", "uiop", "bnm,"},
+ Empty: []string{},
+ Nil: nil,
},
nil,
},