MCPcopy Create free account
hub / github.com/dromara/dongle / TestDecoder_ToBytes

Function TestDecoder_ToBytes

coding/decoder_test.go:151–197  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

149}
150
151func TestDecoder_ToBytes(t *testing.T) {
152 t.Run("to bytes with data", func(t *testing.T) {
153 decoder := NewDecoder()
154 decoder.dst = []byte("hello world")
155 result := decoder.ToBytes()
156 assert.Equal(t, []byte("hello world"), result)
157 })
158
159 t.Run("to bytes with empty data", func(t *testing.T) {
160 decoder := NewDecoder()
161 decoder.dst = []byte{}
162 result := decoder.ToBytes()
163 assert.Equal(t, []byte(""), result)
164 })
165
166 t.Run("to bytes with nil data", func(t *testing.T) {
167 decoder := NewDecoder()
168 decoder.dst = nil
169 result := decoder.ToBytes()
170 assert.Equal(t, []byte(""), result)
171 })
172
173 t.Run("to bytes with unicode data", func(t *testing.T) {
174 decoder := NewDecoder()
175 decoder.dst = []byte("你好世界")
176 result := decoder.ToBytes()
177 assert.Equal(t, []byte("你好世界"), result)
178 })
179
180 t.Run("to bytes with binary data", func(t *testing.T) {
181 decoder := NewDecoder()
182 decoder.dst = []byte{0x00, 0x01, 0x02, 0x03}
183 result := decoder.ToBytes()
184 assert.Equal(t, []byte{0x00, 0x01, 0x02, 0x03}, result)
185 })
186
187 t.Run("to bytes with large data", func(t *testing.T) {
188 largeData := make([]byte, 1000)
189 for i := range largeData {
190 largeData[i] = byte(i % 256)
191 }
192 decoder := NewDecoder()
193 decoder.dst = largeData
194 result := decoder.ToBytes()
195 assert.Equal(t, largeData, result)
196 })
197}
198
199func TestDecoder_stream(t *testing.T) {
200 t.Run("success with data", func(t *testing.T) {

Callers

nothing calls this directly

Calls 2

ToBytesMethod · 0.95
NewDecoderFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…