From 6088ce8f00fa8fe6c60355d815f5829107be4f2a Mon Sep 17 00:00:00 2001 From: asoseil Date: Sun, 3 Dec 2017 20:00:15 +0100 Subject: [PATCH] fixed + tests --- realize/utils.go | 3 +++ realize/utils_test.go | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/realize/utils.go b/realize/utils.go index 7228c9e..14a1034 100644 --- a/realize/utils.go +++ b/realize/utils.go @@ -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 != "" { diff --git a/realize/utils_test.go b/realize/utils_test.go index 855a8c3..1f75063 100644 --- a/realize/utils_test.go +++ b/realize/utils_test.go @@ -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) + } + } + +}