| 45 | } |
| 46 | |
| 47 | func TestBasenameRemovesLeadingPathComponentsFromInputLines(t *testing.T) { |
| 48 | t.Parallel() |
| 49 | tcs := []struct { |
| 50 | path string |
| 51 | want string |
| 52 | }{ |
| 53 | {"\n", ".\n"}, |
| 54 | {"/", "/\n"}, |
| 55 | {"/root", "root\n"}, |
| 56 | {"/tmp/example.php", "example.php\n"}, |
| 57 | {"./src/filters", "filters\n"}, |
| 58 | {"/var/tmp/example.php", "example.php\n"}, |
| 59 | {"/tmp/script-21345.txt\n/tmp/script-5371253.txt", "script-21345.txt\nscript-5371253.txt\n"}, |
| 60 | {"C:/Program Files", "Program Files\n"}, |
| 61 | {"C:/Program Files/", "Program Files\n"}, |
| 62 | } |
| 63 | for _, tc := range tcs { |
| 64 | // Expect results to use this platform's path separator |
| 65 | want := filepath.Clean(tc.want) |
| 66 | got, err := script.Echo(tc.path).Basename().String() |
| 67 | if err != nil { |
| 68 | t.Fatal(err) |
| 69 | } |
| 70 | if want != got { |
| 71 | t.Errorf("%q: want %q, got %q", tc.path, want, got) |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | func TestColumnSelects(t *testing.T) { |
| 77 | t.Parallel() |