2020-12-01 06:58:07 +00:00
|
|
|
package yqlib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var pipeOperatorScenarios = []expressionScenario{
|
|
|
|
{
|
|
|
|
description: "Simple Pipe",
|
|
|
|
document: `{a: {b: cat}}`,
|
|
|
|
expression: `.a | .b`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[a b], (!!str)::cat\n",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "Multiple updates",
|
|
|
|
document: `{a: cow, b: sheep, c: same}`,
|
|
|
|
expression: `.a = "cat" | .b = "dog"`,
|
|
|
|
expected: []string{
|
2023-10-18 01:11:53 +00:00
|
|
|
"D0, P[], (!!map)::{a: cat, b: dog, c: same}\n",
|
2020-12-01 06:58:07 +00:00
|
|
|
},
|
|
|
|
},
|
2023-04-11 02:04:04 +00:00
|
|
|
{
|
|
|
|
skipDoc: true,
|
|
|
|
description: "Don't pass readonly context",
|
|
|
|
expression: `(3 + 4) | ({} | .b = "dog")`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!map)::b: dog\n",
|
|
|
|
},
|
|
|
|
},
|
2020-12-01 06:58:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPipeOperatorScenarios(t *testing.T) {
|
|
|
|
for _, tt := range pipeOperatorScenarios {
|
|
|
|
testScenario(t, &tt)
|
|
|
|
}
|
2021-12-21 04:02:07 +00:00
|
|
|
documentOperatorScenarios(t, "pipe", pipeOperatorScenarios)
|
2020-12-01 06:58:07 +00:00
|
|
|
}
|