-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson_test.go
53 lines (45 loc) · 1.55 KB
/
json_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
package logiface
import (
"fmt"
"testing"
)
type (
minimalJSONSupportMethods[E Event, O any, A any] interface {
NewObject() O
AddObject(evt E, key string, obj O)
SetField(obj O, key string, val any) O
NewArray() A
AddArray(evt E, key string, arr A)
AppendField(arr A, val any) A
}
)
var (
// compile time assertions
_ iJSONSupport[Event] = (*UnimplementedJSONSupport[Event, map[string]any, []any])(nil)
_ JSONSupport[Event, map[string]any, []any] = (*defaultJSONSupport[Event])(nil)
_ iJSONSupport[Event] = (*defaultJSONSupport[Event])(nil)
_ JSONSupport[Event, map[string]any, []any] = struct {
minimalJSONSupportMethods[Event, map[string]any, []any]
UnimplementedJSONSupport[Event, map[string]any, []any]
}{}
)
func TestUnimplementedJSONSupport_mustEmbedUnimplementedJSONSupport(t *testing.T) {
(UnimplementedJSONSupport[Event, map[string]any, []any]{}).mustEmbedUnimplementedJSONSupport()
}
func TestSliceJSONSupport_mustEmbedUnimplementedJSONSupport(t *testing.T) {
defaultJSONSupport[Event]{}.mustEmbedUnimplementedJSONSupport()
}
func TestUnimplementedJSONSupport_CanAppendArray(t *testing.T) {
if (UnimplementedJSONSupport[Event, map[string]any, []any]{}).CanAppendArray() {
t.Error("expected false")
}
}
func TestUnimplementedJSONSupport_AppendArray(t *testing.T) {
defer func() {
if v := fmt.Sprint(recover()); v != `unimplemented` {
t.Errorf("expected panic, got %q", v)
}
}()
(UnimplementedJSONSupport[Event, map[string]any, []any]{}).AppendArray(nil, nil)
t.Error("expected panic")
}