fixed + tests

This commit is contained in:
asoseil 2017-12-03 20:00:15 +01:00
parent efb96e86dc
commit 6088ce8f00
2 changed files with 21 additions and 0 deletions

View File

@ -56,6 +56,9 @@ func ext(path string) string {
for i := len(path) - 1; i >= 0 && !os.IsPathSeparator(path[i]); i-- {
if path[i] == '.' {
ext = path[i:]
if index := strings.LastIndex(ext,"."); index > 0{
ext = ext[index:]
}
}
}
if ext != "" {

View File

@ -63,3 +63,21 @@ func TestWdir(t *testing.T) {
t.Error("Expected", filepath.Base(expected), "instead", result)
}
}
func TestExt(t *testing.T){
paths := map[string]string{
"/test/a/b/c": "",
"/test/a/ac.go": "go",
"/test/a/ac.test.go": "go",
"/test/a/ac_test.go": "go",
"/test/./ac_test.go": "go",
"/test/a/.test": "test",
"/test/a/.": "",
}
for i, v := range paths {
if ext(i) != v{
t.Error("Wrong extension",ext(i),v)
}
}
}