mirror of
https://github.com/taigrr/yq
synced 2025-01-18 04:53:17 -08:00
- Move data_navigator, json_converter, merge, and path_parser to pkg/yqlib - Extract yamlToString from yq to pkg/yqlib/yaml_converter - Move utils_test to test/utils
45 lines
1001 B
Go
45 lines
1001 B
Go
package yqlib
|
|
|
|
import (
|
|
"testing"
|
|
"github.com/mikefarah/yq/test"
|
|
)
|
|
|
|
var parsePathsTests = []struct {
|
|
path string
|
|
expectedPaths []string
|
|
}{
|
|
{"a.b", []string{"a", "b"}},
|
|
{"a.b[0]", []string{"a", "b", "0"}},
|
|
{"a.b.d[+]", []string{"a", "b", "d", "+"}},
|
|
}
|
|
|
|
func TestParsePath(t *testing.T) {
|
|
for _, tt := range parsePathsTests {
|
|
test.AssertResultComplex(t, tt.expectedPaths, ParsePath(tt.path))
|
|
}
|
|
}
|
|
|
|
var nextYamlPathTests = []struct {
|
|
path string
|
|
expectedElement string
|
|
expectedRemaining string
|
|
}{
|
|
{"a.b", "a", "b"},
|
|
{"a", "a", ""},
|
|
{"a.b.c", "a", "b.c"},
|
|
{"\"a.b\".c", "a.b", "c"},
|
|
{"a.\"b.c\".d", "a", "\"b.c\".d"},
|
|
{"[1].a.d", "1", "a.d"},
|
|
{"a[0].c", "a", "[0].c"},
|
|
{"[0]", "0", ""},
|
|
}
|
|
|
|
func TestNextYamlPath(t *testing.T) {
|
|
for _, tt := range nextYamlPathTests {
|
|
var element, remaining = nextYamlPath(tt.path)
|
|
test.AssertResultWithContext(t, tt.expectedElement, element, tt)
|
|
test.AssertResultWithContext(t, tt.expectedRemaining, remaining, tt)
|
|
}
|
|
}
|