forked from phpgearbox/string
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveTest.php
More file actions
95 lines (88 loc) · 3.33 KB
/
Copy pathRemoveTest.php
File metadata and controls
95 lines (88 loc) · 3.33 KB
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
90
91
92
93
94
95
<?php
use Gears\String\Str;
class RemoveTest extends PHPUnit_Framework_TestCase
{
/**
* @dataProvider removeLeftProvider()
*/
public function testRemoveLeft($expected, $string, $substring, $encoding = null)
{
$str = new Str($string, $encoding);
$result = $str->removeLeft($substring);
$this->assertInstanceOf('Gears\\String\\Str', $result);
$this->assertEquals($expected, $result);
$this->assertEquals($string, $str);
}
public function removeLeftProvider()
{
return array
(
array('foo bar', 'foo bar', ''),
array('oo bar', 'foo bar', 'f'),
array('bar', 'foo bar', 'foo '),
array('foo bar', 'foo bar', 'oo'),
array('foo bar', 'foo bar', 'oo bar'),
array('fòô bàř', 'fòô bàř', '', 'UTF-8'),
array('òô bàř', 'fòô bàř', 'f', 'UTF-8'),
array('bàř', 'fòô bàř', 'fòô ', 'UTF-8'),
array('fòô bàř', 'fòô bàř', 'òô', 'UTF-8'),
array('fòô bàř', 'fòô bàř', 'òô bàř', 'UTF-8')
);
}
/**
* @dataProvider removeRightProvider()
*/
public function testRemoveRight($expected, $string, $substring, $encoding = null)
{
$str = new Str($string, $encoding);
$result = $str->removeRight($substring);
$this->assertInstanceOf('Gears\\String\\Str', $result);
$this->assertEquals($expected, $result);
$this->assertEquals($string, $str);
}
public function removeRightProvider()
{
return array
(
array('foo bar', 'foo bar', ''),
array('foo ba', 'foo bar', 'r'),
array('foo', 'foo bar', ' bar'),
array('foo bar', 'foo bar', 'ba'),
array('foo bar', 'foo bar', 'foo ba'),
array('fòô bàř', 'fòô bàř', '', 'UTF-8'),
array('fòô bà', 'fòô bàř', 'ř', 'UTF-8'),
array('fòô', 'fòô bàř', ' bàř', 'UTF-8'),
array('fòô bàř', 'fòô bàř', 'bà', 'UTF-8'),
array('fòô bàř', 'fòô bàř', 'fòô bà', 'UTF-8')
);
}
/**
* @dataProvider removeWhitespaceProvider()
*/
public function testRemoveWhitespace($expected, $string, $encoding = null)
{
$str = new Str($string, $encoding);
$result = $str->removeWhitespace();
$this->assertInstanceOf('Gears\\String\\Str', $result);
$this->assertEquals($expected, $result);
$this->assertEquals($string, $str);
}
public function removeWhitespaceProvider()
{
return array
(
array('foo bar', ' foo bar '),
array('test string', 'test string'),
array('Ο συγγραφέας', ' Ο συγγραφέας '),
array('123', ' 123 '),
array('', ' ', 'UTF-8'), // no-break space (U+00A0)
array('', ' ', 'UTF-8'), // spaces U+2000 to U+200A
array('', ' ', 'UTF-8'), // narrow no-break space (U+202F)
array('', ' ', 'UTF-8'), // medium mathematical space (U+205F)
array('', ' ', 'UTF-8'), // ideographic space (U+3000)
array('1 2 3', ' 1 2 3 ', 'UTF-8'),
array('', ' '),
array('', '')
);
}
}