@@ -27,6 +27,80 @@ import (
2727	"github.com/stretchr/testify/require" 
2828)
2929
30+ func  Test_anyToString (t  * testing.T ) {
31+ 	testCases  :=  []struct  {
32+ 		name              string 
33+ 		thingToSerialize  interface {}
34+ 		expected          string 
35+ 	}{
36+ 		{
37+ 			name :             "nil" ,
38+ 			thingToSerialize : nil ,
39+ 			expected :         "<nil>" ,
40+ 		},
41+ 		{
42+ 			name :             "int" ,
43+ 			thingToSerialize : 1 ,
44+ 			expected :         "1" ,
45+ 		},
46+ 		{
47+ 			name :             "string" ,
48+ 			thingToSerialize : "test" ,
49+ 			expected :         "test" ,
50+ 		},
51+ 		{
52+ 			name : "struct" ,
53+ 			thingToSerialize : struct  {
54+ 				A  string 
55+ 				B  int 
56+ 				C  bool 
57+ 			}{A : "test" , B : 1 , C : true },
58+ 			expected : "(A:test, B:1, C:true)" ,
59+ 		},
60+ 		{
61+ 			name : "pointer" ,
62+ 			thingToSerialize : & struct  {
63+ 				A  string 
64+ 				B  int 
65+ 				C  bool 
66+ 			}{A : "test" , B : 1 , C : true },
67+ 			expected : "(A:test, B:1, C:true)" ,
68+ 		},
69+ 		{
70+ 			name :             "slice" ,
71+ 			thingToSerialize : []int {1 , 2 , 3 },
72+ 			expected :         "[1 2 3]" ,
73+ 		},
74+ 		{
75+ 			name :             "struct with slice" ,
76+ 			thingToSerialize : struct { A  []int  }{A : []int {1 , 2 , 3 }},
77+ 			expected :         "(A:[len=3])" ,
78+ 		},
79+ 		{
80+ 			name :             "struct with blob" ,
81+ 			thingToSerialize : struct { A  []byte  }{A : []byte ("blob-data" )},
82+ 			expected :         "(A:[blob-data])" ,
83+ 		},
84+ 		{
85+ 			name :             "struct with struct" ,
86+ 			thingToSerialize : struct { A  struct { B  int  } }{A : struct { B  int  }{B : 1 }},
87+ 			expected :         "(A:(B:1))" ,
88+ 		},
89+ 		{
90+ 			name :             "struct with pointer" ,
91+ 			thingToSerialize : struct { A  * int  }{A : new (int )},
92+ 			expected :         "(A:0)" ,
93+ 		},
94+ 	}
95+ 
96+ 	for  _ , tc  :=  range  testCases  {
97+ 		t .Run (tc .name , func (t  * testing.T ) {
98+ 			actual  :=  anyToString (tc .thingToSerialize )
99+ 			require .Equal (t , tc .expected , actual )
100+ 		})
101+ 	}
102+ }
103+ 
30104func  Test_byteSliceToString (t  * testing.T ) {
31105	data  :=  []byte ("blob-data" )
32106	v  :=  reflect .ValueOf (data )
0 commit comments