-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
447 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package encoding | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/shamaton/msgpack/v2/def" | ||
) | ||
|
||
func Test_writeByteSliceLength(t *testing.T) { | ||
method := func(e *encoder) func(int) error { | ||
return e.writeByteSliceLength | ||
} | ||
testcases := AsXXXTestCases[int]{ | ||
{ | ||
Name: "Bin8.error.def", | ||
Value: 5, | ||
BufferSize: 1, | ||
PreWriteSize: 1, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "Bin8.error.value", | ||
Value: 5, | ||
BufferSize: 2, | ||
PreWriteSize: 1, | ||
Contains: []byte{def.Bin8}, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "Bin8.ok", | ||
Value: 5, | ||
Expected: []byte{def.Bin8, 0x05}, | ||
BufferSize: 1, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "Bin16.error.def", | ||
Value: 256, | ||
BufferSize: 1, | ||
PreWriteSize: 1, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "Bin16.error.value", | ||
Value: 256, | ||
BufferSize: 3, | ||
PreWriteSize: 1, | ||
Contains: []byte{def.Bin16}, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "Bin16.ok", | ||
Value: 256, | ||
Expected: []byte{def.Bin16, 0x01, 0x00}, | ||
BufferSize: 1, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "Bin32.error.def", | ||
Value: 65536, | ||
BufferSize: 1, | ||
PreWriteSize: 1, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "Bin32.error.value", | ||
Value: 65536, | ||
BufferSize: 3, | ||
PreWriteSize: 1, | ||
Contains: []byte{def.Bin32}, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "Bin32.ok", | ||
Value: 65536, | ||
Expected: []byte{def.Bin32, 0x00, 0x01, 0x00, 0x00}, | ||
BufferSize: 1, | ||
Method: method, | ||
}, | ||
} | ||
testcases.Run(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package encoding | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/shamaton/msgpack/v2/def" | ||
) | ||
|
||
func Test_writeComplex64(t *testing.T) { | ||
method := func(e *encoder) func(complex64) error { | ||
return e.writeComplex64 | ||
} | ||
v := complex64(complex(1, 2)) | ||
testcases := AsXXXTestCases[complex64]{ | ||
{ | ||
Name: "error.def", | ||
Value: v, | ||
BufferSize: 1, | ||
PreWriteSize: 1, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "error.code", | ||
Value: v, | ||
BufferSize: 2, | ||
PreWriteSize: 1, | ||
Contains: []byte{def.Fixext8}, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "error.real", | ||
Value: v, | ||
BufferSize: 3, | ||
PreWriteSize: 1, | ||
Contains: []byte{def.Fixext8, byte(def.ComplexTypeCode())}, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "error.imag", | ||
Value: v, | ||
BufferSize: 7, | ||
PreWriteSize: 1, | ||
Contains: []byte{ | ||
def.Fixext8, byte(def.ComplexTypeCode()), | ||
0x3f, 0x80, 0x00, 0x00, | ||
}, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "ok", | ||
Value: v, | ||
Expected: []byte{ | ||
def.Fixext8, byte(def.ComplexTypeCode()), | ||
0x3f, 0x80, 0x00, 0x00, | ||
0x40, 0x00, 0x00, 0x00, | ||
}, | ||
BufferSize: 1, | ||
Method: method, | ||
}, | ||
} | ||
testcases.Run(t) | ||
} | ||
|
||
func Test_writeComplex128(t *testing.T) { | ||
method := func(e *encoder) func(complex128) error { | ||
return e.writeComplex128 | ||
} | ||
v := complex128(complex(1, 2)) | ||
testcases := AsXXXTestCases[complex128]{ | ||
{ | ||
Name: "error.def", | ||
Value: v, | ||
BufferSize: 1, | ||
PreWriteSize: 1, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "error.code", | ||
Value: v, | ||
BufferSize: 2, | ||
PreWriteSize: 1, | ||
Contains: []byte{def.Fixext16}, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "error.real", | ||
Value: v, | ||
BufferSize: 3, | ||
PreWriteSize: 1, | ||
Contains: []byte{def.Fixext16, byte(def.ComplexTypeCode())}, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "error.imag", | ||
Value: v, | ||
BufferSize: 11, | ||
PreWriteSize: 1, | ||
Contains: []byte{ | ||
def.Fixext16, byte(def.ComplexTypeCode()), | ||
0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
}, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "ok", | ||
Value: v, | ||
Expected: []byte{ | ||
def.Fixext16, byte(def.ComplexTypeCode()), | ||
0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
}, | ||
BufferSize: 1, | ||
Method: method, | ||
}, | ||
} | ||
testcases.Run(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package encoding | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/shamaton/msgpack/v2/def" | ||
) | ||
|
||
func Test_writeFloat32(t *testing.T) { | ||
method := func(e *encoder) func(float64) error { | ||
return e.writeFloat32 | ||
} | ||
v := 1.23 | ||
testcases := AsXXXTestCases[float64]{ | ||
{ | ||
Name: "error.def", | ||
Value: v, | ||
BufferSize: 1, | ||
PreWriteSize: 1, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "error.value", | ||
Value: v, | ||
BufferSize: 2, | ||
PreWriteSize: 1, | ||
Contains: []byte{def.Float32}, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "ok", | ||
Value: v, | ||
Expected: []byte{ | ||
def.Float32, | ||
0x3f, 0x9d, 0x70, 0xa4, | ||
}, | ||
BufferSize: 1, | ||
Method: method, | ||
}, | ||
} | ||
testcases.Run(t) | ||
} | ||
|
||
func Test_writeFloat64(t *testing.T) { | ||
method := func(e *encoder) func(float64) error { | ||
return e.writeFloat64 | ||
} | ||
v := 1.23 | ||
testcases := AsXXXTestCases[float64]{ | ||
{ | ||
Name: "error.def", | ||
Value: v, | ||
BufferSize: 1, | ||
PreWriteSize: 1, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "error.value", | ||
Value: v, | ||
BufferSize: 2, | ||
PreWriteSize: 1, | ||
Contains: []byte{def.Float64}, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "ok", | ||
Value: v, | ||
Expected: []byte{ | ||
def.Float64, | ||
0x3f, 0xf3, 0xae, 0x14, 0x7a, 0xe1, 0x47, 0xae, | ||
}, | ||
BufferSize: 1, | ||
Method: method, | ||
}, | ||
} | ||
testcases.Run(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package encoding | ||
|
||
import ( | ||
"math" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/shamaton/msgpack/v2/def" | ||
) | ||
|
||
func Test_writeString(t *testing.T) { | ||
method := func(e *encoder) func(string) error { | ||
return e.writeString | ||
} | ||
str8 := strings.Repeat("a", math.MaxUint8) | ||
testcases := AsXXXTestCases[string]{ | ||
{ | ||
Name: "Str8.error.def", | ||
Value: str8, | ||
BufferSize: 1, | ||
PreWriteSize: 1, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "Str8.error.length", | ||
Value: str8, | ||
BufferSize: 2, | ||
PreWriteSize: 1, | ||
Contains: []byte{def.Str8}, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "Str8.error.string", | ||
Value: str8, | ||
BufferSize: 3, | ||
PreWriteSize: 1, | ||
Contains: []byte{def.Str8, 0xff}, | ||
Method: method, | ||
}, | ||
{ | ||
Name: "Str8.ok", | ||
Value: str8, | ||
Expected: append( | ||
[]byte{def.Str8, 0xff}, | ||
[]byte(str8)..., | ||
), | ||
BufferSize: 1, | ||
Method: method, | ||
}, | ||
} | ||
testcases.Run(t) | ||
} |
Oops, something went wrong.