Skip to content

Commit 98feac6

Browse files
committed
Add more parser tests
1 parent 9c9cb31 commit 98feac6

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

tests/ImapParserTest.php

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@
151151

152152
test('parses quota response', function () {
153153
$stream = new FakeStream;
154-
155154
$stream->open();
156155

157156
$stream->feed([
@@ -173,3 +172,44 @@
173172
expect($response2->tokens())->toHaveCount(4);
174173
expect((string) $response2)->toBe('TAG1 OK GETQUOTA completed');
175174
});
175+
176+
test('parses response tokens', function (array|string $feed, string $type, string $value) {
177+
$stream = new FakeStream;
178+
$stream->open();
179+
180+
$stream->feed($feed);
181+
182+
$tokenizer = new ImapTokenizer($stream);
183+
$parser = new ImapParser($tokenizer);
184+
$response = $parser->next();
185+
186+
expect($response)->toBeInstanceOf($type);
187+
expect((string) $response)->toBe($value);
188+
})->with([
189+
['()', ListData::class, '()'],
190+
['(A B C)', ListData::class, '(A B C)'],
191+
[['{0}', ''], Literal::class, "{0}\r\n"],
192+
['(A (B C) D)', ListData::class, '(A (B C) D)'],
193+
[['{5}', 'Hello'], Literal::class, "{5}\r\nHello"],
194+
['((A) (B (C)))', ListData::class, '((A) (B (C)))'],
195+
['"Hello, world!"', QuotedString::class, '"Hello, world!"'],
196+
[['{12}', 'Hello', 'Bye'], Literal::class, "{12}\r\nHello\r\nBye\r\n"],
197+
['* OK Dovecot ready.', UntaggedResponse::class, '* OK Dovecot ready.'],
198+
['* 2 FETCH (UID 102)', UntaggedResponse::class, '* 2 FETCH (UID 102)'],
199+
['TAG1 OK FETCH completed', TaggedResponse::class, 'TAG1 OK FETCH completed'],
200+
[
201+
'* QUOTA "#user/testuser" (STORAGE 512 1024)',
202+
UntaggedResponse::class, '* QUOTA "#user/testuser" (STORAGE 512 1024)',
203+
],
204+
['* SEARCH 1 2 3', UntaggedResponse::class, '* SEARCH 1 2 3'],
205+
['A007 NO [ALERT] System busy', TaggedResponse::class, 'A007 NO [ALERT] System busy'],
206+
[
207+
[
208+
'* 1 FETCH (BODY {14}',
209+
'Hello World!',
210+
')',
211+
],
212+
UntaggedResponse::class,
213+
"* 1 FETCH (BODY {14}\r\nHello World!\r\n)",
214+
],
215+
]);

0 commit comments

Comments
 (0)