mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 05:38:04 +00:00
41 lines
967 B
Go
41 lines
967 B
Go
package yqlib
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
var reduceOperatorScenarios = []expressionScenario{
|
|
{
|
|
description: "Sum numbers",
|
|
document: `[10,2, 5, 3]`,
|
|
expression: `.[] as $item ireduce (0; . + $item)`,
|
|
expected: []string{
|
|
"D0, P[], (!!int)::20\n",
|
|
},
|
|
},
|
|
{
|
|
description: "Merge all yaml files together",
|
|
document: `a: cat`,
|
|
document2: `b: dog`,
|
|
expression: `. as $item ireduce ({}; . * $item )`,
|
|
expected: []string{
|
|
"D0, P[], (!!map)::a: cat\nb: dog\n",
|
|
},
|
|
},
|
|
{
|
|
description: "Convert an array to an object",
|
|
document: `[{name: Cathy, has: apples},{name: Bob, has: bananas}]`,
|
|
expression: `.[] as $item ireduce ({}; .[$item | .name] = ($item | .has) )`,
|
|
expected: []string{
|
|
"D0, P[], (!!map)::Cathy: apples\nBob: bananas\n",
|
|
},
|
|
},
|
|
}
|
|
|
|
func TestReduceOperatorScenarios(t *testing.T) {
|
|
for _, tt := range reduceOperatorScenarios {
|
|
testScenario(t, &tt)
|
|
}
|
|
documentScenarios(t, "Reduce", reduceOperatorScenarios)
|
|
}
|