Skip to content

Commit

Permalink
#1259 - Add failing test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Apr 19, 2021
1 parent 5433438 commit 7779437
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 1 deletion.
88 changes: 87 additions & 1 deletion ext/stub/arrayaccesstest.zep.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions ext/stub/arrayaccesstest.zep.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ext/stub/properties/staticprotectedproperties.zep.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions stub/arrayaccesstest.zep
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace Stub;
class ArrayAccessTest
{
protected data;
protected unsetData = ["key_a": "marcin", "key_b": "paula"];

public static function exits()
{
Expand Down Expand Up @@ -117,4 +118,33 @@ class ArrayAccessTest

return params;
}

/**
* @issue https://github.com/zephir-lang/zephir/issues/1259
*/
public function issue1259UnsetKeyFromArrayInternalVariable() -> array
{
array ret = [];
array unsetData = ["key_a": "marcin", "key_b": "paula"];

let ret[] = unsetData;
unset(unsetData["key_a"]);
let ret[] = unsetData;

return ret;
}

/**
* @issue https://github.com/zephir-lang/zephir/issues/1259
*/
public function issue1259UnsetKeyFromArrayProperty() -> array
{
array ret = [];

let ret[] = this->unsetData;
unset(this->unsetData["key_a"]);
let ret[] = this->unsetData;

return ret;
}
}
16 changes: 16 additions & 0 deletions tests/Extension/ArrayAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,20 @@ public function testIssue1086StaticallyCalledFunctionWithArrayAsArgMustReturnArr
$actual = $class->issue1086WontNullArrayAfterPassViaStaticWithoutStrictParams();
$this->assertSame(['test' => 123], $actual);
}

/**
* @issue https://github.com/zephir-lang/zephir/issues/1259
*/
public function testIssue1259CheckUnsetKeyFromArray(): void
{
$class = new \Stub\ArrayAccessTest();

$expected = [
['key_a' => 'marcin', 'key_b' => 'paula'],
['key_b' => 'paula'],
];

$this->assertSame($expected, $class->issue1259UnsetKeyFromArrayInternalVariable());
$this->assertSame($expected, $class->issue1259UnsetKeyFromArrayProperty());
}
}

0 comments on commit 7779437

Please sign in to comment.