Skip to content

Commit

Permalink
fix testcase logic in stream decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
shamaton committed Aug 26, 2024
1 parent ea02dc3 commit 69ee43d
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 165 deletions.
2 changes: 1 addition & 1 deletion internal/decoding/decoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,5 +339,5 @@ func (d *decoder) decode(rv reflect.Value, offset int) (int, error) {
}

func (d *decoder) errorTemplate(code byte, k reflect.Kind) error {
return fmt.Errorf("msgpack : invalid code %x decoding %v, %w", code, k, def.ErrCanNotDecode)
return fmt.Errorf("%w %x decoding as %v", def.ErrCanNotDecode, code, k)
}
2 changes: 1 addition & 1 deletion internal/stream/decoding/bin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func Test_asBinWithCode(t *testing.T) {
{
Name: "Unexpected",
Code: def.Nil,
IsTemplateError: true,
Error: def.ErrCanNotDecode,
MethodAsWithCode: method,
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/stream/decoding/bool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func Test_asBoolWithCode(t *testing.T) {
{
Name: "Unexpected",
Code: def.Nil,
IsTemplateError: true,
Error: def.ErrCanNotDecode,
MethodAsWithCode: method,
},
}
Expand Down
4 changes: 2 additions & 2 deletions internal/stream/decoding/complex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func Test_asComplex64(t *testing.T) {
{
Name: "Unexpected",
Code: def.Nil,
IsTemplateError: true,
Error: def.ErrCanNotDecode,
MethodAsWithCode: method,
},
}
Expand Down Expand Up @@ -155,7 +155,7 @@ func Test_asComplex128(t *testing.T) {
{
Name: "Unexpected",
Code: def.Nil,
IsTemplateError: true,
Error: def.ErrCanNotDecode,
MethodAsWithCode: method,
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/stream/decoding/decoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,5 +320,5 @@ func (d *decoder) decodeWithCode(code byte, rv reflect.Value) error {
}

func (d *decoder) errorTemplate(code byte, k reflect.Kind) error {
return fmt.Errorf("msgpack : invalid code %x decoding %v, %w", code, k, def.ErrCanNotDecode)
return fmt.Errorf("%w %x decoding as %v", def.ErrCanNotDecode, code, k)
}
6 changes: 0 additions & 6 deletions internal/stream/decoding/decoding_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package decoding

import (
"fmt"
"io"
"reflect"
"testing"
Expand All @@ -19,7 +18,6 @@ type AsXXXTestCase[T any] struct {
ReadCount int
Expected T
Error error
IsTemplateError bool
MethodAs func(d *decoder) func(reflect.Kind) (T, error)
MethodAsWithCode func(d *decoder) func(byte, reflect.Kind) (T, error)
MethodAsCustom func(d *decoder) (T, error)
Expand Down Expand Up @@ -69,10 +67,6 @@ func (tc *AsXXXTestCase[T]) Run(t *testing.T) {
tu.IsError(t, err, tc.Error)
return
}
if tc.IsTemplateError {
tu.ErrorContains(t, err, fmt.Sprintf("msgpack : invalid code %x", tc.Code))
return
}
tu.NoError(t, err)
tu.Equal(t, v, tc.Expected)

Expand Down
2 changes: 0 additions & 2 deletions internal/stream/decoding/ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import (
"testing"

"github.com/shamaton/msgpack/v2/def"

"github.com/shamaton/msgpack/v2/internal/common"

tu "github.com/shamaton/msgpack/v2/internal/common/testutil"
"github.com/shamaton/msgpack/v2/time"
)
Expand Down
7 changes: 4 additions & 3 deletions internal/stream/decoding/float_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package decoding

import (
"github.com/shamaton/msgpack/v2/def"
"io"
"reflect"
"testing"

"github.com/shamaton/msgpack/v2/def"
)

func Test_asFloat32(t *testing.T) {
Expand Down Expand Up @@ -88,7 +89,7 @@ func Test_asFloat32WithCode(t *testing.T) {
{
Name: "Unexpected",
Code: def.Str8,
IsTemplateError: true,
Error: def.ErrCanNotDecode,
MethodAsWithCode: method,
},
}
Expand Down Expand Up @@ -193,7 +194,7 @@ func Test_asFloat64WithCode(t *testing.T) {
{
Name: "Unexpected",
Code: def.Str8,
IsTemplateError: true,
Error: def.ErrCanNotDecode,
MethodAsWithCode: method,
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/stream/decoding/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func Test_asInterfaceWithCode(t *testing.T) {
Code: def.Fixext1,
Data: []byte{4, 0},
ReadCount: 2,
IsTemplateError: true,
Error: def.ErrCanNotDecode,
MethodAsWithCode: method,
},
}
Expand Down
Loading

0 comments on commit 69ee43d

Please sign in to comment.