-
Notifications
You must be signed in to change notification settings - Fork 41
/
option_test.go
70 lines (66 loc) · 1.6 KB
/
option_test.go
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package jsondiff
import (
"fmt"
"testing"
)
func TestDiffer_applyOpts(t *testing.T) {
d := Differ{}
var (
marshal = func(any) ([]byte, error) { return nil, nil }
unmarshal = func([]byte, any) error { return nil }
ignoredPaths = []string{
"/a/b/c",
"/x/0/y/2/z/3",
}
)
d.applyOpts(
Factorize(),
Rationalize(),
Equivalent(),
Invertible(),
MarshalFunc(marshal),
UnmarshalFunc(unmarshal),
SkipCompact(),
InPlaceCompaction(),
Ignores(ignoredPaths...),
LCS(),
)
if d.opts.factorize != true {
t.Errorf("factorize option is not enabled")
}
if d.opts.rationalize != true {
t.Errorf("rationalize option is not enabled")
}
if d.opts.equivalent != true {
t.Errorf("equivalent option is not enabled")
}
if d.opts.invertible != true {
t.Errorf("invertible option is not enabled")
}
if d.isCompact != true {
t.Errorf("input not marked as compact")
}
if d.compactInPlace != true {
t.Errorf("in-place compaction disabled")
}
if !cmpFuncs(d.opts.marshal, marshal) {
t.Errorf("marshal funcs mismatch")
}
if !cmpFuncs(d.opts.unmarshal, unmarshal) {
t.Errorf("unmarshal funcs mismatch")
}
if d.opts.hasIgnore != true {
t.Errorf("differ has no ignored paths")
} else if len(d.opts.ignores) != len(ignoredPaths) {
t.Errorf("ignored paths map length mismatch input")
}
if d.opts.lcs != true {
t.Errorf("lcs option is not enabled")
}
}
func cmpFuncs(x, y any) bool {
// Hacky comparison of the function addresses
// since the spec does not allow to compare funcs:
// https://go.dev/ref/spec#Comparison_operators
return fmt.Sprintf("%p", x) == fmt.Sprintf("%p", y)
}