Permalink
Browse files

Fix #830, added (int) case from variable - string

  • Loading branch information...
ovr committed May 7, 2015
1 parent 8499e7d commit 69c06dfa7ff106fe730b1de7c8df70c29b224e64
Showing with 100 additions and 33 deletions.
  1. +1 −0 Library/Operators/Other/CastOperator.php
  2. +28 −1 ext/test/cast.zep.c
  3. +10 −2 ext/test/cast.zep.h
  4. +28 −15 test/cast.zep
  5. +33 −15 unit-tests/Extension/CastTest.php
@@ -103,6 +103,7 @@ public function compile($expression, CompilationContext $compilationContext)
case 'array':
case 'variable':
case 'string':
return new CompiledExpression('int', 'zephir_get_intval(' . $symbolVariable->getName() . ')', $expression);
default:

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -9,73 +9,86 @@ class Cast
{
/** To int cast */
public function testIntCastFromFloat()
public function testIntCastFromFloat() -> int
{
return (int) 5.0;
}
public function testIntCastFromVariableFloat()
public function testIntCastFromVariableFloat() -> int
{
var a = 5.0;
return (int) a;
}
public function testIntCastFromBooleanTrue()
public function testIntCastFromBooleanTrue() -> int
{
return (int) true;
}
public function testIntCastFromBooleanFalse()
public function testIntCastFromBooleanFalse() -> int
{
return (int) false;
}
public function testIntCastFromVariableBooleanTrue()
public function testIntCastFromVariableBooleanTrue() -> int
{
var a = true;
return (int) a;
}
public function testIntCastFromVariableBooleanFalse()
public function testIntCastFromVariableBooleanFalse() -> int
{
var a = false;
return (int) a;
}
public function testIntCastFromVariableNull()
public function testIntCastFromVariableNull() -> int
{
var a = null;
return (int) a;
}
public function testIntCastFromString()
public function testIntCastFromStringValue() -> int
{
return (int) "test";
}
public function testIntCastFromNull()
public function testIntCastFromVariableString() -> int
{
string a;
let a = "test";
return (int) a;
}
public function testIntCastFromParameterString(const string a) -> int
{
return (int) a;
}
public function testIntCastFromNull() -> int
{
return (int) null;
}
public function testIntCastFromVariableEmptyArray()
public function testIntCastFromVariableEmptyArray() -> int
{
var a = [];
return (int) a;
}
public function testIntCastFromEmptyArray()
public function testIntCastFromEmptyArray() -> int
{
return (int) [];
}
public function testIntCastFromVariableArray()
public function testIntCastFromVariableArray() -> int
{
var a = [1, 2, 3, 4];
return (int) a;
}
public function testIntCastFromArray()
public function testIntCastFromArray() -> int
{
return (int) [1, 2, 3, 4];
}
@@ -84,7 +97,7 @@ class Cast
* Notice: Object of class stdClass could not be converted to int
* @return int 1
*/
public function testIntCastFromStdClass()
public function testIntCastFromStdClass() -> int
{
return (int) (new \StdClass);
}
@@ -93,7 +106,7 @@ class Cast
* Notice: Object of class stdClass could not be converted to int
* @return int 1
*/
public function testIntCastFromVariableStdClass()
public function testIntCastFromVariableStdClass() -> int
{
var a;
let a = new \StdClass;
@@ -27,21 +27,39 @@ public function testIntCast()
{
$t = new Cast();
$this->assertTrue($t->testIntCastFromFloat() === 5);
$this->assertTrue($t->testIntCastFromBooleanTrue() === 1);
$this->assertTrue($t->testIntCastFromBooleanFalse() === 0);
$this->assertTrue($t->testIntCastFromNull() === 0);
$this->assertTrue($t->testIntCastFromEmptyArray() === 0);
$this->assertTrue($t->testIntCastFromArray() === 1);
$this->assertTrue($t->testIntCastFromStdClass() === 1);
$this->assertTrue($t->testIntCastFromVariableFloat() === 5);
$this->assertTrue($t->testIntCastFromVariableBooleanTrue() === 1);
$this->assertTrue($t->testIntCastFromVariableBooleanFalse() === 0);
$this->assertTrue($t->testIntCastFromVariableNull() === 0);
$this->assertTrue($t->testIntCastFromVariableEmptyArray() === 0);
$this->assertTrue($t->testIntCastFromVariableArray() === 1);
$this->assertTrue($t->testIntCastFromVariableStdClass() === 1);
/**
* Value
*/
$this->assertSame(5, $t->testIntCastFromFloat());
$this->assertSame(1, $t->testIntCastFromBooleanTrue());
$this->assertSame(0, $t->testIntCastFromBooleanFalse());
$this->assertSame(0, $t->testIntCastFromNull());
$this->assertSame(0, $t->testIntCastFromStringValue());
$this->assertSame(0, $t->testIntCastFromEmptyArray());
$this->assertSame(1, $t->testIntCastFromArray());
$this->assertSame(1, $t->testIntCastFromStdClass());
/**
* Variable types
*/
$this->assertSame(5, $t->testIntCastFromVariableFloat());
$this->assertSame(1, $t->testIntCastFromVariableBooleanTrue());
$this->assertSame(0, $t->testIntCastFromVariableBooleanFalse());
$this->assertSame(0, $t->testIntCastFromVariableNull());
$this->assertSame(0, $t->testIntCastFromVariableString());
$this->assertSame((int) "test", $t->testIntCastFromParameterString("test"));
$this->assertSame((int) "1", $t->testIntCastFromParameterString("1"));
$this->assertSame((int) "12345", $t->testIntCastFromParameterString("12345"));
$this->assertSame((int) "-1", $t->testIntCastFromParameterString("-1"));
$this->assertSame((int) "+5", $t->testIntCastFromParameterString("+5"));
$this->assertSame(0, $t->testIntCastFromVariableEmptyArray());
$this->assertSame(1, $t->testIntCastFromVariableArray());
$this->assertSame(1, $t->testIntCastFromVariableStdClass());
}
public function testFloatCast()

0 comments on commit 69c06df

Please sign in to comment.