2019-11-23 03:52:29 +00:00
|
|
|
package yqlib
|
2015-10-03 05:10:29 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2019-12-01 20:10:42 +00:00
|
|
|
|
2019-12-09 02:44:53 +00:00
|
|
|
"github.com/mikefarah/yq/v3/test"
|
2015-10-03 05:10:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var parsePathsTests = []struct {
|
|
|
|
path string
|
|
|
|
expectedPaths []string
|
|
|
|
}{
|
|
|
|
{"a.b", []string{"a", "b"}},
|
|
|
|
{"a.b[0]", []string{"a", "b", "0"}},
|
2017-09-24 00:21:16 +00:00
|
|
|
{"a.b.d[+]", []string{"a", "b", "d", "+"}},
|
2019-12-01 19:44:44 +00:00
|
|
|
{"a", []string{"a"}},
|
|
|
|
{"a.b.c", []string{"a", "b", "c"}},
|
|
|
|
{"\"a.b\".c", []string{"a.b", "c"}},
|
|
|
|
{"a.\"b.c\".d", []string{"a", "b.c", "d"}},
|
|
|
|
{"[1].a.d", []string{"1", "a", "d"}},
|
|
|
|
{"a[0].c", []string{"a", "0", "c"}},
|
|
|
|
{"[0]", []string{"0"}},
|
2015-10-03 05:10:29 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 23:40:33 +00:00
|
|
|
func TestParsePath(t *testing.T) {
|
2015-10-03 05:10:29 +00:00
|
|
|
for _, tt := range parsePathsTests {
|
2019-12-01 19:44:44 +00:00
|
|
|
test.AssertResultComplex(t, tt.expectedPaths, NewPathParser().ParsePath(tt.path))
|
2015-10-03 05:10:29 +00:00
|
|
|
}
|
2019-12-01 20:10:42 +00:00
|
|
|
}
|