mirror of
https://github.com/ManyakRus/starter.git
synced 2025-11-26 23:10:42 +02:00
сделал IsEmptyValue()
This commit is contained in:
@@ -841,3 +841,10 @@ func StructDeepCopy(src, dist interface{}) (err error) {
|
||||
}
|
||||
return gob.NewDecoder(&buf).Decode(dist)
|
||||
}
|
||||
|
||||
// IsEmptyValue - возвращает true если значение по умолчанию (0, пустая строка, пустой слайс)
|
||||
func IsEmptyValue(v any) bool {
|
||||
rv := reflect.ValueOf(v)
|
||||
Otvet := !rv.IsValid() || reflect.DeepEqual(rv.Interface(), reflect.Zero(rv.Type()).Interface())
|
||||
return Otvet
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/ManyakRus/starter/contextmain"
|
||||
"github.com/google/uuid"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
@@ -634,3 +635,21 @@ func TestStructDeepCopy(t *testing.T) {
|
||||
t.Errorf("copied struct does not match original struct")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsEmptyValue(t *testing.T) {
|
||||
// Testing for integer zero value
|
||||
if !IsEmptyValue(0) {
|
||||
t.Error("Expected true for integer zero value")
|
||||
}
|
||||
|
||||
// Testing for empty string value
|
||||
if !IsEmptyValue("") {
|
||||
t.Error("Expected true for empty string value")
|
||||
}
|
||||
|
||||
// Testing for empty uuid value
|
||||
uuid1 := uuid.Nil
|
||||
if !IsEmptyValue(uuid1) {
|
||||
t.Error("Expected true for empty uuid value")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user