mirror of
https://github.com/TomWright/dasel.git
synced 2022-05-22 02:32:45 +03:00
Add some tests
This commit is contained in:
@@ -140,7 +140,6 @@ func deleteFromParentIndex(n *Node) error {
|
||||
}
|
||||
|
||||
// cleanupSliceDeletions scans through the given reflect and removes any invalid reflect values.
|
||||
// Does not modify the original value.
|
||||
// Returns false if no modification was made.
|
||||
func cleanupSliceDeletions(input reflect.Value) (reflect.Value, bool) {
|
||||
value := unwrapValue(input)
|
||||
@@ -153,11 +152,7 @@ func cleanupSliceDeletions(input reflect.Value) (reflect.Value, bool) {
|
||||
|
||||
for i := 0; i < value.Len(); i++ {
|
||||
item := value.Index(i)
|
||||
if !item.IsValid() {
|
||||
invalidCount++
|
||||
continue
|
||||
}
|
||||
if isDeletePlaceholder(item) {
|
||||
if !item.IsValid() || isDeletePlaceholder(item) {
|
||||
invalidCount++
|
||||
continue
|
||||
}
|
||||
|
||||
37
node_test.go
37
node_test.go
@@ -985,7 +985,7 @@ func TestNode_PutMultiple_Query(t *testing.T) {
|
||||
t.Run("NilChainToListNextAvailableIndex", putQueryMultipleTest(dasel.New(nil), "my.favourite.people.[]", "Tom", "my.favourite.people.[0]"))
|
||||
}
|
||||
|
||||
func TestNode_Delete_Query(t *testing.T) {
|
||||
func TestNode_Delete(t *testing.T) {
|
||||
data := func() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"id": "123",
|
||||
@@ -1079,6 +1079,19 @@ func TestNode_Delete_Query(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}))
|
||||
t.Run("ExistingArray", deleteMultipleTest(dasel.New(data()), "names", map[string]interface{}{
|
||||
"id": "123",
|
||||
"people": []map[string]interface{}{
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Tom",
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Jim",
|
||||
},
|
||||
},
|
||||
}))
|
||||
t.Run("RootNodeObject", deleteTest(dasel.New(map[string]interface{}{
|
||||
"name": "Tom",
|
||||
}), ".", map[string]interface{}{}))
|
||||
@@ -1184,6 +1197,28 @@ func TestNode_DeleteMultiple_Query(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}))
|
||||
t.Run("AllObjectsInArray", deleteMultipleTest(dasel.New(data()), "people.[*]", map[string]interface{}{
|
||||
"id": "123",
|
||||
"names": []string{
|
||||
"Tom",
|
||||
"Jim",
|
||||
},
|
||||
"people": []map[string]interface{}{},
|
||||
}))
|
||||
t.Run("ExistingArray", deleteMultipleTest(dasel.New(data()), "names", map[string]interface{}{
|
||||
"id": "123",
|
||||
"people": []map[string]interface{}{
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Tom",
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Jim",
|
||||
},
|
||||
},
|
||||
}))
|
||||
t.Run("AllItemsInObject", deleteMultipleTest(dasel.New(data()), ".[*]", map[string]interface{}{}))
|
||||
t.Run("RootNodeObject", deleteMultipleTest(dasel.New(map[string]interface{}{
|
||||
"name": "Tom",
|
||||
}), ".", map[string]interface{}{}))
|
||||
|
||||
Reference in New Issue
Block a user