-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_custom_test.go
More file actions
44 lines (35 loc) · 877 Bytes
/
example_custom_test.go
File metadata and controls
44 lines (35 loc) · 877 Bytes
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
package diff_test
import (
"fmt"
"strings"
"github.com/mibk/diff"
)
type ignoreCase struct {
a, b []string
}
func (ic ignoreCase) Lens() (n, m int) { return len(ic.a), len(ic.b) }
func (ic ignoreCase) Equal(i, j int) bool {
return strings.ToLower(ic.a[i]) == strings.ToLower(ic.b[j])
}
// missingIgnoreCase returns elements that are move or deleted from a
// compared to b.
func missingIgnoreCase(a, b []string) []string {
eds := diff.Diff(ignoreCase{a, b})
var miss []string
for _, ed := range eds {
if ed.Op == diff.Insert {
miss = append(miss, b[ed.Bindex])
}
}
return miss
}
func Example_customType() {
a := []string{"black", "#31ad1d", "#8923dd", "#baddad", "yellow"}
b := []string{"#31AD1D", "#8924dd", "#BadDad", "black", "YELLOW"}
for _, m := range missingIgnoreCase(a, b) {
fmt.Println("-", m)
}
// output:
// - #8924dd
// - black
}