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

Function Test_changedFileNames

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

Source from the content-addressed store, hash-verified

394}
395
396func Test_changedFileNames(t *testing.T) {
397 inputs := []struct {
398 input, output string
399 }{
400 {
401 input: "",
402 output: "",
403 },
404 {
405 input: "\n",
406 output: "",
407 },
408 {
409 input: "diff --git a/cmd.go b/cmd.go\n--- /dev/null\n+++ b/cmd.go\n@@ -0,0 +1,313 @@",
410 output: "cmd.go\n",
411 },
412 {
413 input: "diff --git a/cmd.go b/cmd.go\n--- a/cmd.go\n+++ /dev/null\n@@ -0,0 +1,313 @@",
414 output: "cmd.go\n",
415 },
416 {
417 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)),
418 output: "rename.go\n",
419 },
420 {
421 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)),
422 output: "baz.go\n",
423 },
424 {
425 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\"",
426 output: "\"\343\202\212\343\203\274\343\201\251\343\201\277\343\203\274.md\"\n",
427 },
428 }
429 for _, tt := range inputs {
430 buf := bytes.Buffer{}
431 if err := changedFilesNames(&buf, strings.NewReader(tt.input)); err != nil {
432 t.Fatalf("unexpected error: %s", err)
433 }
434 if got := buf.String(); got != tt.output {
435 t.Errorf("expected: %q, got: %q", tt.output, got)
436 }
437 }
438}
439
440func stubDiffRequest(reg *httpmock.Registry, accept, diff string) {
441 reg.Register(

Callers

nothing calls this directly

Calls 3

changedFilesNamesFunction · 0.85
ErrorfMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected