MCPcopy Create free account
hub / github.com/francoispqt/gojay / TestEncoderNumberEncodeAPIErrors

Function TestEncoderNumberEncodeAPIErrors

encode_number_test.go:72–170  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

70}
71
72func TestEncoderNumberEncodeAPIErrors(t *testing.T) {
73 t.Run("encode-int-pool-error", func(t *testing.T) {
74 builder := &strings.Builder{}
75 enc := NewEncoder(builder)
76 enc.isPooled = 1
77 defer func() {
78 err := recover()
79 assert.NotNil(t, err, "err should not be nil")
80 assert.IsType(t, InvalidUsagePooledEncoderError(""), err, "err should be of type InvalidUsagePooledEncoderError")
81 }()
82 _ = enc.EncodeInt(1)
83 assert.True(t, false, "should not be called as encoder should have panicked")
84 })
85 t.Run("encode-int-write-error", func(t *testing.T) {
86 w := TestWriterError("")
87 enc := NewEncoder(w)
88 err := enc.EncodeInt(1)
89 assert.NotNil(t, err, "err should not be nil")
90 assert.Equal(t, "Test Error", err.Error(), "err should be of type InvalidUsagePooledEncoderError")
91 })
92 t.Run("encode-int64-pool-error", func(t *testing.T) {
93 builder := &strings.Builder{}
94 enc := NewEncoder(builder)
95 enc.isPooled = 1
96 defer func() {
97 err := recover()
98 assert.NotNil(t, err, "err should not be nil")
99 assert.IsType(t, InvalidUsagePooledEncoderError(""), err, "err should be of type InvalidUsagePooledEncoderError")
100 }()
101 _ = enc.EncodeInt64(1)
102 assert.True(t, false, "should not be called as encoder should have panicked")
103 })
104 t.Run("encode-int64-write-error", func(t *testing.T) {
105 w := TestWriterError("")
106 enc := NewEncoder(w)
107 err := enc.EncodeInt64(1)
108 assert.NotNil(t, err, "err should not be nil")
109 assert.Equal(t, "Test Error", err.Error(), "err should be of type InvalidUsagePooledEncoderError")
110
111 })
112 t.Run("encode-uint64-pool-error", func(t *testing.T) {
113 builder := &strings.Builder{}
114 enc := NewEncoder(builder)
115 enc.isPooled = 1
116 defer func() {
117 err := recover()
118 assert.NotNil(t, err, "err should not be nil")
119 assert.IsType(t, InvalidUsagePooledEncoderError(""), err, "err should be of type InvalidUsagePooledEncoderError")
120 }()
121 _ = enc.EncodeUint64(1)
122 assert.True(t, false, "should not be called as encoder should have panicked")
123 })
124 t.Run("encode-unt64-write-error", func(t *testing.T) {
125 w := TestWriterError("")
126 enc := NewEncoder(w)
127 err := enc.EncodeUint64(1)
128 assert.NotNil(t, err, "err should not be nil")
129 assert.Equal(t, "Test Error", err.Error(), "err should be of type InvalidUsagePooledEncoderError")

Callers

nothing calls this directly

Calls 9

EncodeIntMethod · 0.95
EncodeInt64Method · 0.95
EncodeUint64Method · 0.95
EncodeFloatMethod · 0.95
EncodeFloat32Method · 0.95
NewEncoderFunction · 0.85
TestWriterErrorTypeAlias · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…