MCPcopy Index your code
hub / github.com/cli/cli / Test_colorDiffLines

Function Test_colorDiffLines

pkg/cmd/pr/diff/diff_test.go:353–394  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

351`
352
353func Test_colorDiffLines(t *testing.T) {
354 inputs := []struct {
355 input, output string
356 }{
357 {
358 input: "",
359 output: "",
360 },
361 {
362 input: "\n",
363 output: "\n",
364 },
365 {
366 input: "foo\nbar\nbaz\n",
367 output: "foo\nbar\nbaz\n",
368 },
369 {
370 input: "foo\nbar\nbaz",
371 output: "foo\nbar\nbaz\n",
372 },
373 {
374 input: fmt.Sprintf("+foo\n-b%sr\n+++ baz\n", strings.Repeat("a", 2*lineBufferSize)),
375 output: fmt.Sprintf(
376 "%[4]s+foo%[2]s\n%[5]s-b%[1]sr%[2]s\n%[3]s+++ baz%[2]s\n",
377 strings.Repeat("a", 2*lineBufferSize),
378 "\x1b[m",
379 "\x1b[1;37m",
380 "\x1b[32m",
381 "\x1b[31m",
382 ),
383 },
384 }
385 for _, tt := range inputs {
386 buf := bytes.Buffer{}
387 if err := colorDiffLines(&buf, strings.NewReader(tt.input)); err != nil {
388 t.Fatalf("unexpected error: %s", err)
389 }
390 if got := buf.String(); got != tt.output {
391 t.Errorf("expected: %q, got: %q", tt.output, got)
392 }
393 }
394}
395
396func Test_changedFileNames(t *testing.T) {
397 inputs := []struct {

Callers

nothing calls this directly

Calls 3

colorDiffLinesFunction · 0.85
ErrorfMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected