Test Failed
Push — master ( afbf8e...641184 )
by Valentin
02:35
created

util.TestPathsEqual   A

Complexity

Conditions 4

Size

Total Lines 22
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 18
nop 1
dl 0
loc 22
rs 9.5
c 0
b 0
f 0
1
package util
2
3
import (
4
	"testing"
5
)
6
7
func TestPathsEqual(t *testing.T) {
8
	type check struct {
9
		a, b string
10
		exp  bool
11
	}
12
13
	set := []check{
14
		{"file\\with/different/slashes\\usage", "file/with\\different/slashes/usage", true},
15
		{"file\\with/different/slashes\\usage", "file/with/different/slashes/usage", true},
16
		{"file/with/different/slashes/usage", "file\\with\\different\\slashes\\usage", true},
17
		{"file\\with\\different\\slashes\\usage", "file\\with\\different\\slashes\\usage", true},
18
		{"file/with/different/slashes/usage", "file/with/different/slashes/usage", true},
19
		{"file/with/different/slashes/usage", "file/with/different/slashes/usage/", true},
20
		{"file/with/different/slashes/usage\\", "file/with/different/slashes/usage/", true},
21
		{"file/with/different/slashes/usage\\", "file/with/different/slashes/usage", true},
22
		{"file/with/different/slashes/usage\\", "file/with/different/slashes/usage/oops", false},
23
	}
24
25
	for i, s := range set {
26
		c := PathsEqual(s.a, s.b)
27
		if c != s.exp {
28
			t.Errorf("values compare failed for %d:\ninput `%s`, `%s`\ngot `%t` \nexpected `%t`", i, s.a, s.b, c, s.exp)
29
		}
30
	}
31
}
32
33
func TestTokenizer(t *testing.T) {
34
	set := map[string][]string{
35
		"a,b,,c, d": {"a", "b", "c", "d"},
36
		"a,b,a":     {"a", "b", "a"},
37
		`a,"b,c",d`: {"a", "d", `b,c`},
38
		"a;b,c":     {"a", "b", "c"},
39
	}
40
41
	for str, exp := range set {
42
		tokens := SplitKeywords(str)
43
		if !Equal(exp, tokens) {
44
			t.Errorf("tokens not equal:\ngot `%s`\nexpected `%s`", tokens, exp)
45
		}
46
	}
47
}
48
49
func TestAdjustSize(t *testing.T) {
50
	type check struct {
51
		n, d, min, an, ad int
52
	}
53
	set := []check{
54
		{10, 3, 5, 2, 5},
55
		{10, 6, 5, 2, 5},
56
		{10, 3, 3, 3, 4},
57
		{10, 3, 2, 3, 4},
58
		{10, 3, 11, 1, 11},
59
		{10, 3, 9, 2, 9},
60
	}
61
62
	for i, v := range set {
63
		p, c := AdjustSizes(v.n, v.d, v.min)
64
		if p != v.an || c != v.ad {
65
			t.Errorf("values are not equal for %d:\ninput `%d`, `%d` and `%d`\ngot `%d` and `%d`\nexpected `%d` and `%d`", i, v.n, v.d, v.min, p, c, v.an, v.ad)
66
		}
67
	}
68
}
69
70
func TestExtension(t *testing.T) {
71
	set := [][]string{
72
		{"filename.ext", "ext"},
73
		{".ext", "ext"},
74
		{"filename", ""},
75
		{"filename.", ""},
76
	}
77
78
	for i, str := range set {
79
		ext := Extension(str[0])
80
		if ext != str[1] {
81
			t.Errorf("extensions not equal for %d:\ngot `%s`\nexpected `%s`", i, ext, str[1])
82
		}
83
	}
84
}
85
86
func TestEqual(t *testing.T) {
87
	type check struct {
88
		a, b []string
89
		exp  bool
90
	}
91
92
	set := []check{
93
		{[]string{"a", "b"}, []string{"b", "a"}, true},
94
		{[]string{"a", "b"}, []string{"b", "c"}, false},
95
		{[]string{"a", "b"}, []string{"b", "A"}, false},
96
		{[]string{"a", "b"}, []string{"b"}, false},
97
	}
98
99
	for i, v := range set {
100
		res := Equal(v.a, v.b)
101
		if res != v.exp {
102
			t.Errorf("equality failed for %d:\ngot `%t` \nexpected `%t`", i, res, v.exp)
103
		}
104
	}
105
}
106
107
func TestUnique(t *testing.T) {
108
	type check struct {
109
		a, b []string
110
	}
111
112
	set := []check{
113
		{[]string{"a", "b", "c"}, []string{"a", "b", "c"}},
114
		{[]string{"a", "b", "a"}, []string{"b", "a"}},
115
		{[]string{"a", "B", "b"}, []string{"b", "a", "B"}},
116
	}
117
118
	for i, v := range set {
119
		res := UniqueValues(v.a)
120
		if !Equal(res, v.b) {
121
			t.Errorf("equality failed for %d:\ngot `%s` \nexpected `%s`", i, res, v.b)
122
		}
123
	}
124
}
125