File: Strings.matchAll.lazy%28%29.phpt

package info (click to toggle)
php-nette-utils 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,460 kB
  • sloc: php: 4,146; xml: 9; makefile: 4
file content (89 lines) | stat: -rw-r--r-- 2,152 bytes parent folder | download | duplicates (2)
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
<?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)),
);