Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #579 from phel-lang/fix/578-native-global-array-push
Fix apush, aset and aunset for global php arrays
- Loading branch information
Showing
14 changed files
with
144 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
tests/php/Integration/Fixtures/Call/php-push-global-reference.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--PHEL-- | ||
(def arr (php/array 1 2 3)) | ||
(php/apush arr 4) | ||
--PHP-- | ||
\Phel\Lang\Registry::getInstance()->addDefinition( | ||
"user", | ||
"arr", | ||
array(1, 2, 3), | ||
\Phel\Lang\TypeFactory::getInstance()->persistentMapFromKVs( | ||
\Phel\Lang\Keyword::create("start-location"), \Phel\Lang\TypeFactory::getInstance()->persistentMapFromKVs( | ||
\Phel\Lang\Keyword::create("file"), "Call/php-push-global-reference.test", | ||
\Phel\Lang\Keyword::create("line"), 1, | ||
\Phel\Lang\Keyword::create("column"), 0 | ||
), | ||
\Phel\Lang\Keyword::create("end-location"), \Phel\Lang\TypeFactory::getInstance()->persistentMapFromKVs( | ||
\Phel\Lang\Keyword::create("file"), "Call/php-push-global-reference.test", | ||
\Phel\Lang\Keyword::create("line"), 1, | ||
\Phel\Lang\Keyword::create("column"), 27 | ||
) | ||
) | ||
); | ||
(\Phel\Lang\Registry::getInstance()->getDefinitionReference("user", "arr"))[] = 4; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
(php/apush arr 4)) | ||
--PHP-- | ||
$arr_1 = array(1, 2, 3); | ||
($arr_1)[] = 4; | ||
($arr_1)[] = 4; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhelTest\Unit\Lang; | ||
|
||
use Phel\Lang\Registry; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class RegistryTest extends TestCase | ||
{ | ||
private Registry $registry; | ||
|
||
public static function tearDownAfterClass(): void | ||
{ | ||
Registry::getInstance()->clear(); | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->registry = Registry::getInstance(); | ||
$this->registry->clear(); | ||
} | ||
|
||
public function test_null_when_non_existing_definition_by_value(): void | ||
{ | ||
$actual = $this->registry->getDefinition('ns', 'non-existing'); | ||
|
||
self::assertNull($actual); | ||
} | ||
|
||
public function test_value_definition(): void | ||
{ | ||
$this->registry->addDefinition('ns', 'array', [1, 2, 3]); | ||
$this->registry->getDefinition('ns', 'array')[] = 4; | ||
$actual = $this->registry->getDefinition('ns', 'array'); | ||
|
||
self::assertSame([1, 2, 3], $actual); | ||
} | ||
|
||
public function test_error_when_non_existing_definition_by_reference(): void | ||
{ | ||
$this->expectExceptionMessage('Only variables can be returned by reference'); | ||
|
||
$this->registry->getDefinitionReference('ns', 'non-existing'); | ||
} | ||
|
||
public function test_reference_definition(): void | ||
{ | ||
$this->registry->addDefinition('ns', 'array', [1, 2, 3]); | ||
$this->registry->getDefinitionReference('ns', 'array')[] = 4; | ||
$actual = $this->registry->getDefinition('ns', 'array'); | ||
|
||
self::assertSame([1, 2, 3, 4], $actual); | ||
} | ||
} |