yq/pkg/yqlib/operator_map_test.go

52 lines
1.0 KiB
Go
Raw Permalink Normal View History

2021-11-30 23:32:36 +00:00
package yqlib
import (
"testing"
)
var mapOperatorScenarios = []expressionScenario{
{
skipDoc: true,
document: `[1,2,3]`,
document2: `[5,6,7]`,
expression: `map(. + 1)`,
expected: []string{
"D0, P[], (!!seq)::[2, 3, 4]\n",
"D0, P[], (!!seq)::[6, 7, 8]\n",
},
},
{
description: "Map array",
document: `[1,2,3]`,
expression: `map(. + 1)`,
expected: []string{
"D0, P[], (!!seq)::[2, 3, 4]\n",
},
},
{
skipDoc: true,
document: `{a: 1, b: 2, c: 3}`,
document2: `{x: 10, y: 20, z: 30}`,
expression: `map_values(. + 1)`,
expected: []string{
"D0, P[], (!!map)::{a: 2, b: 3, c: 4}\n",
"D0, P[], (!!map)::{x: 11, y: 21, z: 31}\n",
2021-11-30 23:32:36 +00:00
},
},
{
description: "Map object values",
document: `{a: 1, b: 2, c: 3}`,
expression: `map_values(. + 1)`,
expected: []string{
"D0, P[], (!!map)::{a: 2, b: 3, c: 4}\n",
2021-11-30 23:32:36 +00:00
},
},
}
func TestMapOperatorScenarios(t *testing.T) {
for _, tt := range mapOperatorScenarios {
testScenario(t, &tt)
}
2021-12-21 04:02:07 +00:00
documentOperatorScenarios(t, "map", mapOperatorScenarios)
2021-11-30 23:32:36 +00:00
}