MCPcopy Create free account
hub / github.com/antonmedv/gitmal / TestParseGitHeaderName

Function TestParseGitHeaderName

pkg/gitdiff/file_header_test.go:643–709  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

641}
642
643func TestParseGitHeaderName(t *testing.T) {
644 tests := map[string]struct {
645 Input string
646 Output string
647 Err bool
648 }{
649 "twoMatchingNames": {
650 Input: "a/dir/file.txt b/dir/file.txt",
651 Output: "dir/file.txt",
652 },
653 "twoDifferentNames": {
654 Input: "a/dir/foo.txt b/dir/bar.txt",
655 Output: "",
656 },
657 "matchingNamesWithSpaces": {
658 Input: "a/dir/file with spaces.txt b/dir/file with spaces.txt",
659 Output: "dir/file with spaces.txt",
660 },
661 "matchingNamesWithTrailingSpaces": {
662 Input: "a/dir/spaces b/dir/spaces ",
663 Output: "dir/spaces ",
664 },
665 "matchingNamesQuoted": {
666 Input: `"a/dir/\"quotes\".txt" "b/dir/\"quotes\".txt"`,
667 Output: `dir/"quotes".txt`,
668 },
669 "matchingNamesFirstQuoted": {
670 Input: `"a/dir/file.txt" b/dir/file.txt`,
671 Output: "dir/file.txt",
672 },
673 "matchingNamesSecondQuoted": {
674 Input: `a/dir/file.txt "b/dir/file.txt"`,
675 Output: "dir/file.txt",
676 },
677 "noSecondName": {
678 Input: "a/dir/foo.txt",
679 Output: "",
680 },
681 "noSecondNameQuoted": {
682 Input: `"a/dir/foo.txt"`,
683 Output: "",
684 },
685 "invalidName": {
686 Input: `"a/dir/file.txt b/dir/file.txt`,
687 Err: true,
688 },
689 }
690
691 for name, test := range tests {
692 t.Run(name, func(t *testing.T) {
693 output, err := parseGitHeaderName(test.Input)
694 if test.Err {
695 if err == nil {
696 t.Fatalf("expected error parsing header name, but got nil")
697 }
698 return
699 }
700 if err != nil {

Callers

nothing calls this directly

Calls 2

parseGitHeaderNameFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected