Passed
Push — master ( 207db3...9c06b5 )
by Stefano
01:16
created

urlpath_test.TestHasExtension   A

Complexity

Conditions 3

Size

Total Lines 45
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 26
nop 1
dl 0
loc 45
rs 9.256
c 0
b 0
f 0
1
package urlpath_test
2
3
import (
4
	"testing"
5
6
	"github.com/stefanoj3/dirstalk/pkg/common/urlpath"
7
	"github.com/stretchr/testify/assert"
8
)
9
10
func TestHasExtension(t *testing.T) {
11
	testCases := []struct {
12
		path           string
13
		expectedResult bool
14
	}{
15
		{
16
			path:           "images/image.jpg",
17
			expectedResult: true,
18
		},
19
		{
20
			path:           "file.pdf",
21
			expectedResult: true,
22
		},
23
		{
24
			path:           "home/page.php",
25
			expectedResult: true,
26
		},
27
		{
28
			path:           "src/code.cpp",
29
			expectedResult: true,
30
		},
31
		{
32
			path:           "src/code.h",
33
			expectedResult: true,
34
		},
35
		{
36
			path:           "folder/script.sh",
37
			expectedResult: true,
38
		},
39
		{
40
			path:           "myfile",
41
			expectedResult: false,
42
		},
43
		{
44
			path:           "myfolder/myfile",
45
			expectedResult: false,
46
		},
47
	}
48
49
	for _, tc := range testCases {
50
		tc := tc
51
		t.Run(tc.path, func(t *testing.T) {
52
			t.Parallel()
53
54
			assert.Equal(t, tc.expectedResult, urlpath.HasExtension(tc.path))
55
		})
56
	}
57
}
58