-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_test.go
More file actions
107 lines (82 loc) · 2.29 KB
/
Copy pathparser_test.go
File metadata and controls
107 lines (82 loc) · 2.29 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestReadConfig(t *testing.T) {
cfg, err := readConfig()
require.NoError(t, err)
assert.Equal(t, 72, cfg.HeaderMaxLength)
assert.Len(t, cfg.AllowedTypes, 2)
}
func TestCheckLength(t *testing.T) {
longString := "long-string"
msgType := "type1"
parsed := Parsed{
Header: &longString,
Type: &msgType,
}
config := LintConfig{
HeaderMaxLength: 1,
AllowedTypes: map[string]struct{}{"type1": {}},
}
res := check(parsed, config)
require.Len(t, res, 1)
assert.Equal(t, "header should be less than 1, actual 11", res[0].Description)
}
func TestCheckAllowedTypes(t *testing.T) {
longString := "long-string"
goodType := "type1"
parsed := Parsed{
Header: &longString,
Type: &goodType,
}
config := LintConfig{
HeaderMaxLength: 72,
AllowedTypes: map[string]struct{}{"type1": {}},
}
res := check(parsed, config)
require.Len(t, res, 0)
}
func TestCheckShouldRejectBadTypes(t *testing.T) {
longString := "long-string"
badType := "bad"
parsed := Parsed{
Header: &longString,
Type: &badType,
}
config := LintConfig{
HeaderMaxLength: 72,
AllowedTypes: map[string]struct{}{"type1": {}},
}
res := check(parsed, config)
require.Len(t, res, 1)
assert.Equal(t, "type should be on of: type1", res[0].Description)
}
func TestParserShouldParseHeader(t *testing.T) {
text := "feat(nglist): Allow custom separator"
assert.NotNil(t, parse(text).Header)
assert.Equal(t, text, *parse(text).Header)
}
func TestParseShouldExtractHeaderParts(t *testing.T) {
text := "feat(scope): broadcast $destroy event on scope destruction"
parsed := parse(text)
assert.NotNil(t, parse(text).Header)
assert.Equal(t, text, *parsed.Header)
assert.NotNil(t, parse(text).Type)
assert.Equal(t, "feat", *parsed.Type)
assert.NotNil(t, parse(text).Scope)
assert.Equal(t, "scope", *parsed.Scope)
assert.NotNil(t, parse(text).Subject)
assert.Equal(t, "broadcast $destroy event on scope destruction", *parsed.Subject)
}
func TestParseShouldSetNullIfPartNotFound(t *testing.T) {
text := "header"
parsed := parse(text)
assert.NotNil(t, parse(text).Header)
assert.Equal(t, text, *parsed.Header)
assert.Nil(t, parsed.Type)
assert.Nil(t, parsed.Scope)
assert.Nil(t, parsed.Subject)
}