-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathnotable.t
executable file
·220 lines (158 loc) · 6.92 KB
/
notable.t
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/env perl6
BEGIN %*ENV<PERL6_TEST_DIE_ON_FAIL> = 1;
%*ENV<TESTABLE> = 1;
use lib <lib xt/lib>;
use Test;
use Testable;
my $t = Testable.new: bot => ‘Notable’;
$t.common-tests: help => “Like this: {$t.bot-nick}: weekly rakudo is now 10x as fast”;
$t.shortcut-tests: (‘weekly:’,),
<note: note weekly>;
$t.test(‘fallback’,
“{$t.bot-nick}: wazzup?”,
“{$t.our-nick}, I cannot recognize this command. See wiki for some examples: https://github.com/Raku/whateverable/wiki/Notable”);
# No notes
my regex date { \d\d\d\d\-\d\d\-\d\dT\d\d\:\d\d\:\d\dZ }
$t.test(‘no notes’,
“{$t.bot-nick}: blah”,
“{$t.our-nick}, No notes for “blah””);
$t.test(‘no notes (shortcut)’,
“weekly:”,
“{$t.our-nick}, No notes for “weekly””);
$t.test(‘no notes, clearing’,
“{$t.bot-nick}: clear blah”,
“{$t.our-nick}, No notes for “blah””);
$t.test(‘no notes, clearing (shortcut)’,
“weekly: clear”,
“{$t.our-nick}, No notes for “weekly””);
$t.test(‘list topics’,
“{$t.bot-nick}: list”,
“{$t.our-nick}, No notes yet”);
# Creating notes
$t.test(:!both, ‘create new topic’,
“{$t.bot-nick}: new-topic blah”,
“{$t.our-nick}, New topic added (“blah”)”);
$t.test(‘try to create the same topic again’,
“{$t.bot-nick}: new-topic blah”,
“{$t.our-nick}, Topic “blah” already exists”);
$t.test(:!both, ‘note something’,
“{$t.bot-nick}: blah foo”,
“{$t.our-nick}, Noted! (blah)”);
$t.test(‘list topics (with notes)’,
“{$t.bot-nick}: list”,
“{$t.our-nick}, blah”);
$t.test(:!both, ‘note something (shortcut)’,
“weekly: Monday”,
“{$t.our-nick}, Noted! (weekly)”);
$t.test(‘list topics (with notes)’,
“{$t.bot-nick}: list”,
“{$t.our-nick}, blah weekly”);
$t.test(‘list notes’,
“{$t.bot-nick}: blah”,
/^<me($t)>‘, 1 note: ’<date>‘ <’<me($t)>‘>: foo’$/);
$t.test(‘list notes (shortcut)’,
“weekly:”,
/^<me($t)>‘, 1 note: ’<date>‘ <’<me($t)>‘>: Monday’$/);
# Clearing notes
my $moved;
my $moved-shortcut;
$t.test(:!both, ‘clear’,
“{$t.bot-nick}: clear blah”,
/^<me($t)>‘, Moved existing notes to “blah_’<date>‘”’$
{$moved=$<date>}/);
$t.test(:!both, ‘clear (shortcut)’,
“weekly: clear”,
/^<me($t)>‘, Moved existing notes to “weekly_’<date>‘”’$
{$moved-shortcut=$<date>}/);
$t.test(‘list moved notes’,
“{$t.bot-nick}: blah_$moved”,
/^<me($t)>‘, 1 note: ’<date>‘ <’<me($t)>‘>: foo’$/);
$t.test(‘list moved notes (can't use a shortcut, but still)’,
“{$t.bot-nick}: weekly_$moved-shortcut”,
/^<me($t)>‘, 1 note: ’<date>‘ <’<me($t)>‘>: Monday’$/);
$t.test(‘empty after clearing’,
“{$t.bot-nick}: clear blah”,
“{$t.our-nick}, No notes for “blah””);
$t.test(‘empty after clearing (shortcut)’,
“weekly: clear”,
“{$t.our-nick}, No notes for “weekly””);
$t.test(:!both, ‘re-create blah topic’,
“{$t.bot-nick}: new-category blah”,
“{$t.our-nick}, New topic added (“blah”)”);
$t.test(:!both, ‘note something after clearing’,
“{$t.bot-nick}: blah foo”,
“{$t.our-nick}, Noted! (blah)”);
$t.test(:!both, ‘note something after clearing (shortcut)’,
“weekly: Monday”,
“{$t.our-nick}, Noted! (weekly)”);
$t.test(‘list notes after clearing’,
“{$t.bot-nick}: blah”,
/^<me($t)>‘, 1 note: ’<date>‘ <’<me($t)>‘>: foo’$/);
$t.test(‘list notes after clearing (shortcut)’,
“weekly:”,
/^<me($t)>‘, 1 note: ’<date>‘ <’<me($t)>‘>: Monday’$/);
$t.test(:!both, ‘note something again’,
“{$t.bot-nick}: blah bar”,
“{$t.our-nick}, Noted! (blah)”);
$t.test(:!both, ‘note something again (shortcut)’,
“weekly: Tuesday”,
“{$t.our-nick}, Noted! (weekly)”);
$t.test(‘list two notes’,
“{$t.bot-nick}: blah”,
/^<me($t)>‘, 2 notes: ’<date>‘ <’<me($t)>‘>: foo ; ’<date>‘ <’<me($t)>‘>: bar’$/);
$t.test(‘list two notes (shortcut)’,
“weekly:”,
/^<me($t)>‘, 2 notes: ’<date>‘ <’<me($t)>‘>: Monday ; ’<date>‘ <’<me($t)>‘>: Tuesday’$/);
$t.test(:!both, ‘note something big’,
“{$t.bot-nick}: blah {‘z’ x 300}”,
“{$t.our-nick}, Noted! (blah)”);
$t.test(:!both, ‘note something big (shortcut)’,
“weekly: {‘Z’ x 300}”,
“{$t.our-nick}, Noted! (weekly)”);
# DWIM
$t.test(‘clear …’,
“{$t.bot-nick}: clear DWIM”,
“{$t.our-nick}, No notes for “DWIM””);
$t.test(‘reset …’,
“{$t.bot-nick}: reset DWIM”,
“{$t.our-nick}, No notes for “DWIM””);
$t.test(‘delete …’,
“{$t.bot-nick}: delete DWIM”,
“{$t.our-nick}, No notes for “DWIM””);
$t.test(‘… clear’,
“{$t.bot-nick}: DWIM clear”,
“{$t.our-nick}, No notes for “DWIM””);
$t.test(‘… reset’,
“{$t.bot-nick}: DWIM reset”,
“{$t.our-nick}, No notes for “DWIM””);
$t.test(‘… delete’,
“{$t.bot-nick}: DWIM delete”,
“{$t.our-nick}, No notes for “DWIM””);
$t.test(:!both, ‘no topic specified’,
“{$t.bot-nick}: just note it somewhere”,
“{$t.our-nick}, Noted! (weekly)”);
$t.test(‘no new topic created’,
“{$t.bot-nick}: just”,
“{$t.our-nick}, No notes for “just””);
# TODO adapt test once the format is changed to markdown
$t.test(‘gist’,
“{$t.bot-nick}: blah”,
“{$t.our-nick}, 3 notes: https://whatever.able/fakeupload”);
$t.test-gist(‘correct gist’,
%(‘result’ => /^<date>‘ <’$($t.our-nick)‘>: foo’\n
<date>‘ <’$($t.our-nick)‘>: bar’\n
<date>‘ <’$($t.our-nick)‘>: ’$(‘z’ x 300)
$/));
$t.test(‘gist (shortcut)’,
“weekly:”,
“{$t.our-nick}, 4 notes: https://whatever.able/fakeupload”);
$t.test-gist(‘correct gist (shortcut)’,
%(‘result’ => /^<date>‘ <’$($t.our-nick)‘>: Monday’\n
<date>‘ <’$($t.our-nick)‘>: Tuesday’\n
<date>‘ <’$($t.our-nick)‘>: ’$(‘Z’ x 300)\n
<date>‘ <’$($t.our-nick)‘>: just note it somewhere’
$/));
$t.last-test;
done-testing;
END $t.end;
# vim: expandtab shiftwidth=4 ft=perl6