Skip to content

Commit 907120e

Browse files
committed
Add missing tests for splitWithOffset
1 parent dc2a617 commit 907120e

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
/*
4+
* This file is part of composer/pcre.
5+
*
6+
* (c) Composer <https://github.com/composer>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
namespace Composer\Pcre\PregTests;
13+
14+
use Composer\Pcre\BaseTestCase;
15+
use Composer\Pcre\Preg;
16+
17+
class SplitWithOffsetTest extends BaseTestCase
18+
{
19+
/**
20+
* This can be replaced with a setUp() method when appropriate
21+
*
22+
* @before
23+
* @return void
24+
*/
25+
public function registerFunctionName()
26+
{
27+
$this->pregFunction = 'preg_split()';
28+
}
29+
30+
/**
31+
* @return void
32+
*/
33+
public function testSuccess()
34+
{
35+
$result = Preg::splitWithOffset('{[\s,]+}', 'a, b, c');
36+
self::assertSame(array(array('a', 0), array('b', 3), array('c', 6)), $result);
37+
}
38+
39+
/**
40+
* @return void
41+
*/
42+
public function testFailure()
43+
{
44+
$result = Preg::splitWithOffset('{[\s,]+}', 'abc');
45+
self::assertSame(array(array('abc', 0)), $result);
46+
}
47+
48+
/**
49+
* @return void
50+
*/
51+
public function testBadPatternThrowsIfWarningsAreNotThrowing()
52+
{
53+
$this->expectPcreException($pattern = '{[\s,]+');
54+
@Preg::splitWithOffset($pattern, 'a, b, c');
55+
}
56+
57+
/**
58+
* @return void
59+
*/
60+
public function testBadPatternTriggersWarningByDefault()
61+
{
62+
$this->expectPcreWarning();
63+
Preg::splitWithOffset('{[\s,]+', 'a, b, c');
64+
}
65+
}

0 commit comments

Comments
 (0)