-
Notifications
You must be signed in to change notification settings - Fork 1
/
command_test.go
79 lines (75 loc) · 2 KB
/
command_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
package notify
import "testing"
var commandTests = []struct {
desc string
notification Notification
want []string
}{
{
"basic notification",
Notification{Text: "foo", Title: "bar"},
[]string{"-e", `display notification "foo" with title "bar"`},
},
{
"double quote semantics",
Notification{Text: `foo"doublequote"`, Title: `bar"doublequote"`},
[]string{"-e", `display notification "foo\"doublequote\"" with title "bar\"doublequote\""`},
},
{
"single quote semantics",
Notification{Text: `foo'singlequote'`, Title: `bar'singlequote'`},
[]string{"-e", `display notification "foo'singlequote'" with title "bar'singlequote'"`},
},
{
"with a subtitle",
Notification{Text: `foo`, Title: `bar`, Subtitle: "baz"},
[]string{
"-e",
`display notification "foo" with title "bar" subtitle "baz"`,
},
},
{
"with a subtitle containing quote marks",
Notification{Text: `foo`, Title: `bar`, Subtitle: `baz"malicious"`},
[]string{
"-e",
`display notification "foo" with title "bar" subtitle "baz\"malicious\""`,
},
},
{
"with a sound",
Notification{Text: `foo`, Title: `bar`, Sound: "Funk"},
[]string{
"-e",
`display notification "foo" with title "bar" sound name "Funk"`,
},
},
{
"with a sound contining quote marks",
Notification{Text: `foo`, Title: `bar`, Sound: `Funk"malicious"`},
[]string{
"-e",
`display notification "foo" with title "bar" sound name "Funk\"malicious\""`,
},
},
{
"with everything containing double quotes",
Notification{Text: `"dq"`, Title: `"dq"`, Subtitle: `"dq"`, Sound: `"dq"`},
[]string{
"-e",
`display notification "\"dq\"" with title "\"dq\"" subtitle "\"dq\"" sound name "\"dq\""`,
},
},
}
func TestCommandCorrectlyFormatsTheCommandString(t *testing.T) {
t.Parallel()
for i, perm := range commandTests {
for j, s := range perm.notification.command() {
if s != perm.want[j] {
t.Errorf(`Error with %s (#%d).
Got: "%v"
Expected: "%v"`, perm.desc, i+1, s, perm.want[j])
}
}
}
}