-
Notifications
You must be signed in to change notification settings - Fork 158
/
ast_test.go
59 lines (54 loc) · 1.35 KB
/
ast_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
package actionlint
import "testing"
func TestStringIsExpressionAssigned(t *testing.T) {
tests := []struct {
input string
want bool
}{
{"${{...}}", true},
{" ${{...}} ", true},
{`${{ foo == '{"a": {"b": "c"}}' }}`, true}, // edge case
{"", false},
{"${}", false},
{"{{}}", false},
{"${{", false},
{"}}", false},
{"${{ ${{ }}", false},
{"abc ${{...}}", false},
{"${{...}} abc", false},
{"${{...}}${{...}}", false},
}
for _, tc := range tests {
t.Run(tc.input, func(t *testing.T) {
s := &String{Value: tc.input}
have := s.IsExpressionAssigned()
if tc.want != have {
t.Fatalf("wanted %v but got %v for input %q", tc.want, have, tc.input)
}
})
}
}
func TestStringContainsExpression(t *testing.T) {
tests := []struct {
input string
want bool
}{
{"${{...}}", true},
{"foo-${{...}}-bar", true},
{"${{...}}-${{...}}", true},
{"${{...", false},
{"...}}", false},
{"${{...} }", false},
}
for _, tc := range tests {
t.Run(tc.input, func(t *testing.T) {
s := &String{Value: tc.input}
if have := s.ContainsExpression(); tc.want != have {
t.Fatalf("wanted %v but the method returned %v for input %q", tc.want, have, tc.input)
}
if have := ContainsExpression(tc.input); tc.want != have {
t.Fatalf("wanted %v but the function returned %v for input %q", tc.want, have, tc.input)
}
})
}
}