-
Notifications
You must be signed in to change notification settings - Fork 1
/
webserver_test.go
52 lines (44 loc) · 1.39 KB
/
webserver_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2021 Teal.Finance/Garcon contributors
// This file is part of Teal.Finance/Garcon,
// an API and website server under the MIT License.
// SPDX-License-Identifier: MIT
//nolint:testpackage // test unexported function
package garcon
import (
"testing"
)
func Test_extIndex(t *testing.T) {
t.Parallel()
cases := []struct {
name string
path string
ext string
}{
{"regular folder and filename", "folder/file.ext", "ext"},
{"without folder", "file.ext", "ext"},
{"filename without extension", "folder/file", ""},
{"empty path has no extension", "", ""},
{"valid folder but empty filename", "folder/", ""},
{"ignore dot in folder", "folder.ext/file", ""},
{"ignore dot in folder even when no file", "folder.ext/", ""},
{"filename ending with a dot has no extension", "ending-dot.", ""},
{"filename ending with a double dot has no extension", "double-dot..", ""},
{"only consider the last dot", "a..b.c..ext", "ext"},
{"filename starting with a dot has an extension", ".gitignore", "gitignore"},
}
for _, c := range cases {
c := c // parallel test
t.Run(c.name, func(t *testing.T) {
t.Parallel()
extPos := extIndex(c.path)
max := len(c.path)
if extPos < 0 || extPos > max {
t.Errorf("extIndex() = %v out of range [0..%v]", extPos, max)
}
got := c.path[extPos:]
if got != c.ext {
t.Errorf("extIndex() = %v, want %v", got, c.ext)
}
})
}
}