-
-
Notifications
You must be signed in to change notification settings - Fork 145
/
Strings.split().phpt
72 lines (59 loc) · 1.13 KB
/
Strings.split().phpt
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
<?php
/**
* Test: Nette\Utils\Strings::split()
*/
declare(strict_types=1);
use Nette\Utils\Strings;
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
Assert::same([
'a',
',',
'b',
',',
'c',
], Strings::split('a, b, c', '#(,)\s*#'));
Assert::same([
'a',
',',
'b',
',',
'c',
], Strings::split('a, b, c', '#(,)\s*#', PREG_SPLIT_NO_EMPTY));
Assert::same([
'a',
',',
'b',
',',
'c',
], Strings::split('a, b, c', '#(,)\s*#', skipEmpty: true));
Assert::same([
['a', 0],
[',', 1],
['b', 3],
[',', 4],
['c', 6],
], Strings::split('a, b, c', '#(,)\s*#', PREG_SPLIT_OFFSET_CAPTURE));
Assert::same([
['ž', 0],
['lu', 2],
['ť', 4],
['ou', 6],
['č', 8],
['k', 10],
['ý ', 11],
['k', 14],
['ůň', 15],
], Strings::split('žluťoučký kůň', '#([a-z]+)\s*#u', captureOffset: true));
Assert::same([
['ž', 0],
['lu', 1],
['ť', 3],
['ou', 4],
['č', 6],
['k', 7],
['ý ', 8],
['k', 10],
['ůň', 11],
], Strings::split('žluťoučký kůň', '#([a-z]+)\s*#u', captureOffset: true, utf8: true));
Assert::same(['', ' ', ''], Strings::split('žluťoučký kůň', '#\w+#', utf8: true)); // without modifier