-
Notifications
You must be signed in to change notification settings - Fork 0
/
EditorTest.php
344 lines (256 loc) · 10.5 KB
/
EditorTest.php
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<?php /** @noinspection ALL */
namespace Placemat\Editor\Tests;
use PHPUnit\Framework\TestCase;
use Placemat\Editor\Editor;
class EditorTest extends TestCase
{
public $str = 'hellö world';
public function testCreate()
{
$str = Editor::create($this->str);
$this->assertInstanceOf(Editor::class, $str);
}
public function testStr()
{
$str = Editor::create($this->str)->str();
$this->assertInternalType('string', $str);
}
public function testAfter()
{
$after = Editor::create($this->str)->after('ö')->str();
$this->assertEquals(' world', $after);
}
public function testBefore()
{
$before = Editor::create($this->str)->before('ö')->str();
$this->assertEquals('hell', $before);
}
public function testStartWith()
{
$prefixed = Editor::create($this->str)->startWith('123á')->str();
$this->assertEquals('123áhellö world', $prefixed);
}
public function testFinishWith()
{
$suffixed = Editor::create($this->str)->finishWith('123á')->str();
$this->assertEquals('hellö world123á', $suffixed);
}
public function testLimitCharacters()
{
$limited = Editor::create($this->str)->limitCharacters(6)->str();
$this->assertEquals('hellö…', $limited);
}
public function testLimitWords()
{
$limited = Editor::create($this->str)->limitWords(1)->str();
$this->assertEquals('hellö…', $limited);
}
public function testPlural()
{
$this->assertTrue(true);
}
public function testSingular()
{
$this->assertTrue(true);
}
public function testReplace()
{
$replaced = Editor::create($this->str)->replace('hellö', 'göödbye')->str();
$this->assertEquals('göödbye world', $replaced);
}
public function testReplaceFirst()
{
$replaced = Editor::create($this->str)->replaceFirst('l', 'w')->str();
$this->assertEquals('hewlö world', $replaced);
}
public function testReplaceLast()
{
$replaced = Editor::create($this->str)->replaceLast('l', 'w')->str();
$this->assertEquals('hellö worwd', $replaced);
}
public function testReplaceSub()
{
$replaced = Editor::create($this->str)->replaceSub('💩', 0, 2)->str();
$this->assertEquals('💩llö world', $replaced);
}
public function testRemove()
{
$removed = Editor::create($this->str)->remove('ö')->str();
$this->assertEquals('hell world', $removed);
}
public function testRemoveFirst()
{
$removed = Editor::create($this->str)->removeFirst('l')->str();
$this->assertEquals('helö world', $removed);
}
public function testRemoveLast()
{
$removed = Editor::create($this->str)->removeLast('l')->str();
$this->assertEquals('hellö word', $removed);
}
public function testSlugify()
{
$slug = Editor::create($this->str)->slug()->str();
$this->assertEquals('hello-world', $slug);
}
public function testChunk()
{
$chunk = Editor::create($this->str)->chunk(2);
$this->assertEquals(['he', 'll', 'ö ', 'wo', 'rl', 'd'], $chunk);
}
public function testSplitWords()
{
$split = Editor::create($this->str)->splitWords();
$this->assertEquals(['hellö', 'world'], $split);
}
public function testSlice()
{
$sliced = Editor::create($this->str)->slice(1, 9)->str();
$this->assertEquals('ellö worl', $sliced);
}
public function testTrim()
{
$trimmed = Editor::create("\n " . $this->str . "\t ")->trim()->str();
$this->assertEquals($this->str, $trimmed);
}
public function testContains()
{
$contains = Editor::create($this->str)->contains('hellö');
$this->assertTrue($contains);
$contains = Editor::create($this->str)->contains('hello');
$this->assertFalse($contains);
}
public function testStartsWith()
{
$startsWith = Editor::create($this->str)->startsWith('hellö');
$this->assertTrue($startsWith);
$startsWith = Editor::create($this->str)->startsWith('hello');
$this->assertFalse($startsWith);
}
public function testEndsWith()
{
$endsWith = Editor::create($this->str)->endsWith('ö world');
$this->assertTrue($endsWith);
$endsWith = Editor::create($this->str)->endsWith('o world');
$this->assertFalse($endsWith);
}
public function testMatches()
{
$matches = Editor::create($this->str)->matches('*ö world');
$this->assertTrue($matches);
$matches = Editor::create($this->str)->matches('*o world');
$this->assertFalse($matches);
}
public function testLength()
{
$length = Editor::create($this->str)->length();
$this->assertInternalType('int', $length);
$this->assertEquals(11, $length);
}
public function testLowerCase()
{
$lower = Editor::create('HELLÖ WORLD')->lowerCase()->str();
$this->assertEquals($this->str, $lower);
}
public function testLowerCaseFirst()
{
$lower = Editor::create('HELLÖ WORLD')->lowerCaseFirst()->str();
$this->assertEquals('hELLÖ WORLD', $lower);
}
public function testLowerCaseWords()
{
$lower = Editor::create('HELLÖ WORLD')->lowerCaseWords()->str();
$this->assertEquals('hELLÖ wORLD', $lower);
}
public function testUpperCase()
{
$upper = Editor::create($this->str)->upperCase()->str();
$this->assertEquals('HELLÖ WORLD', $upper);
}
public function testUpperCaseFirst()
{
$upper = Editor::create($this->str)->upperCaseFirst()->str();
$this->assertEquals('Hellö world', $upper);
}
public function testUpperCaseWords()
{
$upper = Editor::create($this->str)->upperCaseWords()->str();
$this->assertEquals('Hellö World', $upper);
}
/**
* @dataProvider titleCaseProvider
*
* @param $str
* @param $expected
*/
public function testTitleCase($str, $expected, $ignore = [])
{
$title = Editor::create($str)->titleCase($ignore)->str();
$this->assertEquals($expected, $title);
}
public function testCamelCase()
{
$camel = Editor::create($this->str)->camelCase()->str();
$this->assertEquals('hellöWorld', $camel);
}
public function testStudlyCase()
{
$studly = Editor::create($this->str)->studlyCase()->str();
$this->assertEquals('HellöWorld', $studly);
}
public function testSnakeCase()
{
$snake = Editor::create($this->str)->snakeCase()->str();
$this->assertEquals('hellö_world', $snake);
}
public function testKebabCase()
{
$snake = Editor::create($this->str)->kebabCase()->str();
$this->assertEquals('hellö-world', $snake);
}
public function testAscii()
{
$ascii = Editor::create($this->str)->ascii()->str();
$this->assertEquals('hello world', $ascii);
}
public function titleCaseProvider()
{
return [
['TITLE CASE', 'Title Case'],
['testing the method', 'Testing the Method'],
['i like to watch DVDs at home', 'I Like to watch DVDs at Home', ['watch']],
[' Θα ήθελα να φύγει ', 'Θα Ήθελα Να Φύγει', []],
['For step-by-step directions email [email protected]', 'For Step-by-Step Directions Email [email protected]'],
["2lmc Spool: 'Gruber on OmniFocus and Vapo(u)rware'", "2lmc Spool: 'Gruber on OmniFocus and Vapo(u)rware'"],
['Have you read “The Lottery”?', 'Have You Read “The Lottery”?'],
['your hair[cut] looks (nice)', 'Your Hair[cut] Looks (Nice)'],
["People probably won't put http://foo.com/bar/ in titles", "People Probably Won't Put http://foo.com/bar/ in Titles"],
['Scott Moritz and TheStreet.com’s million iPhone la‑la land', 'Scott Moritz and TheStreet.com’s Million iPhone La‑La Land'],
['BlackBerry vs. iPhone', 'BlackBerry vs. iPhone'],
['Notes and observations regarding Apple’s announcements from ‘The Beat Goes On’ special event', 'Notes and Observations Regarding Apple’s Announcements From ‘The Beat Goes On’ Special Event'],
['Read markdown_rules.txt to find out how _underscores around words_ will be interpretted', 'Read markdown_rules.txt to Find Out How _Underscores Around Words_ Will Be Interpretted'],
["Q&A with Steve Jobs: 'That's what happens in technology'", "Q&A with Steve Jobs: 'That's What Happens in Technology'"],
["What is AT&T's problem?", "What Is AT&T's Problem?"],
['Apple deal with AT&T falls through', 'Apple Deal with AT&T Falls Through'],
['this v that', 'This v That'],
['this vs that', 'This vs That'],
['this v. that', 'This v. That'],
['this vs. that', 'This vs. That'],
["The SEC's Apple probe: what you need to know", "The SEC's Apple Probe: What You Need to Know"],
["'by the way, small word at the start but within quotes.'", "'By the Way, Small Word at the Start but Within Quotes.'"],
['Small word at end is nothing to be afraid of', 'Small Word at End Is Nothing to Be Afraid Of'],
['Starting sub-phrase with a small word: a trick, perhaps?', 'Starting Sub-Phrase with a Small Word: A Trick, Perhaps?'],
["Sub-phrase with a small word in quotes: 'a trick, perhaps?'", "Sub-Phrase with a Small Word in Quotes: 'A Trick, Perhaps?'"],
['Sub-phrase with a small word in quotes: "a trick, perhaps?"', 'Sub-Phrase with a Small Word in Quotes: "A Trick, Perhaps?"'],
['"Nothing to Be Afraid of?"', '"Nothing to Be Afraid Of?"'],
['a thing', 'A Thing'],
['Dr. Strangelove (or: how I Learned to Stop Worrying and Love the Bomb)', 'Dr. Strangelove (Or: How I Learned to Stop Worrying and Love the Bomb)'],
[' this is trimming', 'This Is Trimming'],
['this is trimming ', 'This Is Trimming'],
[' this is trimming ', 'This Is Trimming'],
['IF IT’S ALL CAPS, FIX IT', 'If It’s All Caps, Fix It'],
['What could/should be done about slashes?', 'What Could/Should Be Done About Slashes?'],
['Never touch paths like /var/run before/after /boot', 'Never Touch Paths Like /var/run Before/After /boot'],
];
}
}