Former-commit-id: 7c77e2f08fdcb7a48a6aa92364ba3b8e431d8d69
This commit is contained in:
Gerasimos (Makis) Maropoulos 2019-11-20 14:39:45 +02:00
parent 256cda05fa
commit cad90a2753
2 changed files with 51 additions and 0 deletions

View File

@ -173,6 +173,7 @@ func (e Entry) IntDefault(def int) (int, error) {
return int(vv), nil
case int64:
return int(vv), nil
case uint:
return int(vv), nil
case uint8:
@ -213,6 +214,17 @@ func (e Entry) Int8Default(def int8) (int8, error) {
return int8(vv), nil
case int64:
return int8(vv), nil
case uint:
return int8(vv), nil
case uint8:
return int8(vv), nil
case uint16:
return int8(vv), nil
case uint32:
return int8(vv), nil
case uint64:
return int8(vv), nil
}
return def, e.notFound(reflect.Int8)
@ -243,6 +255,17 @@ func (e Entry) Int16Default(def int16) (int16, error) {
return int16(vv), nil
case int64:
return int16(vv), nil
case uint:
return int16(vv), nil
case uint8:
return int16(vv), nil
case uint16:
return int16(vv), nil
case uint32:
return int16(vv), nil
case uint64:
return int16(vv), nil
}
return def, e.notFound(reflect.Int16)
@ -297,6 +320,17 @@ func (e Entry) Int64Default(def int64) (int64, error) {
return int64(vv), nil
case int:
return int64(vv), nil
case uint:
return int64(vv), nil
case uint8:
return int64(vv), nil
case uint16:
return int64(vv), nil
case uint32:
return int64(vv), nil
case uint64:
return int64(vv), nil
}
return def, e.notFound(reflect.Int64)
@ -344,6 +378,14 @@ func (e Entry) UintDefault(def uint) (uint, error) {
return def, e.notFound(reflect.Uint)
}
return uint(vv), nil
case int8:
return uint(vv), nil
case int16:
return uint(vv), nil
case int32:
return uint(vv), nil
case int64:
return uint(vv), nil
}
return def, e.notFound(reflect.Uint)

View File

@ -110,3 +110,12 @@ func TestImmutableSetOnlyWithSetImmutable(t *testing.T) {
t.Fatalf("caller should be able to change the immutable entry with a `SetImmutable`")
}
}
func TestGetInt64Default(t *testing.T) {
var p Store
p.Set("a uint16", uint16(2))
if v := p.GetInt64Default("a uint16", 0); v != 2 {
t.Fatalf("unexpected value of %d", v)
}
}