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",
|
2023-03-16 02:39:36 +00:00
|
|
|
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)
|
|
|
|
}
|