diff --git a/micro/microfunctions.go b/micro/microfunctions.go index 62bccd6c..6ed3d52c 100644 --- a/micro/microfunctions.go +++ b/micro/microfunctions.go @@ -946,3 +946,18 @@ func IsNilInterface(i any) bool { return false } } + +// StringFromMassInt64 - преобразование массива int64 в строку +func StringFromMassInt64(A []int64, delim string) string { + + var buffer bytes.Buffer + for i := 0; i < len(A); i++ { + s1 := StringFromInt64(A[i]) + buffer.WriteString(s1) + if i != len(A)-1 { + buffer.WriteString(delim) + } + } + + return buffer.String() +} diff --git a/micro/microfunctions_test.go b/micro/microfunctions_test.go index 6f675a19..aef321d8 100644 --- a/micro/microfunctions_test.go +++ b/micro/microfunctions_test.go @@ -829,3 +829,27 @@ func TestIsNilInterface(t *testing.T) { t.Error("Expected true for nil interface") } } + +func TestStringFromMassInt64(t *testing.T) { + // Test with an empty array + emptyArray := []int64{} + emptyResult := StringFromMassInt64(emptyArray, ",") + if emptyResult != "" { + t.Errorf("Expected empty string, but got: %s", emptyResult) + } + + // Test with an array of single element + singleArray := []int64{42} + singleResult := StringFromMassInt64(singleArray, ",") + if singleResult != "42" { + t.Errorf("Expected '42', but got: %s", singleResult) + } + + // Test with an array of multiple elements + multipleArray := []int64{1, 2, 3} + multipleResult := StringFromMassInt64(multipleArray, "-") + expectedResult := "1-2-3" + if multipleResult != expectedResult { + t.Errorf("Expected '%s', but got: %s", expectedResult, multipleResult) + } +}