Skip to content

Commit

Permalink
Add coverage for uint changes
Browse files Browse the repository at this point in the history
  • Loading branch information
morris-kelly committed Jul 12, 2024
1 parent b4e7840 commit e9430c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
11 changes: 11 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e9430c0

Please sign in to comment.