compareTables normalizes the incoming table lines
(t *testing.T, expected, out string)
| 485 | |
| 486 | // compareTables normalizes the incoming table lines |
| 487 | func compareTables(t *testing.T, expected, out string) { |
| 488 | t.Helper() |
| 489 | |
| 490 | expectedLines := strings.Split(strings.TrimSpace(expected), "\n") |
| 491 | gotLines := strings.Split(strings.TrimSpace(out), "\n") |
| 492 | assert.Equal(t, len(expectedLines), len(gotLines), "expected line count does not match generated line count") |
| 493 | |
| 494 | // Map the expected and got lines to normalize them. |
| 495 | expectedNormalized := make([]string, len(expectedLines)) |
| 496 | gotNormalized := make([]string, len(gotLines)) |
| 497 | normalizeLine := func(s string) string { |
| 498 | return strings.Join(strings.Fields(strings.TrimSpace(s)), " ") |
| 499 | } |
| 500 | for i, s := range expectedLines { |
| 501 | expectedNormalized[i] = normalizeLine(s) |
| 502 | } |
| 503 | for i, s := range gotLines { |
| 504 | gotNormalized[i] = normalizeLine(s) |
| 505 | } |
| 506 | |
| 507 | require.Equal(t, expectedNormalized, gotNormalized, "expected lines to match generated lines") |
| 508 | } |
no test coverage detected