Fixed ability to grow arrays

This commit is contained in:
Mike Farah 2017-04-18 08:53:27 +10:00
parent 0facf35d60
commit 909b62be54
2 changed files with 18 additions and 0 deletions

View File

@ -82,6 +82,9 @@ func writeArray(context interface{}, paths []string, value interface{}) []interf
if err != nil { if err != nil {
die("Error accessing array: %v", err) die("Error accessing array: %v", err)
} }
for index >= int64(len(array)) {
array = append(array, nil)
}
currentChild := array[index] currentChild := array[index]
log.Debugf("\tcurrentChild %v\n", currentChild) log.Debugf("\tcurrentChild %v\n", currentChild)

View File

@ -205,6 +205,21 @@ b:
assertResult(t, "4", readMap(updated, "b", []string{"d", "0"})) assertResult(t, "4", readMap(updated, "b", []string{"d", "0"}))
} }
func TestWrite_add_to_array(t *testing.T) {
var data = parseData(`
b:
- aa
`)
var expected = `b:
- aa
- bb`
updated := writeMap(data, []string{"b", "1"}, "bb")
assertResult(t, expected, yamlToString(updated))
}
func TestWrite_with_no_tail(t *testing.T) { func TestWrite_with_no_tail(t *testing.T) {
var data = parseData(` var data = parseData(`
b: b: