mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-05 17:36:59 +08:00
Added line and column operators
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
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`,
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user