sq/cli/diff/internal/go-udiff/_examples/changes/main.go
2023-11-19 18:06:36 -07:00

26 lines
464 B
Go

package main
import (
"fmt"
udiff "github.com/neilotoole/sq/cli/diff/internal/go-udiff"
)
func main() {
a := "Hello, world!\n"
b := "Hello, Go!\nSay hi to µDiff"
edits := udiff.Strings(a, b)
d, err := udiff.ToUnifiedDiff("a.txt", "b.txt", a, edits, 3)
if err != nil {
panic(err)
}
for _, h := range d.Hunks {
fmt.Printf("hunk: -%d, +%d\n", h.FromLine, h.ToLine)
for _, l := range h.Lines {
fmt.Printf("%s %q\n", l.Kind, l.Content)
}
}
}