[kahlan:api/core/Checker] tests + fixed Checker (array single type vs. array complex type)
This commit is contained in:
parent
3c61e63af1
commit
4eb873a182
|
@ -48,16 +48,12 @@
|
|||
|
||||
/* [2] Si de type ARRAY(type_elements)
|
||||
=========================================================*/
|
||||
if( preg_match('/^array(?:<(.+)>)?$/', $type, $match) ){
|
||||
if( preg_match('/^array(?:<(.+)>)$/', $type, $match) ){
|
||||
|
||||
// Si c'est pas un tableau on retourne une erreur
|
||||
if( !is_array($value) )
|
||||
return false;
|
||||
|
||||
// Si c'est un tableau et que 'array' recu
|
||||
if( $type == 'array' )
|
||||
return true;
|
||||
|
||||
$elements_type = $match[1];
|
||||
|
||||
// On verifie le type pour chaque element
|
||||
|
|
|
@ -775,7 +775,7 @@
|
|||
|
||||
/* (17) Array
|
||||
---------------------------------------------------------*/
|
||||
context('* array', function(){
|
||||
context('* array<subtype>', function(){
|
||||
|
||||
it('pass when empty array', function(){
|
||||
|
||||
|
@ -783,7 +783,7 @@
|
|||
|
||||
expect($arr)->toBeA('array');
|
||||
expect($arr)->toBeEmpty();
|
||||
expect(Checker::run('array', $arr))->toBeTruthy();
|
||||
expect(Checker::run('array<mixed>', $arr))->toBeTruthy();
|
||||
|
||||
});
|
||||
|
||||
|
@ -800,6 +800,17 @@
|
|||
|
||||
});
|
||||
|
||||
it('fail when empty array (single type \'array\')', function(){
|
||||
|
||||
$arr = [];
|
||||
|
||||
expect($arr)->toBeA('array');
|
||||
expect($arr)->toBeEmpty();
|
||||
|
||||
expect(Checker::run('array', $arr))->toBeFalsy();
|
||||
|
||||
});
|
||||
|
||||
it('pass when recursive empty arrays', function(){
|
||||
|
||||
$arr = [[], []];
|
||||
|
@ -810,9 +821,22 @@
|
|||
expect($arr[0])->toBeEmpty();
|
||||
expect($arr[1])->toBeEmpty();
|
||||
|
||||
expect(Checker::run('array', $arr))->toBeTruthy();
|
||||
expect(Checker::run('array<mixed>', $arr))->toBeTruthy();
|
||||
expect(Checker::run('array<array>', $arr))->toBeTruthy();
|
||||
expect(Checker::run('array<array<mixed>>', $arr))->toBeTruthy();
|
||||
|
||||
});
|
||||
|
||||
it('fail when recursive empty arrays (array<array>)', function(){
|
||||
|
||||
$arr = [[], []];
|
||||
|
||||
expect($arr)->toBeA('array');
|
||||
expect($arr[0])->toBeA('array');
|
||||
expect($arr[1])->toBeA('array');
|
||||
expect($arr[0])->toBeEmpty();
|
||||
expect($arr[1])->toBeEmpty();
|
||||
|
||||
expect(Checker::run('array<array>', $arr))->toBeFalsy();
|
||||
|
||||
});
|
||||
|
||||
|
@ -824,7 +848,6 @@
|
|||
expect(Checker::run('id', $id))->toBeTruthy();
|
||||
|
||||
expect($arr)->toBeA('array');
|
||||
expect(Checker::run('array', $arr))->toBeTruthy();
|
||||
expect(Checker::run('array<mixed>', $arr))->toBeTruthy();
|
||||
expect(Checker::run('array<id>', $arr))->toBeTruthy();
|
||||
|
||||
|
|
Loading…
Reference in New Issue