mirror of
https://github.com/ManyakRus/starter.git
synced 2025-11-26 23:10:42 +02:00
сделал StructDeepCopy()
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/ManyakRus/starter/contextmain"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -598,3 +599,38 @@ func TestStringFloat32_Dimension2(t *testing.T) {
|
||||
func TestShowTimePassed(t *testing.T) {
|
||||
defer ShowTimePassed(time.Now())
|
||||
}
|
||||
|
||||
func TestStructDeepCopy(t *testing.T) {
|
||||
type NestedStruct struct {
|
||||
Number int
|
||||
Text string
|
||||
}
|
||||
|
||||
type TestStruct struct {
|
||||
ID int
|
||||
Name string
|
||||
Nested NestedStruct
|
||||
Numbers []int
|
||||
}
|
||||
|
||||
src := TestStruct{
|
||||
ID: 1,
|
||||
Name: "Test",
|
||||
Nested: NestedStruct{
|
||||
Number: 100,
|
||||
Text: "Nested",
|
||||
},
|
||||
Numbers: []int{1, 2, 3},
|
||||
}
|
||||
|
||||
var dist TestStruct
|
||||
|
||||
err := StructDeepCopy(src, &dist)
|
||||
if err != nil {
|
||||
t.Fatalf("error copying struct: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(src, dist) {
|
||||
t.Errorf("copied struct does not match original struct")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user