1
0
Fork 0
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:
kirillston 2024-12-09 22:52:25 +01:00
parent e31075a7d7
commit f7caa5f5e5
No known key found for this signature in database
GPG key ID: BE4BF014F0ECDFE8
2 changed files with 8 additions and 11 deletions

View file

@ -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
}

View file

@ -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},