|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests; |
|
4
|
|
|
|
|
5
|
|
|
use LazyEight\BasicTypes\JString; |
|
6
|
|
|
use LazyEight\BasicTypes\Exceptions\IndexOutOfBoundsException; |
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
|
|
9
|
|
|
class StringTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var string |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $defaultString = 'TEST STRING'; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $stringyPrefix = 'TEST'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $stringySuffix = 'RING'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $stringyLowerCase = 'test string'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $errorStringy = 'ERROR STRING'; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $ignoreCase = 'teST strING'; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $ignoreCaseSuffix = 'rING'; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $concatFinalResult = 'TEST STRING CONCAT'; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @var string |
|
53
|
|
|
*/ |
|
54
|
|
|
protected $concatSuffix = ' CONCAT'; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @var string |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $trimTest = ' ABC '; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @var string |
|
63
|
|
|
*/ |
|
64
|
|
|
protected $trimmedTest = 'ABC'; |
|
65
|
|
|
|
|
66
|
|
|
public function setUp() |
|
67
|
|
|
{ |
|
68
|
|
|
parent::setUp(); // TODO: Change the autogenerated stub |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return \LazyEight\BasicTypes\JString |
|
73
|
|
|
*/ |
|
74
|
|
|
public function testCanConstructedByStringValue() |
|
75
|
|
|
{ |
|
76
|
|
|
$str = new JString($this->defaultString); |
|
77
|
|
|
$this->assertInstanceOf(JString::class, $str); |
|
78
|
|
|
return $str; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
83
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
84
|
|
|
*/ |
|
85
|
|
|
public function testCanBeConstructedByIntValue() |
|
86
|
|
|
{ |
|
87
|
|
|
$str = new JString(1); |
|
88
|
|
|
$this->assertInstanceOf(JString::class, $str); |
|
89
|
|
|
return $str; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
94
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
95
|
|
|
*/ |
|
96
|
|
|
public function testCanBeConstructedByTrueBoolValue() |
|
97
|
|
|
{ |
|
98
|
|
|
$str = new JString(true); |
|
99
|
|
|
$this->assertInstanceOf(JString::class, $str); |
|
100
|
|
|
return $str; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
105
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
106
|
|
|
*/ |
|
107
|
|
|
public function testCanBeCreatedByFalseBoolValue() |
|
108
|
|
|
{ |
|
109
|
|
|
$str = new JString(true); |
|
110
|
|
|
$this->assertInstanceOf(JString::class, $str); |
|
111
|
|
|
return $str; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
116
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
117
|
|
|
*/ |
|
118
|
|
|
public function testCantBeCreatedByNullValue() |
|
119
|
|
|
{ |
|
120
|
|
|
$this->expectException(\TypeError::class); |
|
121
|
|
|
(new JString(null)); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
126
|
|
|
* @covers \LazyEight\BasicTypes\JString::getValue |
|
127
|
|
|
* @depends testCanConstructedByStringValue |
|
128
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
129
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
130
|
|
|
*/ |
|
131
|
|
|
public function testValueCanBeRetrieved(JString $str) |
|
132
|
|
|
{ |
|
133
|
|
|
$this->assertEquals($this->defaultString, $str->getValue()); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
138
|
|
|
* @covers \LazyEight\BasicTypes\JString::equals |
|
139
|
|
|
* @depends testCanConstructedByStringValue |
|
140
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
141
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
142
|
|
|
*/ |
|
143
|
|
|
public function testEqualsMethodOnTrue(JString $str) |
|
144
|
|
|
{ |
|
145
|
|
|
$this->assertTrue($str->equals($this->defaultString)); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
150
|
|
|
* @covers \LazyEight\BasicTypes\JString::equals |
|
151
|
|
|
* @depends testCanConstructedByStringValue |
|
152
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
153
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
154
|
|
|
*/ |
|
155
|
|
|
public function testEqualsMethodOnFalse(JString $str) |
|
156
|
|
|
{ |
|
157
|
|
|
$this->assertFalse($str->equals($this->errorStringy)); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
162
|
|
|
* @covers \LazyEight\BasicTypes\JString::equals |
|
163
|
|
|
* @depends testCanConstructedByStringValue |
|
164
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
165
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
166
|
|
|
*/ |
|
167
|
|
|
public function testEqualsMethodNullValue(JString $str) |
|
168
|
|
|
{ |
|
169
|
|
|
$this->expectException(\TypeError::class); |
|
170
|
|
|
$this->assertFalse($str->equals(null)); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
175
|
|
|
* @covers \LazyEight\BasicTypes\JString::equalsIgnoreCase |
|
176
|
|
|
* @depends testCanConstructedByStringValue |
|
177
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
178
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
179
|
|
|
*/ |
|
180
|
|
|
public function testEqualsIgnoreCaseMethodOnTrue(JString $str) |
|
181
|
|
|
{ |
|
182
|
|
|
$this->assertTrue($str->equalsIgnoreCase($this->ignoreCase)); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
187
|
|
|
* @covers \LazyEight\BasicTypes\JString::equalsIgnoreCase |
|
188
|
|
|
* @depends testCanConstructedByStringValue |
|
189
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
190
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
191
|
|
|
*/ |
|
192
|
|
|
public function testEqualsIgnoreCaseMethodOnFalse(JString $str) |
|
193
|
|
|
{ |
|
194
|
|
|
$this->assertFalse($str->equalsIgnoreCase($this->errorStringy)); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
199
|
|
|
* @covers \LazyEight\BasicTypes\JString::equalsIgnoreCase |
|
200
|
|
|
* @depends testCanConstructedByStringValue |
|
201
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
202
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
203
|
|
|
*/ |
|
204
|
|
|
public function testEqualsIgnoreCaseMethodOnNull(JString $str) |
|
205
|
|
|
{ |
|
206
|
|
|
$this->expectException(\TypeError::class); |
|
207
|
|
|
$this->assertFalse($str->equalsIgnoreCase(null)); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
212
|
|
|
* @covers \LazyEight\BasicTypes\JString::length |
|
213
|
|
|
* @depends testCanConstructedByStringValue |
|
214
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
215
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
216
|
|
|
*/ |
|
217
|
|
|
public function testLengthMethodOnTrue(JString $str) |
|
218
|
|
|
{ |
|
219
|
|
|
$this->assertTrue($str->length() == mb_strlen($this->defaultString)); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
224
|
|
|
* @covers \LazyEight\BasicTypes\JString::length |
|
225
|
|
|
* @depends testCanConstructedByStringValue |
|
226
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
227
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
228
|
|
|
*/ |
|
229
|
|
|
public function testLengthMethodOnFalse(JString $str) |
|
230
|
|
|
{ |
|
231
|
|
|
$this->assertFalse($str->length() == mb_strlen($this->errorStringy)); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
236
|
|
|
* @covers \LazyEight\BasicTypes\JString::concat |
|
237
|
|
|
* @depends testCanConstructedByStringValue |
|
238
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
239
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
240
|
|
|
* @return \LazyEight\BasicTypes\JString |
|
241
|
|
|
*/ |
|
242
|
|
|
public function testConcatMethod(JString $str) |
|
243
|
|
|
{ |
|
244
|
|
|
$strTest = $str->concat($this->concatSuffix); |
|
245
|
|
|
$this->assertEquals($this->concatFinalResult, $strTest); |
|
246
|
|
|
$this->assertNotEquals($str->concat('ABC'), $this->defaultString); |
|
247
|
|
|
return new JString($strTest); |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
252
|
|
|
* @covers \LazyEight\BasicTypes\JString::contains |
|
253
|
|
|
* @depends testConcatMethod |
|
254
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
255
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
256
|
|
|
*/ |
|
257
|
|
|
public function testContainsMethodOnTrue(JString $str) |
|
258
|
|
|
{ |
|
259
|
|
|
$this->assertTrue($str->contains($this->concatSuffix)); |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
264
|
|
|
* @covers \LazyEight\BasicTypes\JString::contains |
|
265
|
|
|
* @depends testConcatMethod |
|
266
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
267
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
268
|
|
|
*/ |
|
269
|
|
|
public function testContainsMethodOnFalse(JString $str) |
|
270
|
|
|
{ |
|
271
|
|
|
$this->assertFalse($str->contains($this->errorStringy)); |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
/** |
|
275
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
276
|
|
|
* @covers \LazyEight\BasicTypes\JString::contains |
|
277
|
|
|
* @depends testConcatMethod |
|
278
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
279
|
|
|
* @expectedException \TypeError |
|
280
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
281
|
|
|
*/ |
|
282
|
|
|
public function testContainsNull(JString $str) |
|
283
|
|
|
{ |
|
284
|
|
|
$this->expectException(\TypeError::class); |
|
285
|
|
|
$this->assertFalse($str->contains(null)); |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
/** |
|
289
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
290
|
|
|
* @covers \LazyEight\BasicTypes\JString::endsWith |
|
291
|
|
|
* @depends testCanConstructedByStringValue |
|
292
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
293
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
294
|
|
|
*/ |
|
295
|
|
|
public function testEndsWith(JString $str) |
|
296
|
|
|
{ |
|
297
|
|
|
$this->assertTrue($str->endsWith($this->stringySuffix)); |
|
298
|
|
|
$this->assertFalse($str->endsWith($this->ignoreCaseSuffix)); |
|
299
|
|
|
$this->assertTrue($str->endsWith($this->ignoreCaseSuffix, false)); |
|
300
|
|
|
$this->assertFalse($str->endsWith($this->concatSuffix, false)); |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
/** |
|
304
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
305
|
|
|
* @covers \LazyEight\BasicTypes\JString::startsWith |
|
306
|
|
|
* @depends testCanConstructedByStringValue |
|
307
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
308
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
309
|
|
|
*/ |
|
310
|
|
|
public function testStartsWith(JString $str) |
|
311
|
|
|
{ |
|
312
|
|
|
$this->assertTrue($str->startsWith($this->stringyPrefix)); |
|
313
|
|
|
$this->assertFalse($str->startsWith($this->stringySuffix)); |
|
314
|
|
|
$this->assertTrue($str->startsWith($this->stringySuffix, 7)); |
|
315
|
|
|
$this->assertFalse($str->startsWith($this->stringySuffix, 1)); |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
/** |
|
319
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
320
|
|
|
* @covers \LazyEight\BasicTypes\JString::charAt |
|
321
|
|
|
* @depends testCanConstructedByStringValue |
|
322
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
323
|
|
|
* @expectedException \LazyEight\BasicTypes\Exceptions\IndexOutOfBoundsException |
|
324
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
325
|
|
|
*/ |
|
326
|
|
|
public function testChartAt(JString $str) |
|
327
|
|
|
{ |
|
328
|
|
|
$indexToSearch = 3; |
|
329
|
|
|
$this->assertEquals($str->charAt($indexToSearch), mb_substr($str->getValue(), $indexToSearch, 1)); |
|
330
|
|
|
$this->assertNotEquals($str->charAt($indexToSearch), mb_substr($str->getValue(), 1, 1)); |
|
331
|
|
|
|
|
332
|
|
|
$this->expectException(IndexOutOfBoundsException::class); |
|
333
|
|
|
$str->charAt($str->length() + 1); |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
/** |
|
337
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
338
|
|
|
* @covers \LazyEight\BasicTypes\JString::indexOf |
|
339
|
|
|
* @depends testCanConstructedByStringValue |
|
340
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
341
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
342
|
|
|
*/ |
|
343
|
|
|
public function testIndexOf(JString $str) |
|
344
|
|
|
{ |
|
345
|
|
|
$offSet = 4; |
|
346
|
|
|
$suffixIndexStarts = mb_strpos($str->getValue(), $this->stringySuffix); |
|
347
|
|
|
$prefixIndexStarts = mb_strpos($str->getValue(), $this->stringyPrefix); |
|
348
|
|
|
$suffixIndexOffSet = mb_strpos($str->getValue(), $this->stringySuffix, $offSet); |
|
349
|
|
|
|
|
350
|
|
|
$this->assertEquals($str->indexOf($this->stringySuffix), $suffixIndexStarts); |
|
351
|
|
|
$this->assertNotEquals($str->indexOf($this->stringySuffix), $prefixIndexStarts); |
|
352
|
|
|
$this->assertEquals($str->indexOf($this->stringySuffix, $offSet), $suffixIndexOffSet); |
|
353
|
|
|
$this->assertNotEquals($str->indexOf($this->stringySuffix, $offSet), $prefixIndexStarts); |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
|
|
/** |
|
357
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
358
|
|
|
* @covers \LazyEight\BasicTypes\JString::isEmpty |
|
359
|
|
|
* @depends testCanConstructedByStringValue |
|
360
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
361
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
362
|
|
|
*/ |
|
363
|
|
|
public function testisEmpty(JString $str) |
|
364
|
|
|
{ |
|
365
|
|
|
$emptyString = new JString(''); |
|
366
|
|
|
$this->assertFalse($str->isEmpty()); |
|
367
|
|
|
$this->assertTrue($emptyString->isEmpty()); |
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
|
|
/** |
|
371
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
372
|
|
|
* @covers \LazyEight\BasicTypes\JString::toLowerCase |
|
373
|
|
|
* @depends testCanConstructedByStringValue |
|
374
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
375
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
376
|
|
|
*/ |
|
377
|
|
|
public function testToLowerCase(JString $str) |
|
378
|
|
|
{ |
|
379
|
|
|
$this->assertEquals($str->toLowerCase(), $this->stringyLowerCase); |
|
380
|
|
|
$this->assertNotEquals($str->toLowerCase(), $this->defaultString); |
|
381
|
|
|
} |
|
382
|
|
|
|
|
383
|
|
|
/** |
|
384
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
385
|
|
|
* @covers \LazyEight\BasicTypes\JString::toUpperCase |
|
386
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
387
|
|
|
*/ |
|
388
|
|
|
public function testToUpperCase() |
|
389
|
|
|
{ |
|
390
|
|
|
$strToBeUpperCase = new JString($this->stringyLowerCase); |
|
391
|
|
|
$this->assertEquals($strToBeUpperCase->toUpperCase(), $this->defaultString); |
|
392
|
|
|
$this->assertNotEquals($strToBeUpperCase->toUpperCase(), $this->stringyLowerCase); |
|
393
|
|
|
} |
|
394
|
|
|
|
|
395
|
|
|
/** |
|
396
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
397
|
|
|
* @covers \LazyEight\BasicTypes\JString::trim |
|
398
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
399
|
|
|
*/ |
|
400
|
|
|
public function testTrim() |
|
401
|
|
|
{ |
|
402
|
|
|
$strToBeTrimmed = new JString($this->trimTest); |
|
403
|
|
|
$this->assertEquals($strToBeTrimmed->trim(), $this->trimmedTest); |
|
404
|
|
|
$this->assertNotEquals($strToBeTrimmed->trim(), $this->trimTest); |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
/** |
|
408
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
409
|
|
|
* @covers \LazyEight\BasicTypes\JString::__toString |
|
410
|
|
|
* @depends testCanConstructedByStringValue |
|
411
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
412
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
413
|
|
|
*/ |
|
414
|
|
|
public function testToString(JString $str) |
|
415
|
|
|
{ |
|
416
|
|
|
$this->assertEquals($str->__toString(), $this->defaultString); |
|
417
|
|
|
$this->assertNotEquals($str->__toString(), $this->errorStringy); |
|
418
|
|
|
} |
|
419
|
|
|
|
|
420
|
|
|
/** |
|
421
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
422
|
|
|
* @covers \LazyEight\BasicTypes\JString::split |
|
423
|
|
|
* @depends testCanConstructedByStringValue |
|
424
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
425
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
426
|
|
|
*/ |
|
427
|
|
|
public function testSplit(JString $str) |
|
428
|
|
|
{ |
|
429
|
|
|
$subset = mb_split(' ', $this->defaultString); |
|
430
|
|
|
$this->assertArraySubset($subset, $str->split(' ')); |
|
431
|
|
|
$this->assertTrue(count($subset) == 2); |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
/** |
|
435
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
436
|
|
|
* @covers \LazyEight\BasicTypes\JString::substring |
|
437
|
|
|
* @depends testCanConstructedByStringValue |
|
438
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
439
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
440
|
|
|
*/ |
|
441
|
|
|
public function testSubstring(JString $str) |
|
442
|
|
|
{ |
|
443
|
|
|
$this->assertEquals($str->substring(0, 3), $this->stringyPrefix); |
|
444
|
|
|
$this->assertEquals($str->substring(7), $this->stringySuffix); |
|
445
|
|
|
$this->assertNotEquals($str->substring(0, 3), $this->stringySuffix); |
|
446
|
|
|
} |
|
447
|
|
|
|
|
448
|
|
|
/** |
|
449
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
450
|
|
|
* @covers \LazyEight\BasicTypes\JString::replace |
|
451
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
452
|
|
|
*/ |
|
453
|
|
|
public function testReplace() |
|
454
|
|
|
{ |
|
455
|
|
|
$strToTest = new JString($this->trimTest); |
|
456
|
|
|
$this->assertEquals($this->trimmedTest, $strToTest->replace(' ', '')); |
|
457
|
|
|
$this->assertEquals(new JString(' A0C '), $strToTest->replace('B', '0')); |
|
458
|
|
|
$this->assertNotEquals(new JString(' A0C '), $strToTest->replace('B', 'H')); |
|
459
|
|
|
} |
|
460
|
|
|
|
|
461
|
|
|
/** |
|
462
|
|
|
* @covers \LazyEight\BasicTypes\JString::__construct |
|
463
|
|
|
* @covers \LazyEight\BasicTypes\JString::lastIndexOf |
|
464
|
|
|
* @depends testCanConstructedByStringValue |
|
465
|
|
|
* @uses \LazyEight\BasicTypes\JString |
|
466
|
|
|
* @param \LazyEight\BasicTypes\JString $str |
|
467
|
|
|
*/ |
|
468
|
|
|
public function testLastIndexOf(JString $str) |
|
469
|
|
|
{ |
|
470
|
|
|
$this->assertEquals($str->lastIndexOf('T'), 6); |
|
471
|
|
|
$this->assertNotEquals($str->lastIndexOf('T'), 8); |
|
472
|
|
|
$this->assertEquals($str->lastIndexOf('G'), ($str->length() - 1)); |
|
473
|
|
|
$this->assertEquals($str->lastIndexOf('T', 7), 6); |
|
474
|
|
|
$this->assertNotEquals($str->lastIndexOf('T', 7), 0); |
|
475
|
|
|
$this->assertEquals($str->lastIndexOf('T', 2), 0); |
|
476
|
|
|
} |
|
477
|
|
|
} |
|
478
|
|
|
|