-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjsonry_suite_test.go
More file actions
65 lines (52 loc) · 1.08 KB
/
Copy pathjsonry_suite_test.go
File metadata and controls
65 lines (52 loc) · 1.08 KB
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
package jsonry_test
import (
"bytes"
"encoding/json"
"errors"
"testing"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
type implementsJSONMarshaler struct {
bytes []byte
err error
}
func (i implementsJSONMarshaler) MarshalJSON() ([]byte, error) {
return i.bytes, i.err
}
type implementsJSONUnmarshaler struct {
hasBeenSet bool
}
func (i *implementsJSONUnmarshaler) UnmarshalJSON(input []byte) error {
if bytes.Equal(input, []byte(`"fail"`)) {
return errors.New("ouch")
}
i.hasBeenSet = true
return nil
}
type implementsOmissible string
func (i implementsOmissible) OmitJSONry() bool {
return i == "omit"
}
type nullString struct {
value string
null bool
}
func (n nullString) MarshalJSON() ([]byte, error) {
if n.null {
return []byte("null"), nil
}
return json.Marshal(n.value)
}
func (n *nullString) UnmarshalJSON(input []byte) error {
if bytes.Equal(input, []byte("null")) {
n.null = true
return nil
}
n.null = false
return json.Unmarshal(input, &n.value)
}
func TestJSONry(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "JSONry Suite")
}