-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Strings::matchAll(): added option 'lazy'
- Loading branch information
Showing
4 changed files
with
127 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\Utils\Strings::matchAll() | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\Utils\Strings; | ||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
// not matched | ||
Assert::type(Generator::class, Strings::matchAll('hello world!', '#([E-L])+#', lazy: true)); | ||
Assert::same(0, iterator_count(Strings::matchAll('hello world!', '#([E-L])+#', lazy: true))); | ||
|
||
|
||
// sentinel | ||
Assert::same( | ||
[['h'], ['e']], | ||
iterator_to_array(Strings::matchAll('he', '#.#', lazy: true)), | ||
); | ||
|
||
Assert::same( | ||
[[''], ['']], | ||
iterator_to_array(Strings::matchAll('he', '##', lazy: true)), | ||
); | ||
|
||
|
||
// right edge | ||
Assert::same( | ||
[['']], | ||
iterator_to_array(Strings::matchAll('he', '#(?<=e)#', offset: 2, lazy: true)), | ||
); | ||
|
||
Assert::same( | ||
[], | ||
iterator_to_array(Strings::matchAll('he', '#(?<=x)#', offset: 2, lazy: true)), | ||
); | ||
|
||
Assert::same( | ||
[], | ||
iterator_to_array(Strings::matchAll('he', '##', offset: 3, lazy: true)), | ||
); | ||
|
||
|
||
// capturing | ||
Assert::same([ | ||
['hell', 'l'], | ||
['l', 'l'], | ||
], iterator_to_array(Strings::matchAll('hello world!', '#([e-l])+#', lazy: true))); | ||
|
||
Assert::same([ | ||
['hell'], | ||
['l'], | ||
], iterator_to_array(Strings::matchAll('hello world!', '#[e-l]+#', lazy: true))); | ||
|
||
|
||
// options | ||
Assert::same([ | ||
[['lu', 2], ['l', 2], ['u', 3]], | ||
[['ou', 6], ['o', 6], ['u', 7]], | ||
[['k', 10], ['k', 10], ['', 11]], | ||
[['k', 14], ['k', 14], ['', 15]], | ||
], iterator_to_array(Strings::matchAll('žluťoučký kůň!', '#([a-z])([a-z]*)#u', captureOffset: true, lazy: true))); | ||
|
||
Assert::same([ | ||
[['lu', 1], ['l', 1], ['u', 2]], | ||
[['ou', 4], ['o', 4], ['u', 5]], | ||
[['k', 7], ['k', 7], ['', 8]], | ||
[['k', 10], ['k', 10], ['', 11]], | ||
], iterator_to_array(Strings::matchAll('žluťoučký kůň!', '#([a-z])([a-z]*)#u', captureOffset: true, utf8: true, lazy: true))); | ||
|
||
Assert::same( | ||
[['l'], ['k'], ['k']], | ||
iterator_to_array(Strings::matchAll('žluťoučký kůň', '#[e-l]+#u', offset: 2, lazy: true)), | ||
); | ||
|
||
Assert::same( | ||
[['k'], ['k']], | ||
iterator_to_array(Strings::matchAll('žluťoučký kůň', '#[e-l]+#u', offset: 2, utf8: true, lazy: true)), | ||
); | ||
|
||
Assert::same( | ||
[['e', null]], | ||
iterator_to_array(Strings::matchAll('hello world!', '#e(x)*#', unmatchedAsNull: true, lazy: true)), | ||
); |