Commit f0ac879
Alejandro Mery
feat(core): add same-ness testing functions and modernise test patterns
Adds same-ness testing utilities that distinguish between value equality
and reference equality for different Go types, alongside comprehensive
refactoring of existing test suites to use modern assertion patterns.
For value types (numbers, strings, booleans), same-ness means equal
values. For reference types (slices, maps, pointers, channels,
functions), same-ness means pointer equality to the same underlying
data structure.
New functions:
- IsSame() base function with comprehensive type handling.
- AssertSame() and AssertNotSame() testing assertions.
- asReflectValue() helper to avoid duplicate reflect.ValueOf() calls.
- isReflectValueSame() helper following established naming patterns.
Key features:
- Proper nil handling: typed nils of same type are considered same.
- Interface support with recursive comparison of contained values.
- Complexity-compliant implementation using helper functions.
- Interface comparison inlined directly into isSamePointer() for efficiency.
Test modernisation:
- Refactored as_test.go to use AssertEqual for length checks.
- Modernised compounderror_test.go with AssertSame, AssertEqual, AssertNotNil.
- Updated errgroup_test.go to use AssertSame for error instance checks.
- Improved lists_test.go with AssertNotSame for independence verification.
- Applied fatal assertion pattern consistently for critical preconditions.
Documentation updates:
- Added same-ness function documentation to README.md.
- Extended TESTING.md with assertion usage examples.
- Updated function documentation to match final implementation.
Includes comprehensive test suite with 263 lines of test code covering
all scenarios: value types, reference types, nil handling, different
types, interface wrapping, and reflect.Value handling.
Coverage increased to 97.0% with full linting compliance.
Signed-off-by: Alejandro Mery <amery@apply.co>1 parent b3ec005 commit f0ac879
File tree
10 files changed
+656
-91
lines changed10 files changed
+656
-91
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
127 | 134 | | |
128 | 135 | | |
129 | 136 | | |
| |||
466 | 473 | | |
467 | 474 | | |
468 | 475 | | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
469 | 480 | | |
470 | 481 | | |
471 | 482 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
92 | 94 | | |
93 | 95 | | |
94 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
166 | | - | |
| 165 | + | |
| 166 | + | |
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
201 | | - | |
202 | | - | |
| 201 | + | |
| 202 | + | |
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
| |||
299 | 299 | | |
300 | 300 | | |
301 | 301 | | |
302 | | - | |
303 | | - | |
| 302 | + | |
| 303 | + | |
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
| 59 | + | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
78 | | - | |
| 77 | + | |
| 78 | + | |
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
83 | | - | |
| 82 | + | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
98 | | - | |
| 97 | + | |
| 98 | + | |
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
103 | | - | |
| 102 | + | |
| 103 | + | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
194 | | - | |
195 | | - | |
| 194 | + | |
| 195 | + | |
196 | 196 | | |
197 | 197 | | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
| 198 | + | |
| 199 | + | |
203 | 200 | | |
| 201 | + | |
204 | 202 | | |
205 | 203 | | |
206 | 204 | | |
| |||
245 | 243 | | |
246 | 244 | | |
247 | 245 | | |
248 | | - | |
249 | | - | |
| 246 | + | |
| 247 | + | |
250 | 248 | | |
251 | 249 | | |
252 | 250 | | |
253 | | - | |
254 | | - | |
| 251 | + | |
| 252 | + | |
255 | 253 | | |
256 | 254 | | |
257 | 255 | | |
258 | 256 | | |
259 | | - | |
260 | | - | |
| 257 | + | |
| 258 | + | |
261 | 259 | | |
262 | 260 | | |
263 | 261 | | |
| |||
273 | 271 | | |
274 | 272 | | |
275 | 273 | | |
276 | | - | |
277 | | - | |
| 274 | + | |
| 275 | + | |
278 | 276 | | |
279 | 277 | | |
280 | 278 | | |
281 | 279 | | |
282 | | - | |
283 | | - | |
| 280 | + | |
| 281 | + | |
284 | 282 | | |
285 | 283 | | |
286 | 284 | | |
287 | 285 | | |
288 | | - | |
289 | | - | |
| 286 | + | |
| 287 | + | |
290 | 288 | | |
291 | | - | |
292 | | - | |
| 289 | + | |
| 290 | + | |
293 | 291 | | |
294 | | - | |
295 | | - | |
| 292 | + | |
| 293 | + | |
296 | 294 | | |
297 | 295 | | |
298 | 296 | | |
| |||
317 | 315 | | |
318 | 316 | | |
319 | 317 | | |
320 | | - | |
321 | | - | |
| 318 | + | |
| 319 | + | |
322 | 320 | | |
323 | 321 | | |
324 | 322 | | |
325 | 323 | | |
326 | | - | |
327 | | - | |
| 324 | + | |
| 325 | + | |
328 | 326 | | |
329 | 327 | | |
330 | 328 | | |
| |||
375 | 373 | | |
376 | 374 | | |
377 | 375 | | |
378 | | - | |
379 | | - | |
380 | | - | |
| 376 | + | |
381 | 377 | | |
382 | 378 | | |
383 | | - | |
384 | | - | |
| 379 | + | |
| 380 | + | |
385 | 381 | | |
386 | 382 | | |
387 | 383 | | |
388 | 384 | | |
389 | | - | |
390 | | - | |
| 385 | + | |
| 386 | + | |
391 | 387 | | |
392 | 388 | | |
393 | 389 | | |
| |||
397 | 393 | | |
398 | 394 | | |
399 | 395 | | |
400 | | - | |
401 | | - | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
402 | 400 | | |
403 | 401 | | |
404 | 402 | | |
| |||
419 | 417 | | |
420 | 418 | | |
421 | 419 | | |
422 | | - | |
423 | | - | |
| 420 | + | |
| 421 | + | |
424 | 422 | | |
425 | 423 | | |
426 | 424 | | |
427 | 425 | | |
428 | | - | |
429 | | - | |
| 426 | + | |
| 427 | + | |
430 | 428 | | |
431 | 429 | | |
432 | 430 | | |
433 | 431 | | |
434 | | - | |
435 | | - | |
| 432 | + | |
| 433 | + | |
436 | 434 | | |
437 | 435 | | |
438 | 436 | | |
| |||
443 | 441 | | |
444 | 442 | | |
445 | 443 | | |
446 | | - | |
447 | | - | |
| 444 | + | |
| 445 | + | |
448 | 446 | | |
449 | 447 | | |
450 | | - | |
451 | | - | |
| 448 | + | |
| 449 | + | |
452 | 450 | | |
453 | 451 | | |
454 | 452 | | |
| |||
462 | 460 | | |
463 | 461 | | |
464 | 462 | | |
465 | | - | |
466 | | - | |
| 463 | + | |
| 464 | + | |
467 | 465 | | |
468 | 466 | | |
469 | 467 | | |
470 | 468 | | |
471 | | - | |
472 | | - | |
| 469 | + | |
| 470 | + | |
473 | 471 | | |
474 | 472 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
320 | | - | |
321 | | - | |
322 | | - | |
| 320 | + | |
323 | 321 | | |
324 | 322 | | |
325 | 323 | | |
| |||
332 | 330 | | |
333 | 331 | | |
334 | 332 | | |
335 | | - | |
336 | | - | |
337 | | - | |
| 333 | + | |
338 | 334 | | |
339 | 335 | | |
340 | 336 | | |
| |||
357 | 353 | | |
358 | 354 | | |
359 | 355 | | |
360 | | - | |
361 | | - | |
362 | | - | |
| 356 | + | |
363 | 357 | | |
364 | 358 | | |
365 | 359 | | |
| |||
494 | 488 | | |
495 | 489 | | |
496 | 490 | | |
497 | | - | |
498 | | - | |
499 | | - | |
| 491 | + | |
500 | 492 | | |
501 | 493 | | |
502 | 494 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
222 | | - | |
223 | | - | |
224 | | - | |
| 222 | + | |
225 | 223 | | |
226 | 224 | | |
227 | 225 | | |
| |||
0 commit comments