File: example_test.go

package info (click to toggle)
golang-github-pkg-diff 0.0~git20210226.20ebb0f-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 3,528 kB
  • sloc: makefile: 3
file content (52 lines) | stat: -rw-r--r-- 586 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package diff_test

import (
	"os"

	"github.com/pkg/diff"
)

func Example_Slices() {
	want := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
	got := []int{1, 2, 3, 4, 6, 7, 8, 9}
	err := diff.Slices("want", "got", want, got, os.Stdout)
	if err != nil {
		panic(err)
	}
	// Output:
	// --- want
	// +++ got
	// @@ -2,7 +2,6 @@
	//  2
	//  3
	//  4
	// -5
	//  6
	//  7
	//  8
}

func Example_Text() {
	a := `
a
b
c
`[1:]
	b := `
a
c
d
`[1:]
	err := diff.Text("a", "b", a, b, os.Stdout)
	if err != nil {
		panic(err)
	}
	// Output:
	// --- a
	// +++ b
	// @@ -1,3 +1,3 @@
	//  a
	// -b
	//  c
	// +d
}