-
Notifications
You must be signed in to change notification settings - Fork 1
/
filter_test.go
56 lines (45 loc) · 1.04 KB
/
filter_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
package dapper_test
import (
"fmt"
"reflect"
"testing"
. "github.com/dogmatiq/dapper"
)
func TestPrinter_WithFilter(t *testing.T) {
t.Run("it is passed a valid format function", func(t *testing.T) {
type testType struct {
i int
}
tt := testType{
i: 100,
}
p := NewPrinter(
WithFilter(
func(r Renderer, v Value) {
if v.DynamicType != reflect.TypeOf(testType{}) {
return
}
r.Print("github.com/dogmatiq/dapper_test.testType<")
fv := v.Value.FieldByName("i")
r.WriteValue(
Value{
Value: fv,
DynamicType: fv.Type(),
StaticType: fv.Type(),
IsAmbiguousDynamicType: false,
IsAmbiguousStaticType: false,
IsUnexported: true,
},
)
r.Print(">")
},
),
)
expected := fmt.Sprintf("github.com/dogmatiq/dapper_test.testType<%d>", tt.i)
t.Log("expected:\n\n" + expected + "\n")
actual := p.Format(tt)
if actual != expected {
t.Fatal("actual:\n\n" + actual + "\n")
}
})
}