2020-11-14 02:38:44 +00:00
|
|
|
package yqlib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var deleteOperatorScenarios = []expressionScenario{
|
|
|
|
{
|
|
|
|
description: "Delete entry in map",
|
|
|
|
document: `{a: cat, b: dog}`,
|
|
|
|
expression: `del(.b)`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (doc)::{a: cat}\n",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "Delete entry in array",
|
|
|
|
document: `[1,2,3]`,
|
|
|
|
expression: `del(.[1])`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (doc)::[1, 3]\n",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "Delete no matches",
|
|
|
|
document: `{a: cat, b: dog}`,
|
|
|
|
expression: `del(.c)`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (doc)::{a: cat, b: dog}\n",
|
|
|
|
},
|
|
|
|
},
|
2020-11-19 11:11:26 +00:00
|
|
|
{
|
|
|
|
description: "Delete matching entries",
|
|
|
|
document: `{a: cat, b: dog, c: bat}`,
|
|
|
|
expression: `del( .[] | select(. == "*at") )`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (doc)::{b: dog}\n",
|
|
|
|
},
|
|
|
|
},
|
2020-11-14 02:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeleteOperatorScenarios(t *testing.T) {
|
|
|
|
for _, tt := range deleteOperatorScenarios {
|
|
|
|
testScenario(t, &tt)
|
|
|
|
}
|
2020-11-22 02:16:54 +00:00
|
|
|
documentScenarios(t, "Delete", deleteOperatorScenarios)
|
2020-11-14 02:38:44 +00:00
|
|
|
}
|