TestFirstLine covers firstLine: it returns the first non-empty trimmed line, skips leading blank lines, and returns "" when there is no non-empty line.
(t *testing.T)
| 8 | // TestFirstLine covers firstLine: it returns the first non-empty trimmed line, |
| 9 | // skips leading blank lines, and returns "" when there is no non-empty line. |
| 10 | func TestFirstLine(t *testing.T) { |
| 11 | cases := []struct { |
| 12 | name string |
| 13 | in string |
| 14 | want string |
| 15 | }{ |
| 16 | {"single line with trailing newline", "abc123\n", "abc123"}, |
| 17 | {"trims surrounding whitespace", " deadbeef \n", "deadbeef"}, |
| 18 | {"skips leading blank lines", "\n\n sha\n", "sha"}, |
| 19 | {"empty input", "", ""}, |
| 20 | {"only whitespace and newlines", "\n \n\t\n", ""}, |
| 21 | } |
| 22 | for _, tc := range cases { |
| 23 | t.Run(tc.name, func(t *testing.T) { |
| 24 | if got := firstLine(tc.in); got != tc.want { |
| 25 | t.Errorf("firstLine(%q) = %q, want %q", tc.in, got, tc.want) |
| 26 | } |
| 27 | }) |
| 28 | } |
| 29 | } |