yq/pkg/yqlib/operator_group_by_test.go

32 lines
908 B
Go
Raw Normal View History

2021-10-26 04:07:50 +00:00
package yqlib
import (
"testing"
)
var groupByOperatorScenarios = []expressionScenario{
{
description: "Group by field",
document: `[{foo: 1, bar: 10}, {foo: 3, bar: 100}, {foo: 1, bar: 1}]`,
expression: `group_by(.foo)`,
expected: []string{
"D0, P[], (!!seq)::- - {foo: 1, bar: 10}\n - {foo: 1, bar: 1}\n- - {foo: 3, bar: 100}\n",
},
},
2023-05-30 01:39:25 +00:00
{
description: "Group by field, with nuls",
document: `[{cat: dog}, {foo: 1, bar: 10}, {foo: 3, bar: 100}, {no: foo for you}, {foo: 1, bar: 1}]`,
expression: `group_by(.foo)`,
expected: []string{
"D0, P[], (!!seq)::- - {cat: dog}\n - {no: foo for you}\n- - {foo: 1, bar: 10}\n - {foo: 1, bar: 1}\n- - {foo: 3, bar: 100}\n",
},
},
2021-10-26 04:07:50 +00:00
}
func TestGroupByOperatorScenarios(t *testing.T) {
for _, tt := range groupByOperatorScenarios {
testScenario(t, &tt)
}
2023-05-30 01:39:25 +00:00
documentOperatorScenarios(t, "group-by", groupByOperatorScenarios)
2021-10-26 04:07:50 +00:00
}