Skip to content

Commit d1d4d96

Browse files
ronfroymihai-vlc
authored andcommitted
add digit method (#24)
* add digit method * composer bootstrap should not be fixed with php-cs-fixer * add digit unit test * php-cs-fixer must be a dev-dependency (no need in prod env)
1 parent 755a716 commit d1d4d96

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/vendor
22
composer.lock
33
/phpunit/
4+
.idea/

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ before_script:
1111
- composer install
1212
script:
1313
- vendor/bin/php-cs-fixer fix --level=psr2 --dry-run src
14-
- vendor/bin/php-cs-fixer fix --level=psr2 --dry-run tests
14+
- vendor/bin/php-cs-fixer fix --level=psr2 --dry-run tests/VerbalExpressionsTest.php

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"type": "project",
55
"description": "PHP Regular expressions made easy",
66
"require": {
7-
"php": ">=5.3",
8-
"fabpot/php-cs-fixer": "^1.11"
7+
"php": ">=5.3"
98
},
109
"require-dev": {
11-
"phpunit/phpunit": "* >=4"
10+
"phpunit/phpunit": "* >=4",
11+
"fabpot/php-cs-fixer": "^1.11"
1212
},
1313
"suggest": {
1414
"fabpot/php-cs-fixer": "PHP CS Fixer (testing for PSR-2 compliance)"

src/VerbalExpressions.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,19 @@ public function word()
247247
return $this->add('\\w+');
248248
}
249249

250+
/**
251+
* Digit
252+
*
253+
* Match any digit
254+
*
255+
* @access public
256+
* @return VerbalExpressions
257+
*/
258+
public function digit()
259+
{
260+
return $this->add('\\d');
261+
}
262+
250263
/**
251264
* List Chars
252265
*

tests/VerbalExpressionsTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,19 @@ public function testWord()
254254
$this->assertFalse($regex->test('a!b'));
255255
}
256256

257+
258+
public function testDigit()
259+
{
260+
$regex = new VerbalExpressions();
261+
$regex->digit();
262+
263+
$this->assertTrue($regex->test('0123456789'));
264+
265+
foreach (str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZ_-@,./%*') as $char) {
266+
$this->assertFalse($regex->test($char), 'Should not match digit ('.$char.')');
267+
}
268+
}
269+
257270
public function testAny()
258271
{
259272
$regex = new VerbalExpressions();

0 commit comments

Comments
 (0)