|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Test: Nette\Utils\Strings::matchAll() |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +use Nette\Utils\Strings; |
| 10 | +use Tester\Assert; |
| 11 | + |
| 12 | + |
| 13 | +require __DIR__ . '/../bootstrap.php'; |
| 14 | + |
| 15 | + |
| 16 | +Assert::type(Generator::class, Strings::matchAll('hello world!', '#([E-L])+#', lazy: true)); |
| 17 | +Assert::type(Generator::class, Strings::matchAll('hello world!', '#([E-L])+#', lazy: true, offset: 50)); |
| 18 | + |
| 19 | +Assert::same(0, iterator_count(Strings::matchAll('hello world!', '#([E-L])+#', lazy: true))); |
| 20 | + |
| 21 | +Assert::same([ |
| 22 | + ['hell', 'l'], |
| 23 | + ['l', 'l'], |
| 24 | +], iterator_to_array(Strings::matchAll('hello world!', '#([e-l])+#', lazy: true))); |
| 25 | + |
| 26 | +Assert::same([ |
| 27 | + ['hell'], |
| 28 | + ['l'], |
| 29 | +], iterator_to_array(Strings::matchAll('hello world!', '#[e-l]+#', lazy: true))); |
| 30 | + |
| 31 | +Assert::same([ |
| 32 | + [['lu', 2], ['l', 2], ['u', 3]], |
| 33 | + [['ou', 6], ['o', 6], ['u', 7]], |
| 34 | + [['k', 10], ['k', 10], ['', 11]], |
| 35 | + [['k', 14], ['k', 14], ['', 15]], |
| 36 | +], iterator_to_array(Strings::matchAll('žluťoučký kůň!', '#([a-z])([a-z]*)#u', captureOffset: true, lazy: true))); |
| 37 | + |
| 38 | +Assert::same([ |
| 39 | + [['lu', 1], ['l', 1], ['u', 2]], |
| 40 | + [['ou', 4], ['o', 4], ['u', 5]], |
| 41 | + [['k', 7], ['k', 7], ['', 8]], |
| 42 | + [['k', 10], ['k', 10], ['', 11]], |
| 43 | +], iterator_to_array(Strings::matchAll('žluťoučký kůň!', '#([a-z])([a-z]*)#u', captureOffset: true, utf8: true, lazy: true))); |
| 44 | + |
| 45 | +Assert::same( |
| 46 | + [['l'], ['k'], ['k']], |
| 47 | + iterator_to_array(Strings::matchAll('žluťoučký kůň', '#[e-l]+#u', offset: 2, lazy: true)), |
| 48 | +); |
| 49 | + |
| 50 | +Assert::same( |
| 51 | + [['k'], ['k']], |
| 52 | + iterator_to_array(Strings::matchAll('žluťoučký kůň', '#[e-l]+#u', offset: 2, utf8: true, lazy: true)), |
| 53 | +); |
| 54 | + |
| 55 | +Assert::same( |
| 56 | + [['e', null]], |
| 57 | + iterator_to_array(Strings::matchAll('hello world!', '#e(x)*#', unmatchedAsNull: true, lazy: true)), |
| 58 | +); |
| 59 | + |
| 60 | +Assert::same( |
| 61 | + [], |
| 62 | + iterator_to_array(Strings::matchAll('hello world!', '', offset: 50, lazy: true)), |
| 63 | +); |
0 commit comments