MCPcopy Create free account
hub / github.com/alibaba/open-code-review / TestFirstLine

Function TestFirstLine

internal/diff/first_line_test.go:10–29  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
10func 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}

Callers

nothing calls this directly

Calls 2

firstLineFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected