aboutsummaryrefslogtreecommitdiff
path: root/file
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-05-03 14:39:06 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-05-03 14:39:06 +0200
commita60a43fadb0ebc1a5c87fc36a77c6b8d671fba95 (patch)
treef076b0a01e428d7beed38b86a69ee534457103c9 /file
parentf96a2c43ac81acd7f51fafa109770b6744c4959d (diff)
test split
Diffstat (limited to 'file')
-rw-r--r--file/names.go6
-rw-r--r--file/names_test.go20
2 files changed, 24 insertions, 2 deletions
diff --git a/file/names.go b/file/names.go
index a522f6b..2e90e7b 100644
--- a/file/names.go
+++ b/file/names.go
@@ -18,9 +18,11 @@ const (
)
func splitNameExt(fname string) (string, string) {
- fname = filepath.Base(fname)
ext := filepath.Ext(fname)
- return fname[:len(ext)-1], ext
+ if len(ext) == 0 {
+ return fname, ""
+ }
+ return fname[:len(fname)-len(ext)], ext
}
func Names(pubFile, encFile string) error {
diff --git a/file/names_test.go b/file/names_test.go
index d57d6ee..f4d474b 100644
--- a/file/names_test.go
+++ b/file/names_test.go
@@ -42,3 +42,23 @@ func TestVerify(t *testing.T) {
})
}
}
+
+func TestSplit(t *testing.T) {
+ testCases := []struct {
+ fname, name, ext string
+ }{
+ {"testkey.pub", "testkey", ".pub"},
+ {"testkey", "testkey", ""},
+ {".pub", "", ".pub"},
+ {".testkey.pub", ".testkey", ".pub"},
+ {"", "", ""},
+ }
+ for _, tc := range testCases {
+ t.Run(tc.fname, func(t *testing.T) {
+ name, ext := splitNameExt(tc.fname)
+ if name != tc.name || ext != tc.ext {
+ t.Errorf("got %q %q, want %q %q", name, tc.name, ext, tc.ext)
+ }
+ })
+ }
+}