Skip to content

Commit

Permalink
add test example function for compare
Browse files Browse the repository at this point in the history
  • Loading branch information
semihbkgr committed Nov 4, 2024
1 parent c20f117 commit 541dcb9
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions compare/diff_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package compare

import (
"fmt"
"os"
"testing"

Expand Down Expand Up @@ -155,3 +156,39 @@ func readFile(t *testing.T, path string) []byte {
}
return data
}

func ExampleCompare() {
left := []byte(`
name: Alice
city: New York
items:
- one
- two
`)

right := []byte(`
name: Bob
value: 990
items:
- one
- three
`)

diffs, err := Compare(left, right, false, DefaultDiffOptions)
if err != nil {
panic(err)
}

output := diffs.Format(FormatOptions{
Plain: true,
Silent: false,
Metadata: false,
})
fmt.Println(output)

// Output:
// ~ name: Alice -> Bob
// - city: New York
// + value: 990
// ~ items[1]: two -> three
}

0 comments on commit 541dcb9

Please sign in to comment.