Skip to content

Commit

Permalink
Merge pull request #2191 from zephir-lang/#663-add-tests
Browse files Browse the repository at this point in the history
#663 - Add test case
  • Loading branch information
AlexNDRmac authored Apr 5, 2021
2 parents 6451f8a + 8dc6424 commit 96aa055
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
35 changes: 35 additions & 0 deletions stub/issue663.zep
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace Stub;

class Issue663
{
public static function is_array_assoc(arr) -> bool
{
if (!is_array(arr) || empty(arr)) {
return false;
}

return static::is_array_assoc_internal(arr);
}

private static function is_array_assoc_internal(array arr) -> bool
{
int count, i;
let count = count(arr);
for i in range(0, count - 1) {
if (!isset(arr[i])) {
return true;
}
}

return false;
}

public static function is_array_indexed(arr) -> bool
{
if (!is_array(arr) || empty(arr)) {
return false;
}

return !static::is_array_assoc_internal(arr);
}
}
39 changes: 39 additions & 0 deletions tests/Extension/Issue663Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/**
* This file is part of the Zephir.
*
* (c) Phalcon Team <[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Extension;

use PHPUnit\Framework\TestCase;
use Stub\Issue663;

final class Issue663Test extends TestCase
{
public function testIssue663(): void
{
$test = new Issue663();

$this->assertFalse($test->is_array_assoc(false));
$this->assertFalse($test->is_array_assoc(1));
$this->assertFalse($test->is_array_assoc([]));
$this->assertTrue($test->is_array_assoc(['test' => 'test']));
$this->assertFalse($test->is_array_assoc(['test']));
$this->assertFalse($test->is_array_assoc([0 => 'test']));

$this->assertFalse($test->is_array_indexed(false));
$this->assertFalse($test->is_array_indexed(1));
$this->assertFalse($test->is_array_indexed([]));
$this->assertFalse($test->is_array_indexed(['test' => 'test']));
$this->assertTrue($test->is_array_indexed(['test']));
$this->assertTrue($test->is_array_indexed([0 => 'test']));
}
}

0 comments on commit 96aa055

Please sign in to comment.