Skip to content

Commit

Permalink
Add example
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy committed Oct 12, 2021
1 parent d647cb1 commit 1179bab
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,37 @@ b: "hello"
// 3 | b: "hello"
}

func ExamplePath_AnnotateSourceWithComment() {
yml := `
# This is my document
doc:
# This comment should be line 3
map:
# And below should be line 5
- value1
- value2
other: value3
`
path, err := yaml.PathString("$.doc.map[0]")
if err != nil {
log.Fatal(err)
}
msg, err := path.AnnotateSource([]byte(yml), false)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(msg))
// OUTPUT:
// 4 | # This comment should be line 3
// 5 | map:
// 6 | # And below should be line 5
// > 7 | - value1
// ^
// 8 | - value2
// 9 | other: value3
// 10 |
}

func ExamplePath_PathString() {
yml := `
store:
Expand Down

0 comments on commit 1179bab

Please sign in to comment.