Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shamaton committed Aug 7, 2024
1 parent 3f12965 commit ed51f6b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 9 deletions.
9 changes: 8 additions & 1 deletion internal/stream/decoding/bool_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package decoding

import (
"io"
"reflect"
"testing"

Expand All @@ -13,7 +14,13 @@ func Test_asBool(t *testing.T) {
}
testcases := AsXXXTestCases[bool]{
{
Name: "Bool",
Name: "error",
ReadCount: 0,
Error: io.EOF,
MethodAs: method,
},
{
Name: "ok",
Data: []byte{def.True},
Expected: true,
ReadCount: 1,
Expand Down
2 changes: 1 addition & 1 deletion internal/stream/decoding/int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func Test_asInt(t *testing.T) {
testcases := AsXXXTestCases[int64]{
{
Name: "error",
Data: []byte{def.Int8},
Data: []byte{},
Error: io.EOF,
ReadCount: 1,
MethodAs: method,
Expand Down
21 changes: 19 additions & 2 deletions internal/stream/decoding/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package decoding
import (
"bytes"
"fmt"
"io"
"math"
"reflect"
"testing"
Expand All @@ -25,15 +26,31 @@ func Test_mapLength(t *testing.T) {
MethodAsWithCode: method,
},
{
Name: "Map16",
Name: "Map16.error",
Code: def.Map16,
Data: []byte{},
ReadCount: 0,
Error: io.EOF,
MethodAsWithCode: method,
},
{
Name: "Map16.ok",
Code: def.Map16,
Data: []byte{0xff, 0xff},
Expected: math.MaxUint16,
ReadCount: 1,
MethodAsWithCode: method,
},
{
Name: "Map32",
Name: "Map32.error",
Code: def.Map32,
Data: []byte{},
ReadCount: 0,
Error: io.EOF,
MethodAsWithCode: method,
},
{
Name: "Map32.ok",
Code: def.Map32,
Data: []byte{0xff, 0xff, 0xff, 0xff},
Expected: math.MaxUint32,
Expand Down
47 changes: 42 additions & 5 deletions internal/stream/decoding/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,47 @@ func Test_stringByteLength(t *testing.T) {
MethodAsWithCode: method,
},
{
Name: "Str8",
Name: "Str8.error",
Code: def.Str8,
Data: []byte{},
Error: io.EOF,
ReadCount: 0,
MethodAsWithCode: method,
},
{
Name: "Str8.ok",
Code: def.Str8,
Data: []byte{0xff},
Expected: math.MaxUint8,
ReadCount: 1,
MethodAsWithCode: method,
},
{
Name: "Str16",
Name: "Str16.error",
Code: def.Str16,
Data: []byte{},
Error: io.EOF,
ReadCount: 0,
MethodAsWithCode: method,
},
{
Name: "Str16.ok",
Code: def.Str16,
Data: []byte{0xff, 0xff},
Expected: math.MaxUint16,
ReadCount: 1,
MethodAsWithCode: method,
},
{
Name: "Str32",
Name: "Str32.error",
Code: def.Str32,
Data: []byte{},
Error: io.EOF,
ReadCount: 0,
MethodAsWithCode: method,
},
{
Name: "Str32.ok",
Code: def.Str32,
Data: []byte{0xff, 0xff, 0xff, 0xff},
Expected: math.MaxUint32,
Expand All @@ -50,6 +74,12 @@ func Test_stringByteLength(t *testing.T) {
Expected: 0,
MethodAsWithCode: method,
},
{
Name: "Unexpected",
Code: def.Array16,
Error: ErrCanNotDecode,
MethodAsWithCode: method,
},
}

for _, tc := range testcases {
Expand All @@ -63,14 +93,21 @@ func Test_asString(t *testing.T) {
}
testcases := AsXXXTestCases[string]{
{
Name: "String.error",
Name: "error.code",
Data: []byte{},
Error: io.EOF,
ReadCount: 0,
MethodAs: method,
},
{
Name: "error.string",
Data: []byte{def.FixStr + 1},
Error: io.EOF,
ReadCount: 1,
MethodAs: method,
},
{
Name: "String.ok",
Name: "ok",
Data: []byte{def.FixStr + 1, 'a'},
Expected: "a",
ReadCount: 2,
Expand Down

0 comments on commit ed51f6b

Please sign in to comment.