|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Xml; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use Xml\Impl\Util\StringUtil; |
|
7
|
|
|
|
|
8
|
|
|
class StringUtilTest extends TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
public function testStringListSplit(): void |
|
11
|
|
|
{ |
|
12
|
|
|
$this->assertEmpty(StringUtil::splitCommaSeparatedList(null)); |
|
13
|
|
|
$this->assertEmpty(StringUtil::splitCommaSeparatedList('')); |
|
14
|
|
|
$this->assertEmpty(StringUtil::splitCommaSeparatedList(' ')); |
|
15
|
|
|
$this->assertContains('a', StringUtil::splitCommaSeparatedList('a')); |
|
16
|
|
|
foreach (['a', 'b'] as $value) { |
|
17
|
|
|
$this->assertContains($value, StringUtil::splitCommaSeparatedList('a,b')); |
|
18
|
|
|
} |
|
19
|
|
|
$this->assertCount(2, StringUtil::splitCommaSeparatedList('a,b')); |
|
20
|
|
|
foreach (['a', 'b', 'c'] as $value) { |
|
21
|
|
|
$this->assertContains($value, StringUtil::splitCommaSeparatedList('a , b, c ')); |
|
22
|
|
|
} |
|
23
|
|
|
$this->assertCount(3, StringUtil::splitCommaSeparatedList('a , b, c ')); |
|
24
|
|
|
$this->assertContains('${}', StringUtil::splitCommaSeparatedList('${}')); |
|
25
|
|
|
$this->assertContains('#{ }', StringUtil::splitCommaSeparatedList(' #{ } ')); |
|
26
|
|
|
foreach (['#{}', '${a}', '#{b}'] as $value) { |
|
27
|
|
|
$this->assertContains($value, StringUtil::splitCommaSeparatedList(' #{}, ${a}, #{b} ')); |
|
28
|
|
|
} |
|
29
|
|
|
$this->assertCount(3, StringUtil::splitCommaSeparatedList(' #{}, ${a}, #{b} ')); |
|
30
|
|
|
foreach (['a', '${b}', '#{c}'] as $value) { |
|
31
|
|
|
$this->assertContains($value, StringUtil::splitCommaSeparatedList(' a, ${b}, #{c} ')); |
|
32
|
|
|
} |
|
33
|
|
|
$this->assertCount(3, StringUtil::splitCommaSeparatedList(' a, ${b}, #{c} ')); |
|
34
|
|
|
foreach (['#{a}', 'b', 'c', '${d}'] as $value) { |
|
35
|
|
|
$this->assertContains($value, StringUtil::splitCommaSeparatedList(' #{a}, b, ,c ,${d} ')); |
|
36
|
|
|
} |
|
37
|
|
|
$this->assertCount(4, StringUtil::splitCommaSeparatedList(' #{a}, b, ,c ,${d} ')); |
|
38
|
|
|
foreach (['#{a(b,c)}', 'd', 'e', '${fg(h , i , j)}'] as $value) { |
|
39
|
|
|
$this->assertContains($value, StringUtil::splitCommaSeparatedList(' #{a(b,c)}, d, ,e ,${fg(h , i , j)} ')); |
|
40
|
|
|
} |
|
41
|
|
|
$this->assertCount(4, StringUtil::splitCommaSeparatedList(' #{a(b,c)}, d, ,e ,${fg(h , i , j)} ')); |
|
42
|
|
|
foreach (['#{a == (b, c)}', 'd = e', 'f', '${fg(h , i , j)}'] as $value) { |
|
43
|
|
|
$this->assertContains($value, StringUtil::splitCommaSeparatedList( |
|
44
|
|
|
' #{a == (b, c)}, d = e, f ,${fg(h , i , j)} ' |
|
45
|
|
|
)); |
|
46
|
|
|
} |
|
47
|
|
|
$this->assertCount(4, StringUtil::splitCommaSeparatedList(' #{a == (b, c)}, d = e, f ,${fg(h , i , j)} ')); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testStringListJoin(): void |
|
51
|
|
|
{ |
|
52
|
|
|
$this->assertNull(StringUtil::joinCommaSeparatedList(null)); |
|
53
|
|
|
$arr = []; |
|
54
|
|
|
$this->assertEquals('', StringUtil::joinCommaSeparatedList($arr)); |
|
55
|
|
|
$arr[] = 'a'; |
|
56
|
|
|
$this->assertEquals('a', StringUtil::joinCommaSeparatedList($arr)); |
|
57
|
|
|
$arr[] = 'b'; |
|
58
|
|
|
$this->assertEquals('a, b', StringUtil::joinCommaSeparatedList($arr)); |
|
59
|
|
|
$arr[] = '${a,b,c}'; |
|
60
|
|
|
$this->assertEquals('a, b, ${a,b,c}', StringUtil::joinCommaSeparatedList($arr)); |
|
61
|
|
|
$arr[] = 'foo'; |
|
62
|
|
|
$this->assertEquals('a, b, ${a,b,c}, foo', StringUtil::joinCommaSeparatedList($arr)); |
|
63
|
|
|
$arr[] = '#{bar(e,f,g)}'; |
|
64
|
|
|
$this->assertEquals('a, b, ${a,b,c}, foo, #{bar(e,f,g)}', StringUtil::joinCommaSeparatedList($arr)); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|