Skip to content

Commit 9c9cb31

Browse files
committed
Add lots of tokenizer tests
1 parent af5798a commit 9c9cb31

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

tests/ImapTokenizerTest.php

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@
232232
expect($tokenizer->nextToken())->toBeNull();
233233
});
234234

235-
test('tokenizer parsed tagged response', function () {
235+
test('tokenizer parses tagged response with response codes', function () {
236236
$stream = new FakeStream;
237237
$stream->open();
238238

@@ -275,6 +275,65 @@
275275
expect($tokenizer->nextToken())->toBeNull();
276276
});
277277

278+
test('tokenizer parsers properly', function (array|string $feed, array $tokens) {
279+
$stream = new FakeStream;
280+
$stream->open();
281+
$stream->feed($feed);
282+
283+
$tokenizer = new ImapTokenizer($stream);
284+
285+
for ($i = 0; $i < count($tokens); $i++) {
286+
$token = $tokenizer->nextToken();
287+
288+
expect($token->value)->toBe($tokens[$i]);
289+
}
290+
})->with([
291+
[
292+
'TAG2 OK List completed (0.002 + 0.000 + 0.001 secs).',
293+
['TAG2', 'OK', 'List', 'completed', '(', '0.002', '+', '0.000', '+', '0.001', 'secs', ')'],
294+
],
295+
[
296+
'TAG1 OK [UIDNEXT 1000] Completed',
297+
['TAG1', 'OK', '[', 'UIDNEXT', '1000', ']', 'Completed'],
298+
],
299+
[
300+
'* OK [CAPABILITY IMAP4rev1 LITERAL+] Server ready',
301+
['*', 'OK', '[', 'CAPABILITY', 'IMAP4rev1', 'LITERAL+', ']', 'Server', 'ready'],
302+
],
303+
[
304+
'* BAD Command unknown',
305+
['*', 'BAD', 'Command', 'unknown'],
306+
],
307+
[
308+
'A1 NO (ALERT Unrecognized command)',
309+
['A1', 'NO', '(', 'ALERT', 'Unrecognized', 'command', ')'],
310+
],
311+
[
312+
'A142 FETCH (FLAGS (\\Seen) UID 48273)',
313+
['A142', 'FETCH', '(', 'FLAGS', '(', '\\Seen', ')', 'UID', '48273', ')'],
314+
],
315+
[
316+
'A002 OK [READ-ONLY] Mailbox opened',
317+
['A002', 'OK', '[', 'READ-ONLY', ']', 'Mailbox', 'opened'],
318+
],
319+
[
320+
['A003 OK {4}', 'Test'],
321+
['A003', 'OK', 'Test'],
322+
],
323+
[
324+
'* LIST (\\HasNoChildren) "/" INBOX',
325+
['*', 'LIST', '(', '\\HasNoChildren', ')', '/', 'INBOX'],
326+
],
327+
[
328+
'A005 OK <[email protected]> Email sent',
329+
['A005', 'OK', '[email protected]', 'Email', 'sent'],
330+
],
331+
[
332+
'A004 BAD Syntax error',
333+
['A004', 'BAD', 'Syntax', 'error'],
334+
],
335+
]);
336+
278337
test('all tokens implement the token interface', function (string $data) {
279338
$stream = new FakeStream;
280339
$stream->open();

0 commit comments

Comments
 (0)