mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-15 07:38:14 +00:00
13d1bbb45f
Remove dependency on yaml.Node for internal AST representation. Yaml decoder is now just another decoder.
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package yqlib
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
var documentIndexScenarios = []expressionScenario{
|
|
{
|
|
description: "Retrieve a document index",
|
|
document: "a: cat\n---\na: frog\n",
|
|
expression: `.a | document_index`,
|
|
expected: []string{
|
|
"D0, P[a], (!!int)::0\n",
|
|
"D1, P[a], (!!int)::1\n",
|
|
},
|
|
},
|
|
{
|
|
description: "Retrieve a document index, shorthand",
|
|
document: "a: cat\n---\na: frog\n",
|
|
expression: `.a | di`,
|
|
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(document_index == 1)`,
|
|
expected: []string{
|
|
"D1, P[], (!!map)::a: frog\n",
|
|
},
|
|
},
|
|
{
|
|
description: "Filter by document index shorthand",
|
|
document: "a: cat\n---\na: frog\n",
|
|
expression: `select(di == 1)`,
|
|
expected: []string{
|
|
"D1, P[], (!!map)::a: frog\n",
|
|
},
|
|
},
|
|
{
|
|
description: "Print Document Index with matches",
|
|
document: "a: cat\n---\na: frog\n",
|
|
expression: `.a | ({"match": ., "doc": document_index})`,
|
|
expected: []string{
|
|
"D0, P[], (!!map)::match: cat\ndoc: 0\n",
|
|
"D1, P[], (!!map)::match: frog\ndoc: 1\n",
|
|
},
|
|
},
|
|
}
|
|
|
|
func TestDocumentIndexScenarios(t *testing.T) {
|
|
for _, tt := range documentIndexScenarios {
|
|
testScenario(t, &tt)
|
|
}
|
|
documentOperatorScenarios(t, "document-index", documentIndexScenarios)
|
|
}
|