yq/pkg/yqlib/operator_line_test.go

48 lines
1010 B
Go
Raw Permalink Normal View History

2022-02-27 00:56:46 +00:00
package yqlib
import (
"testing"
)
var lineOperatorScenarios = []expressionScenario{
{
description: "Returns line of _value_ node",
document: "a: cat\nb:\n c: cat",
expression: `.b | line`,
expected: []string{
"D0, P[b], (!!int)::3\n",
},
},
{
description: "Returns line of _key_ node",
subdescription: "Pipe through the key operator to get the line of the key",
document: "a: cat\nb:\n c: cat",
expression: `.b | key | line`,
2022-02-27 00:56:46 +00:00
expected: []string{
"D0, P[b], (!!int)::2\n",
},
},
{
description: "First line is 1",
document: "a: cat",
expression: `.a | line`,
expected: []string{
"D0, P[a], (!!int)::1\n",
},
},
{
description: "No line data is 0",
expression: `{"a": "new entry"} | line`,
expected: []string{
"D0, P[], (!!int)::0\n",
},
},
}
func TestLineOperatorScenarios(t *testing.T) {
for _, tt := range lineOperatorScenarios {
testScenario(t, &tt)
}
documentOperatorScenarios(t, "line", lineOperatorScenarios)
}