Skip to content

Commit

Permalink
Added initial test for #1494
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyklay committed Nov 2, 2019
1 parent fedc314 commit eb00f5b
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 6 deletions.
76 changes: 70 additions & 6 deletions test/spropertyaccess.zep
Expand Up @@ -10,6 +10,10 @@ class SPropertyAccess
private static b;
protected static delimiter = ".";
protected static _delimiterWithUnderscore = ".";
protected static stringVar = "";
protected static intVar = 0;
protected static doubleVar = 0.0;
protected static arrayVar = [];

public function __construct()
{
Expand All @@ -29,11 +33,71 @@ class SPropertyAccess
}

public function testArgument(var delimiter = null)
{
if empty delimiter {
let delimiter = self::delimiter;
}
{
if empty delimiter {
let delimiter = self::delimiter;
}

return delimiter;
}

/**
* @see https://github.com/phalcon/zephir/issues/1494
*/
public static function mutateStringVarInsideCycle() -> string
{
var i;

return delimiter;
}
for _ in range(0, 3) {
let i = " + ";
let self::stringVar = self::stringVar . i;
}

return self::stringVar;
}

/**
* @see https://github.com/phalcon/zephir/issues/1494
*/
public static function mutateIntVarInsideCycle() -> int
{
var i;

for _ in range(0, 3) {
let i = 2;
let self::intVar = self::intVar + i;
}

return self::intVar;
}

/**
* @see https://github.com/phalcon/zephir/issues/1494
*/
public static function mutateDoubleVarInsideCycle() -> double
{
var i;

for _ in range(0, 3) {
let i = 2.1;
let self::doubleVar = self::doubleVar + i;
}

return self::doubleVar;
}

/**
* @see https://github.com/phalcon/zephir/issues/1494
*/
public static function mutateArrayVarInsideCycle() -> array
{
var i;

for _ in range(0, 3) {
let i = [1];
let self::arrayVar = self::arrayVar + i;
}

return self::arrayVar;
}
}
48 changes: 48 additions & 0 deletions unit-tests/Extension/SPropertyAccessTest.php
Expand Up @@ -29,4 +29,52 @@ public function testStaticPropertyAccessWithUnderscore()
$this->assertSame($spa->testArgumentWithUnderscore(','), ',');
$this->assertSame($spa->testArgumentWithUnderscore(), '.');
}

/**
* @test
* @see https://github.com/phalcon/zephir/issues/1494
*/
public function shouldMutateStringVarInsideCycle()
{
$this->assertEquals(
str_repeat(' + ', 4),
SPropertyAccess::mutateStringVarInsideCycle()
);
}

/**
* @test
* @see https://github.com/phalcon/zephir/issues/1494
*/
public function shouldMutateIntVarInsideCycle()
{
$this->assertEquals(
8,
SPropertyAccess::mutateIntVarInsideCycle()
);
}

/**
* @test
* @see https://github.com/phalcon/zephir/issues/1494
*/
public function shouldMutateDoubleVarInsideCycle()
{
$this->assertEquals(
8.4,
SPropertyAccess::mutateDoubleVarInsideCycle()
);
}

/**
* @test
* @see https://github.com/phalcon/zephir/issues/1494
*/
public function shouldMutateArrayVarInsideCycle()
{
$this->assertEquals(
[0, 1, 2, 3],
SPropertyAccess::mutateArrayVarInsideCycle()
);
}
}

0 comments on commit eb00f5b

Please sign in to comment.