@@ -81,6 +81,92 @@ func TestStringify(t *testing.T) {
8181 }
8282}
8383
84+ func TestStringify_Primitives (t * testing.T ) {
85+ t .Parallel ()
86+ tests := []struct {
87+ in any
88+ out string
89+ }{
90+ // Bool
91+ {true , "true" },
92+ {false , "false" },
93+
94+ // Int variants
95+ {int (1 ), "1" },
96+ {int8 (2 ), "2" },
97+ {int16 (3 ), "3" },
98+ {int32 (4 ), "4" },
99+ {int64 (5 ), "5" },
100+
101+ // Uint variants
102+ {uint (6 ), "6" },
103+ {uint8 (7 ), "7" },
104+ {uint16 (8 ), "8" },
105+ {uint32 (9 ), "9" },
106+ {uint64 (10 ), "10" },
107+ {uintptr (11 ), "11" },
108+
109+ // Float variants (Precision Correctness)
110+ {float32 (1.1 ), "1.1" },
111+ {float64 (1.1 ), "1.1" },
112+ {float32 (1.0000001 ), "1.0000001" },
113+ {float64 (1.000000000000001 ), "1.000000000000001" },
114+
115+ // Boundary Cases
116+ {int8 (- 128 ), "-128" },
117+ {int8 (127 ), "127" },
118+ {uint64 (18446744073709551615 ), "18446744073709551615" },
119+
120+ // String Optimization
121+ {"hello" , `"hello"` },
122+ {"" , `""` },
123+ }
124+
125+ for i , tt := range tests {
126+ s := Stringify (tt .in )
127+ if s != tt .out {
128+ t .Errorf ("%v. Stringify(%T) => %q, want %q" , i , tt .in , s , tt .out )
129+ }
130+ }
131+ }
132+
133+ func TestStringify_BufferPool (t * testing.T ) {
134+ t .Parallel ()
135+ // Verify that concurrent usage of Stringify is safe and doesn't corrupt buffers.
136+ // While we can't easily verify reuse without exposing internal metrics,
137+ // we can verify correctness under load which implies proper Reset() handling.
138+ const goroutines = 10
139+ const iterations = 100
140+
141+ errCh := make (chan error , goroutines )
142+
143+ for range goroutines {
144+ go func () {
145+ for range iterations {
146+ // Use a mix of types to exercise different code paths
147+ s1 := Stringify (123 )
148+ if s1 != "123" {
149+ errCh <- fmt .Errorf ("got %q, want %q" , s1 , "123" )
150+ return
151+ }
152+
153+ s2 := Stringify ("test" )
154+ if s2 != `"test"` {
155+ errCh <- fmt .Errorf ("got %q, want %q" , s2 , `"test"` )
156+ return
157+ }
158+ }
159+ errCh <- nil
160+ }()
161+ }
162+
163+ for range goroutines {
164+ if err := <- errCh ; err != nil {
165+ t .Error (err )
166+ }
167+ }
168+ }
169+
84170// Directly test the String() methods on various GitHub types. We don't do an
85171// exhaustive test of all the various field types, since TestStringify() above
86172// takes care of that. Rather, we just make sure that Stringify() is being
@@ -143,3 +229,23 @@ func TestString(t *testing.T) {
143229 }
144230 }
145231}
232+
233+ func TestStringify_Floats (t * testing.T ) {
234+ t .Parallel ()
235+ tests := []struct {
236+ in any
237+ out string
238+ }{
239+ {float32 (1.1 ), "1.1" },
240+ {float64 (1.1 ), "1.1" },
241+ {float32 (1.0000001 ), "1.0000001" },
242+ {struct { F float32 }{1.1 }, "{F:1.1}" },
243+ }
244+
245+ for i , tt := range tests {
246+ s := Stringify (tt .in )
247+ if s != tt .out {
248+ t .Errorf ("%v. Stringify(%v) = %q, want %q" , i , tt .in , s , tt .out )
249+ }
250+ }
251+ }
0 commit comments