2020-11-20 11:57:32 +00:00
|
|
|
package yqlib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var fileOperatorScenarios = []expressionScenario{
|
|
|
|
{
|
|
|
|
description: "Get filename",
|
2020-11-20 12:08:12 +00:00
|
|
|
document: `{a: cat}`,
|
2020-11-20 11:57:32 +00:00
|
|
|
expression: `filename`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!str)::sample.yml\n",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "Get file index",
|
2020-11-20 12:08:12 +00:00
|
|
|
document: `{a: cat}`,
|
2022-02-10 22:05:17 +00:00
|
|
|
expression: `file_index`,
|
2020-11-20 11:57:32 +00:00
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!int)::0\n",
|
|
|
|
},
|
|
|
|
},
|
2021-02-15 06:31:12 +00:00
|
|
|
{
|
|
|
|
description: "Get file indices of multiple documents",
|
|
|
|
document: `{a: cat}`,
|
|
|
|
document2: `{a: cat}`,
|
2022-02-10 22:05:17 +00:00
|
|
|
expression: `file_index`,
|
2021-02-15 06:31:12 +00:00
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!int)::0\n",
|
|
|
|
"D0, P[], (!!int)::1\n",
|
|
|
|
},
|
|
|
|
},
|
2021-01-01 23:49:33 +00:00
|
|
|
{
|
|
|
|
description: "Get file index alias",
|
|
|
|
document: `{a: cat}`,
|
|
|
|
expression: `fi`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!int)::0\n",
|
|
|
|
},
|
|
|
|
},
|
2021-01-12 08:36:28 +00:00
|
|
|
{
|
|
|
|
skipDoc: true,
|
|
|
|
document: "a: cat\nb: dog",
|
|
|
|
expression: `.. lineComment |= filename`,
|
|
|
|
expected: []string{
|
2023-05-05 05:19:58 +00:00
|
|
|
"D0, P[], (doc)::a: cat # sample.yml\nb: dog # sample.yml\n",
|
2021-01-12 08:36:28 +00:00
|
|
|
},
|
|
|
|
},
|
2020-11-20 11:57:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFileOperatorsScenarios(t *testing.T) {
|
|
|
|
for _, tt := range fileOperatorScenarios {
|
|
|
|
testScenario(t, &tt)
|
|
|
|
}
|
2021-12-21 04:02:07 +00:00
|
|
|
documentOperatorScenarios(t, "file-operators", fileOperatorScenarios)
|
2020-11-20 11:57:32 +00:00
|
|
|
}
|