Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion path.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,9 @@ type PathBuilder struct {
// Root add '$' to current path.
func (b *PathBuilder) Root() *PathBuilder {
root := newRootNode()
return &PathBuilder{root: root, node: root}
b.root = root
b.node = root
return b
}

// IndexAll add '[*]' to current path.
Expand Down
17 changes: 17 additions & 0 deletions path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ func TestPathBuilder(t *testing.T) {
}
}

func TestPathBuilderNoChain(t *testing.T) {
// See PR #420.
builder := yaml.PathBuilder{}
builder.Root()
builder.Child("a")
builder.Child("b")
builder.Index(0)
path := builder.Build()

expected := `$.a.b[0]`
got := path.String()

if expected != got {
t.Fatalf("failed to build path. expected:[%q] but got:[%q]", expected, got)
}
}

func TestPath(t *testing.T) {
yml := `
store:
Expand Down