From e9430c0b3714c7d5b103c79b1436cbb9044616a7 Mon Sep 17 00:00:00 2001 From: Morris Kelly Date: Fri, 12 Jul 2024 09:59:04 +0100 Subject: [PATCH] Add coverage for uint changes --- decode.go | 5 +++-- decode_test.go | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/decode.go b/decode.go index c194da6c..72af5e22 100644 --- a/decode.go +++ b/decode.go @@ -928,10 +928,11 @@ func (d *Decoder) decodeValue(ctx context.Context, dst reflect.Value, src ast.No if 0 <= i && i <= math.MaxUint64 && !dst.OverflowUint(uint64(i)) { dst.SetUint(uint64(i)) return nil - } else { // couldn't be parsed as float - return errTypeMismatch(valueType, reflect.TypeOf(v), src.GetToken()) } + } else { // couldn't be parsed as float + return errTypeMismatch(valueType, reflect.TypeOf(v), src.GetToken()) } + default: return errTypeMismatch(valueType, reflect.TypeOf(v), src.GetToken()) } diff --git a/decode_test.go b/decode_test.go index a76be944..f0b0c080 100644 --- a/decode_test.go +++ b/decode_test.go @@ -1198,6 +1198,17 @@ func TestDecoder_TypeConversionError(t *testing.T) { t.Fatalf("expected error message: %s to contain: %s", err.Error(), msg) } }) + t.Run("string to uint", func(t *testing.T) { + var v T + err := yaml.Unmarshal([]byte(`b: str`), &v) + if err == nil { + t.Fatal("expected to error") + } + msg := "cannot unmarshal string into Go struct field T.B of type uint" + if !strings.Contains(err.Error(), msg) { + t.Fatalf("expected error message: %s to contain: %s", err.Error(), msg) + } + }) t.Run("string to bool", func(t *testing.T) { var v T err := yaml.Unmarshal([]byte(`d: str`), &v)