2019-11-23 03:52:29 +00:00
|
|
|
package yqlib
|
2015-09-28 01:39:16 +00:00
|
|
|
|
|
|
|
import (
|
2015-09-28 02:00:38 +00:00
|
|
|
"fmt"
|
2015-10-05 23:01:33 +00:00
|
|
|
"sort"
|
2015-09-28 02:00:38 +00:00
|
|
|
"testing"
|
2019-12-01 20:10:42 +00:00
|
|
|
|
2019-12-04 05:10:28 +00:00
|
|
|
"github.com/mikefarah/yq/v2/test"
|
2019-12-01 19:44:44 +00:00
|
|
|
logging "gopkg.in/op/go-logging.v1"
|
2015-09-28 01:39:16 +00:00
|
|
|
)
|
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
func TestDataNavigator(t *testing.T) {
|
|
|
|
var log = logging.MustGetLogger("yq")
|
|
|
|
subject := NewDataNavigator(log)
|
|
|
|
|
|
|
|
t.Run("TestReadMap_simple", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2015-10-05 23:01:45 +00:00
|
|
|
---
|
|
|
|
b:
|
|
|
|
c: 2
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
got, _ := subject.ReadChildValue(data, []string{"b", "c"})
|
|
|
|
test.AssertResult(t, 2, got)
|
|
|
|
})
|
2015-09-28 01:39:16 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestReadMap_numberKey", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2019-04-29 23:43:09 +00:00
|
|
|
---
|
|
|
|
200: things
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
got, _ := subject.ReadChildValue(data, []string{"200"})
|
|
|
|
test.AssertResult(t, "things", got)
|
|
|
|
})
|
2019-04-29 23:43:09 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestReadMap_splat", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2015-10-05 23:01:33 +00:00
|
|
|
---
|
|
|
|
mapSplat:
|
|
|
|
item1: things
|
|
|
|
item2: whatever
|
2019-05-12 23:32:08 +00:00
|
|
|
otherThing: cat
|
2015-10-05 23:01:33 +00:00
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
res, _ := subject.ReadChildValue(data, []string{"mapSplat", "*"})
|
|
|
|
test.AssertResult(t, "[things whatever cat]", fmt.Sprintf("%v", res))
|
|
|
|
})
|
2019-05-12 23:32:08 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestReadMap_prefixSplat", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2019-05-12 23:32:08 +00:00
|
|
|
---
|
|
|
|
mapSplat:
|
|
|
|
item1: things
|
|
|
|
item2: whatever
|
|
|
|
otherThing: cat
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
res, _ := subject.ReadChildValue(data, []string{"mapSplat", "item*"})
|
|
|
|
test.AssertResult(t, "[things whatever]", fmt.Sprintf("%v", res))
|
|
|
|
})
|
2015-10-05 23:01:33 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestReadMap_deep_splat", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2015-10-05 23:01:33 +00:00
|
|
|
---
|
|
|
|
mapSplatDeep:
|
|
|
|
item1:
|
|
|
|
cats: bananas
|
|
|
|
item2:
|
|
|
|
cats: apples
|
|
|
|
`)
|
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
res, _ := subject.ReadChildValue(data, []string{"mapSplatDeep", "*", "cats"})
|
|
|
|
result := res.([]interface{})
|
|
|
|
var actual = []string{result[0].(string), result[1].(string)}
|
|
|
|
sort.Strings(actual)
|
|
|
|
test.AssertResult(t, "[apples bananas]", fmt.Sprintf("%v", actual))
|
|
|
|
})
|
2015-10-05 23:01:33 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestReadMap_key_doesnt_exist", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2015-10-05 23:01:45 +00:00
|
|
|
---
|
|
|
|
b:
|
|
|
|
c: 2
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
got, _ := subject.ReadChildValue(data, []string{"b", "x", "f", "c"})
|
|
|
|
test.AssertResult(t, nil, got)
|
|
|
|
})
|
2015-10-03 07:06:33 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestReadMap_recurse_against_string", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2015-10-05 23:01:45 +00:00
|
|
|
---
|
|
|
|
a: cat
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
got, _ := subject.ReadChildValue(data, []string{"a", "b"})
|
|
|
|
test.AssertResult(t, nil, got)
|
|
|
|
})
|
2015-10-05 03:47:24 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestReadMap_with_array", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2015-10-05 23:01:45 +00:00
|
|
|
---
|
|
|
|
b:
|
|
|
|
d:
|
|
|
|
- 3
|
|
|
|
- 4
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
got, _ := subject.ReadChildValue(data, []string{"b", "d", "1"})
|
|
|
|
test.AssertResult(t, 4, got)
|
|
|
|
})
|
2017-09-22 19:58:12 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestReadMap_with_array_and_bad_index", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2017-09-22 19:58:12 +00:00
|
|
|
---
|
|
|
|
b:
|
|
|
|
d:
|
|
|
|
- 3
|
|
|
|
- 4
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
_, err := subject.ReadChildValue(data, []string{"b", "d", "x"})
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Expected error due to invalid path")
|
|
|
|
}
|
|
|
|
expectedOutput := `error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
|
|
|
|
test.AssertResult(t, expectedOutput, err.Error())
|
|
|
|
})
|
2017-09-22 19:58:12 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestReadMap_with_mapsplat_array_and_bad_index", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2017-09-22 19:58:12 +00:00
|
|
|
---
|
|
|
|
b:
|
|
|
|
d:
|
|
|
|
e:
|
|
|
|
- 3
|
|
|
|
- 4
|
|
|
|
f:
|
|
|
|
- 1
|
|
|
|
- 2
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
_, err := subject.ReadChildValue(data, []string{"b", "d", "*", "x"})
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Expected error due to invalid path")
|
|
|
|
}
|
|
|
|
expectedOutput := `error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
|
|
|
|
test.AssertResult(t, expectedOutput, err.Error())
|
|
|
|
})
|
2017-09-22 19:58:12 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestReadMap_with_arraysplat_map_array_and_bad_index", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2017-09-22 19:58:12 +00:00
|
|
|
---
|
|
|
|
b:
|
|
|
|
d:
|
|
|
|
- names:
|
|
|
|
- fred
|
|
|
|
- smith
|
|
|
|
- names:
|
|
|
|
- sam
|
|
|
|
- bo
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
_, err := subject.ReadChildValue(data, []string{"b", "d", "*", "names", "x"})
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Expected error due to invalid path")
|
|
|
|
}
|
|
|
|
expectedOutput := `error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
|
|
|
|
test.AssertResult(t, expectedOutput, err.Error())
|
|
|
|
})
|
2015-09-29 00:56:28 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestReadMap_with_array_out_of_bounds", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2015-10-05 23:01:45 +00:00
|
|
|
---
|
|
|
|
b:
|
|
|
|
d:
|
|
|
|
- 3
|
|
|
|
- 4
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
got, _ := subject.ReadChildValue(data, []string{"b", "d", "3"})
|
|
|
|
test.AssertResult(t, nil, got)
|
|
|
|
})
|
2015-10-03 06:50:36 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestReadMap_with_array_out_of_bounds_by_1", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2016-03-16 05:11:06 +00:00
|
|
|
---
|
|
|
|
b:
|
|
|
|
d:
|
|
|
|
- 3
|
|
|
|
- 4
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
got, _ := subject.ReadChildValue(data, []string{"b", "d", "2"})
|
|
|
|
test.AssertResult(t, nil, got)
|
|
|
|
})
|
2016-03-16 05:11:06 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestReadMap_with_array_splat", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2015-10-05 23:01:45 +00:00
|
|
|
e:
|
|
|
|
-
|
|
|
|
name: Fred
|
|
|
|
thing: cat
|
|
|
|
-
|
|
|
|
name: Sam
|
|
|
|
thing: dog
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
got, _ := subject.ReadChildValue(data, []string{"e", "*", "name"})
|
|
|
|
test.AssertResult(t, "[Fred Sam]", fmt.Sprintf("%v", got))
|
|
|
|
})
|
2015-10-05 03:41:01 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestWrite_really_simple", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
|
|
|
b: 2
|
2017-02-26 22:01:52 +00:00
|
|
|
`)
|
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
updated := subject.UpdatedChildValue(data, []string{"b"}, "4")
|
|
|
|
test.AssertResult(t, "[{b 4}]", fmt.Sprintf("%v", updated))
|
|
|
|
})
|
2017-02-26 22:01:52 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestWrite_simple", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2015-10-05 23:01:45 +00:00
|
|
|
b:
|
|
|
|
c: 2
|
|
|
|
`)
|
2015-09-29 00:56:28 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
updated := subject.UpdatedChildValue(data, []string{"b", "c"}, "4")
|
|
|
|
test.AssertResult(t, "[{b [{c 4}]}]", fmt.Sprintf("%v", updated))
|
|
|
|
})
|
2015-10-01 04:43:57 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestWrite_new", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2017-04-11 23:16:54 +00:00
|
|
|
b:
|
|
|
|
c: 2
|
|
|
|
`)
|
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
updated := subject.UpdatedChildValue(data, []string{"b", "d"}, "4")
|
|
|
|
test.AssertResult(t, "[{b [{c 2} {d 4}]}]", fmt.Sprintf("%v", updated))
|
|
|
|
})
|
2017-04-11 23:16:54 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestWrite_new_deep", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2017-04-11 23:16:54 +00:00
|
|
|
b:
|
|
|
|
c: 2
|
|
|
|
`)
|
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
updated := subject.UpdatedChildValue(data, []string{"b", "d", "f"}, "4")
|
|
|
|
test.AssertResult(t, "[{b [{c 2} {d [{f 4}]}]}]", fmt.Sprintf("%v", updated))
|
|
|
|
})
|
2017-04-11 23:16:54 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestWrite_array", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2017-02-09 02:57:05 +00:00
|
|
|
b:
|
|
|
|
- aa
|
|
|
|
`)
|
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
updated := subject.UpdatedChildValue(data, []string{"b", "0"}, "bb")
|
2017-02-09 02:57:05 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
test.AssertResult(t, "[{b [bb]}]", fmt.Sprintf("%v", updated))
|
|
|
|
})
|
2017-02-09 02:57:05 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestWrite_new_array", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2017-04-11 23:16:54 +00:00
|
|
|
b:
|
|
|
|
c: 2
|
|
|
|
`)
|
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
updated := subject.UpdatedChildValue(data, []string{"b", "0"}, "4")
|
|
|
|
test.AssertResult(t, "[{b [{c 2} {0 4}]}]", fmt.Sprintf("%v", updated))
|
|
|
|
})
|
2017-04-11 23:16:54 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestWrite_new_array_deep", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2019-04-30 22:40:35 +00:00
|
|
|
a: apple
|
2017-04-11 23:16:54 +00:00
|
|
|
`)
|
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
updated := subject.UpdatedChildValue(data, []string{"b", "+", "c"}, "4")
|
|
|
|
test.AssertResult(t, "[{a apple} {b [[{c 4}]]}]", fmt.Sprintf("%v", updated))
|
|
|
|
})
|
2017-04-11 23:16:54 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestWrite_new_map_array_deep", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2017-04-11 23:16:54 +00:00
|
|
|
b:
|
|
|
|
c: 2
|
|
|
|
`)
|
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
updated := subject.UpdatedChildValue(data, []string{"b", "d", "+"}, "4")
|
|
|
|
test.AssertResult(t, "[{b [{c 2} {d [4]}]}]", fmt.Sprintf("%v", updated))
|
|
|
|
})
|
2017-04-11 23:16:54 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestWrite_add_to_array", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2017-04-17 22:53:27 +00:00
|
|
|
b:
|
|
|
|
- aa
|
|
|
|
`)
|
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
updated := subject.UpdatedChildValue(data, []string{"b", "1"}, "bb")
|
|
|
|
test.AssertResult(t, "[{b [aa bb]}]", fmt.Sprintf("%v", updated))
|
|
|
|
})
|
2017-04-17 22:53:27 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestWrite_with_no_tail", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2015-10-05 23:01:45 +00:00
|
|
|
b:
|
|
|
|
c: 2
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
updated := subject.UpdatedChildValue(data, []string{"b"}, "4")
|
2015-10-05 04:59:59 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
test.AssertResult(t, "[{b 4}]", fmt.Sprintf("%v", updated))
|
|
|
|
})
|
2017-04-14 02:39:55 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestWriteMap_no_paths", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2017-04-14 02:39:55 +00:00
|
|
|
b: 5
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
var new = test.ParseData(`
|
|
|
|
c: 4
|
|
|
|
`)
|
|
|
|
result := subject.UpdatedChildValue(data, []string{}, new)
|
|
|
|
test.AssertResult(t, fmt.Sprintf("%v", new), fmt.Sprintf("%v", result))
|
|
|
|
})
|
2017-04-14 02:39:55 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestWriteArray_no_paths", func(t *testing.T) {
|
|
|
|
var data = make([]interface{}, 1)
|
|
|
|
data[0] = "mike"
|
|
|
|
var new = test.ParseData(`
|
|
|
|
c: 4
|
|
|
|
`)
|
|
|
|
result := subject.UpdatedChildValue(data, []string{}, new)
|
|
|
|
test.AssertResult(t, fmt.Sprintf("%v", new), fmt.Sprintf("%v", result))
|
|
|
|
})
|
2018-05-04 15:46:58 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestDelete_MapItem", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2018-05-04 15:46:58 +00:00
|
|
|
a: 123
|
|
|
|
b: 456
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
var expected = test.ParseData(`
|
2018-05-04 15:46:58 +00:00
|
|
|
b: 456
|
|
|
|
`)
|
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
result, _ := subject.DeleteChildValue(data, []string{"a"})
|
|
|
|
test.AssertResult(t, fmt.Sprintf("%v", expected), fmt.Sprintf("%v", result))
|
|
|
|
})
|
2018-05-04 15:46:58 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
// Ensure deleting an index into a string does nothing
|
|
|
|
t.Run("TestDelete_index_to_string", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2018-05-04 15:46:58 +00:00
|
|
|
a: mystring
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
result, _ := subject.DeleteChildValue(data, []string{"a", "0"})
|
|
|
|
test.AssertResult(t, fmt.Sprintf("%v", data), fmt.Sprintf("%v", result))
|
|
|
|
})
|
2018-05-04 15:46:58 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestDelete_list_index", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2018-05-04 15:46:58 +00:00
|
|
|
a: [3, 4]
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
var expected = test.ParseData(`
|
2018-05-04 15:46:58 +00:00
|
|
|
a: [3]
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
result, _ := subject.DeleteChildValue(data, []string{"a", "1"})
|
|
|
|
test.AssertResult(t, fmt.Sprintf("%v", expected), fmt.Sprintf("%v", result))
|
|
|
|
})
|
2018-05-04 15:46:58 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestDelete_list_index_beyond_bounds", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2018-05-04 15:46:58 +00:00
|
|
|
a: [3, 4]
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
result, _ := subject.DeleteChildValue(data, []string{"a", "5"})
|
|
|
|
test.AssertResult(t, fmt.Sprintf("%v", data), fmt.Sprintf("%v", result))
|
|
|
|
})
|
2018-05-04 15:46:58 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestDelete_list_index_out_of_bounds_by_1", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2018-05-04 15:46:58 +00:00
|
|
|
a: [3, 4]
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
result, _ := subject.DeleteChildValue(data, []string{"a", "2"})
|
|
|
|
test.AssertResult(t, fmt.Sprintf("%v", data), fmt.Sprintf("%v", result))
|
|
|
|
})
|
2018-05-04 15:46:58 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestDelete_no_paths", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2018-05-04 15:46:58 +00:00
|
|
|
a: [3, 4]
|
|
|
|
b:
|
|
|
|
- name: test
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
result, _ := subject.DeleteChildValue(data, []string{})
|
|
|
|
test.AssertResult(t, fmt.Sprintf("%v", data), fmt.Sprintf("%v", result))
|
|
|
|
})
|
2018-05-04 15:46:58 +00:00
|
|
|
|
2019-12-01 19:44:44 +00:00
|
|
|
t.Run("TestDelete_array_map_item", func(t *testing.T) {
|
|
|
|
var data = test.ParseData(`
|
2018-05-04 15:46:58 +00:00
|
|
|
b:
|
|
|
|
- name: fred
|
|
|
|
value: blah
|
|
|
|
- name: john
|
|
|
|
value: test
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
var expected = test.ParseData(`
|
2018-05-04 15:46:58 +00:00
|
|
|
b:
|
|
|
|
- value: blah
|
|
|
|
- name: john
|
|
|
|
value: test
|
|
|
|
`)
|
2019-12-01 19:44:44 +00:00
|
|
|
result, _ := subject.DeleteChildValue(data, []string{"b", "0", "name"})
|
|
|
|
test.AssertResult(t, fmt.Sprintf("%v", expected), fmt.Sprintf("%v", result))
|
|
|
|
})
|
2019-12-01 20:10:42 +00:00
|
|
|
}
|