mirror of https://github.com/mikefarah/yq.git
33 lines
699 B
Go
33 lines
699 B
Go
|
package yqlib
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
var documentIndexScenarios = []expressionScenario{
|
||
|
{
|
||
|
description: "Retrieve a document index",
|
||
|
document: "a: cat\n---\na: frog\n",
|
||
|
expression: `.a | documentIndex`,
|
||
|
expected: []string{
|
||
|
"D0, P[a], (!!int)::0\n",
|
||
|
"D1, P[a], (!!int)::1\n",
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
description: "Filter by document index",
|
||
|
document: "a: cat\n---\na: frog\n",
|
||
|
expression: `select(. | documentIndex == 1)`,
|
||
|
expected: []string{
|
||
|
"D1, P[], (doc)::a: frog\n",
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
|
||
|
func TestDocumentIndexScenarios(t *testing.T) {
|
||
|
for _, tt := range documentIndexScenarios {
|
||
|
testScenario(t, &tt)
|
||
|
}
|
||
|
documentScenarios(t, "Document Index Operator", documentIndexScenarios)
|
||
|
}
|