MCPcopy Create free account
hub / github.com/cli/cli / Test_changedFileNames

Function Test_changedFileNames

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

Source from the content-addressed store, hash-verified

462}
463
464func Test_changedFileNames(t *testing.T) {
465 inputs := []struct {
466 input, output string
467 }{
468 {
469 input: "",
470 output: "",
471 },
472 {
473 input: "\n",
474 output: "",
475 },
476 {
477 input: "diff --git a/cmd.go b/cmd.go\n--- /dev/null\n+++ b/cmd.go\n@@ -0,0 +1,313 @@",
478 output: "cmd.go\n",
479 },
480 {
481 input: "diff --git a/cmd.go b/cmd.go\n--- a/cmd.go\n+++ /dev/null\n@@ -0,0 +1,313 @@",
482 output: "cmd.go\n",
483 },
484 {
485 input: fmt.Sprintf("diff --git a/baz.go b/rename.go\n--- a/baz.go\n+++ b/rename.go\n+foo\n-b%sr", strings.Repeat("a", 2*lineBufferSize)),
486 output: "rename.go\n",
487 },
488 {
489 input: fmt.Sprintf("diff --git a/baz.go b/baz.go\n--- a/baz.go\n+++ b/baz.go\n+foo\n-b%sr", strings.Repeat("a", 2*lineBufferSize)),
490 output: "baz.go\n",
491 },
492 {
493 input: "diff --git \"a/\343\202\212\343\203\274\343\201\251\343\201\277\343\203\274.md\" \"b/\343\202\212\343\203\274\343\201\251\343\201\277\343\203\274.md\"",
494 output: "\"\343\202\212\343\203\274\343\201\251\343\201\277\343\203\274.md\"\n",
495 },
496 }
497 for _, tt := range inputs {
498 buf := bytes.Buffer{}
499 if err := changedFilesNames(&buf, strings.NewReader(tt.input)); err != nil {
500 t.Fatalf("unexpected error: %s", err)
501 }
502 if got := buf.String(); got != tt.output {
503 t.Errorf("expected: %q, got: %q", tt.output, got)
504 }
505 }
506}
507
508func stubDiffRequest(reg *httpmock.Registry, accept, diff string) {
509 reg.Register(

Callers

nothing calls this directly

Calls 3

changedFilesNamesFunction · 0.85
StringMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected