mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
86639acf70
The base directory has all shell scripts in scripts/ and all example/test files in examples/. A Makefile provides all the commands with helpful information. If a developer simply types `make` then vendor is properly updated, the code is formatted, linted, tested, built, acceptance test run, and installed. Linting errors resolved. Ignored test case (`TestParsePath`) updated to work as expected.
43 lines
908 B
Go
43 lines
908 B
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
var parsePathsTests = []struct {
|
|
path string
|
|
expectedPaths []string
|
|
}{
|
|
{"a.b", []string{"a", "b"}},
|
|
{"a.b[0]", []string{"a", "b", "0"}},
|
|
}
|
|
|
|
func TestParsePath(t *testing.T) {
|
|
for _, tt := range parsePathsTests {
|
|
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)
|
|
assertResultWithContext(t, tt.expectedElement, element, tt)
|
|
assertResultWithContext(t, tt.expectedRemaining, remaining, tt)
|
|
}
|
|
}
|