| 725 | } |
| 726 | |
| 727 | func Test_parsePathFromFileArg(t *testing.T) { |
| 728 | tests := []struct { |
| 729 | name string |
| 730 | currentDir string |
| 731 | fileArg string |
| 732 | expectedPath string |
| 733 | }{ |
| 734 | { |
| 735 | name: "empty paths", |
| 736 | currentDir: "", |
| 737 | fileArg: "", |
| 738 | expectedPath: "", |
| 739 | }, |
| 740 | { |
| 741 | name: "root directory", |
| 742 | currentDir: "", |
| 743 | fileArg: ".", |
| 744 | expectedPath: "", |
| 745 | }, |
| 746 | { |
| 747 | name: "relative path", |
| 748 | currentDir: "", |
| 749 | fileArg: filepath.FromSlash("foo/bar.py"), |
| 750 | expectedPath: "foo/bar.py", |
| 751 | }, |
| 752 | { |
| 753 | name: "go to parent folder", |
| 754 | currentDir: "pkg/cmd/browse/", |
| 755 | fileArg: filepath.FromSlash("../"), |
| 756 | expectedPath: "pkg/cmd", |
| 757 | }, |
| 758 | { |
| 759 | name: "current folder", |
| 760 | currentDir: "pkg/cmd/browse/", |
| 761 | fileArg: ".", |
| 762 | expectedPath: "pkg/cmd/browse", |
| 763 | }, |
| 764 | { |
| 765 | name: "current folder (alternative)", |
| 766 | currentDir: "pkg/cmd/browse/", |
| 767 | fileArg: filepath.FromSlash("./"), |
| 768 | expectedPath: "pkg/cmd/browse", |
| 769 | }, |
| 770 | { |
| 771 | name: "file that starts with '.'", |
| 772 | currentDir: "pkg/cmd/browse/", |
| 773 | fileArg: ".gitignore", |
| 774 | expectedPath: "pkg/cmd/browse/.gitignore", |
| 775 | }, |
| 776 | { |
| 777 | name: "file in current folder", |
| 778 | currentDir: "pkg/cmd/browse/", |
| 779 | fileArg: filepath.Join(".", "browse.go"), |
| 780 | expectedPath: "pkg/cmd/browse/browse.go", |
| 781 | }, |
| 782 | { |
| 783 | name: "file within parent folder", |
| 784 | currentDir: "pkg/cmd/browse/", |