forked from rhysd/actionlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quotes_test.go
87 lines (80 loc) · 1.61 KB
/
quotes_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
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
package actionlint
import (
"sort"
"strconv"
"strings"
"testing"
)
func TestQuotesSortedQuotes(t *testing.T) {
testCases := [][]string{
{},
{"foo"},
{"foo", "bar", "piyo"},
{"\n", "\t"},
}
for i, tc := range testCases {
t.Run(strconv.Itoa(i), func(t *testing.T) {
ss := tc[:]
sort.Strings(ss)
qs := make([]string, 0, len(ss))
for _, s := range tc {
qs = append(qs, strconv.Quote(s))
}
want := strings.Join(qs, ", ")
have := sortedQuotes(tc)
if want != have {
t.Errorf("want: %s\nhave: %s", want, have)
}
})
}
}
func TestQuotesQuotesRunes(t *testing.T) {
testCases := [][]rune{
{},
{'a'},
{'a', 'b', 'c'},
{'\n', '\t', '\\'},
}
for i, tc := range testCases {
t.Run(strconv.Itoa(i), func(t *testing.T) {
qs := make([]string, 0, len(tc))
for _, r := range tc {
qs = append(qs, strconv.QuoteRune(r))
}
want := strings.Join(qs, ", ")
qb := quotesBuilder{}
for _, r := range tc {
qb.appendRune(r)
}
have := qb.build()
if want != have {
t.Errorf("want: %s\nhave: %s", want, have)
}
})
}
}
func TestQuotesQuotesAll(t *testing.T) {
testCases := [][][]string{
{{}},
{{"foo"}},
{{"foo", "bar"}},
{{"foo"}, {"bar"}},
{{}, {"foo"}, {"bar", "piyo"}},
{{"\n", "\t"}, {"\v"}, {}},
}
for i, tc := range testCases {
t.Run(strconv.Itoa(i), func(t *testing.T) {
qs := []string{}
for _, ss := range tc {
for _, s := range ss {
qs = append(qs, strconv.Quote(s))
}
}
want := strings.Join(qs, ", ")
have := quotesAll(tc...)
if want != have {
t.Errorf("want: %s\nhave: %s", want, have)
}
})
}
}