generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 16
/
match.test.js
121 lines (105 loc) · 3.3 KB
/
match.test.js
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const test = require('ava')
const match = require('./match.js')
test('parses newline-separated arguments', (t) => {
const allowedLabels = match.parseAllowed('hello\nworld')
t.deepEqual(allowedLabels, ['hello', 'world'])
})
test('parses comma-separated arguments', (t) => {
const allowedLabels = match.parseAllowed('hello,world')
t.deepEqual(allowedLabels, ['hello', 'world'])
})
test('parses mixed newline-and-comma arguments', (t) => {
const allowedLabels = match.parseAllowed('major\nminor,patch')
t.deepEqual(allowedLabels, ['major', 'minor', 'patch'])
})
test('parses arguments with whitespace', (t) => {
const allowedLabels = match.parseAllowed('hello, world')
t.deepEqual(allowedLabels, ['hello', 'world'])
})
test('parses arguments with excessive whitespace', (t) => {
const allowedLabels = match.parseAllowed('hello , world')
t.deepEqual(allowedLabels, ['hello', 'world'])
})
test('parses arguments by skipping empty arguments', (t) => {
const allowedLabels = match.parseAllowed('hello ,, world')
t.deepEqual(allowedLabels, ['hello', 'world'])
})
test('match succeeds with exactly one label', (t) => {
const matchedLabel = match.findMatching(
['minor'],
['major', 'minor', 'patch'],
false
)
t.deepEqual(matchedLabel, ['minor'])
})
test('match throws for no labels', (t) => {
t.throws(() => match.findMatching([], ['major', 'minor', 'patch'], false))
t.throws(() => match.findMatching([], ['major', 'minor', 'patch'], true))
})
test('match throws for too many labels', (t) => {
t.throws(() =>
match.findMatching(['minor', 'patch'], ['major', 'minor', 'patch'], false)
)
})
test('match does not throw for too many allowed multiple labels', (t) => {
const matchLabel = match.findMatching(
['minor', 'patch'],
['major', 'minor', 'patch'],
true
)
t.deepEqual(matchLabel, ['minor', 'patch'])
})
test('match returns default for no labels', (t) => {
const matchedLabel = match.findMatching(
[''],
['major', 'minor', 'patch'],
false,
'default'
)
t.deepEqual(matchedLabel, ['default'])
})
test('match returns default for no matching labels', (t) => {
const matchedLabel = match.findMatching(
['not matching'],
['major', 'minor', 'patch'],
false,
'default'
)
t.deepEqual(matchedLabel, ['default'])
})
test('match returns default for no matching multiple labels', (t) => {
const matchedLabel = match.findMatching(
['not matching', 'still not'],
['major', 'minor', 'patch'],
true,
'default'
)
t.deepEqual(matchedLabel, ['default'])
})
test('match does not return default for matching labels', (t) => {
const matchedLabel = match.findMatching(
['not matching', 'minor'],
['major', 'minor', 'patch'],
false,
'default'
)
t.deepEqual(matchedLabel, ['minor'])
})
test('match does not return default for matchin multiple labels', (t) => {
const matchedLabel = match.findMatching(
['major', 'minor'],
['major', 'minor', 'patch'],
true,
'default'
)
t.deepEqual(matchedLabel, ['major', 'minor'])
})
test('match does not return default for matchin multiple labels but not all', (t) => {
const matchedLabel = match.findMatching(
['patch', 'not matching', 'minor'],
['major', 'minor', 'patch'],
true,
'default'
)
t.deepEqual(matchedLabel, ['patch', 'minor'])
})