mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-11 18:20:33 +09:00
GO-4079 Review IsEmptyValue
This commit is contained in:
parent
e31075a7d7
commit
f7caa5f5e5
2 changed files with 8 additions and 11 deletions
|
@ -131,8 +131,9 @@ func IsEmptyValueOrAbsent(s *types.Struct, name string) bool {
|
|||
return IsEmptyValue(value)
|
||||
}
|
||||
|
||||
// IsEmptyValue returns true for nil, null value, unknown kind of value, empty strings and empty lists
|
||||
func IsEmptyValue(value *types.Value) bool {
|
||||
if value == nil {
|
||||
if IsNullValue(value) {
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -140,22 +141,18 @@ func IsEmptyValue(value *types.Value) bool {
|
|||
return len(v.StringValue) == 0
|
||||
}
|
||||
|
||||
if v, ok := value.Kind.(*types.Value_NumberValue); ok {
|
||||
return v.NumberValue == 0
|
||||
if _, ok := value.Kind.(*types.Value_NumberValue); ok {
|
||||
return false
|
||||
}
|
||||
|
||||
if v, ok := value.Kind.(*types.Value_BoolValue); ok {
|
||||
return !v.BoolValue
|
||||
if _, ok := value.Kind.(*types.Value_BoolValue); ok {
|
||||
return false
|
||||
}
|
||||
|
||||
if _, ok := value.Kind.(*types.Value_ListValue); ok {
|
||||
return len(GetStringListValue(value)) == 0
|
||||
}
|
||||
|
||||
if _, ok := value.Kind.(*types.Value_NullValue); ok {
|
||||
return true
|
||||
}
|
||||
|
||||
if _, ok := value.Kind.(*types.Value_StructValue); ok {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -163,9 +163,9 @@ func TestIsEmptyValueOrAbsent(t *testing.T) {
|
|||
{"AbsentField", data, "nonExistentField", true},
|
||||
{"EmptyStringValue", data, "emptyStringValue", true},
|
||||
{"NonEmptyStringValue", data, "stringValue", false},
|
||||
{"ZeroNumberValue", data, "emptyNumberValue", true},
|
||||
{"ZeroNumberValue", data, "emptyNumberValue", false},
|
||||
{"NonZeroNumberValue", data, "numberValue", false},
|
||||
{"FalseBoolValue", data, "emptyBoolValue", true},
|
||||
{"FalseBoolValue", data, "emptyBoolValue", false},
|
||||
{"TrueBoolValue", data, "boolValue", false},
|
||||
{"EmptyListValue", data, "emptyListValue", true},
|
||||
{"NullValue", data, "nullValue", true},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue