Skip to content

Commit

Permalink
Add test cases for HackArrDVArrs
Browse files Browse the repository at this point in the history
Summary:
Add test cases for the HackArrDVArrs option. These test cases are cloned from
the normal d/varray test cases (with a few low value omissions), with
HackArrDVArrs enabled, and the expect files modified as needed.

Reviewed By: paulbiss

Differential Revision: D6970274

fbshipit-source-id: b95de146631c319118fa3b5141e0d914ed5f941f
  • Loading branch information
ricklavoie authored and hhvm-bot committed Feb 15, 2018
1 parent 68269b3 commit 9f9d44f
Show file tree
Hide file tree
Showing 104 changed files with 10,990 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hphp/test/slow/dv_array/hhbbc4.php
Expand Up @@ -6,7 +6,7 @@ private static function get(): varray<string> {
return varray['SP', 'PP', 'SP2', 'PP2', 'I'];
}

public async function gen(): Awaitable<array> {
public async function gen(): Awaitable<darray> {
$x = darray[];
foreach (self::get() as $t) $x[$t] = 'N/A';
return $x;
Expand Down
55 changes: 55 additions & 0 deletions hphp/test/slow/dv_array/xhp.php
@@ -0,0 +1,55 @@
<?hh

abstract class :base {
// This is necessary because the generated __xhpAttributeDeclaration() has a
// call to parent::__xhpAttributeDeclaration().
protected static function __xhpAttributeDeclaration() {
return darray[];
}

public static function xhpAttributeDeclaration() {
return static::__xhpAttributeDeclaration();
}
}

class :node1 extends :base {
attribute
mixed checkme;
}

class :node2 extends :base {
attribute
Exception e,
mixed checkme;
}

class :node3 extends :base {
attribute
int num,
mixed checkme,
var beans,
string cheese;
}

class :node4 extends :base {
attribute
int num = 2,
mixed checkme,
var beans,
string cheese = "hi";
}

function test($x) {
echo "====================================================\n";
var_dump($x);
var_dump(is_array($x));
var_dump(is_varray($x));
var_dump(is_darray($x));
var_dump(is_vec($x));
var_dump(is_dict($x));
}

test(:node1::xhpAttributeDeclaration());
test(:node2::xhpAttributeDeclaration());
test(:node3::xhpAttributeDeclaration());
test(:node4::xhpAttributeDeclaration());
153 changes: 153 additions & 0 deletions hphp/test/slow/dv_array/xhp.php.expect
@@ -0,0 +1,153 @@
====================================================
array(1) {
["checkme"]=>
array(4) {
[0]=>
int(6)
[1]=>
NULL
[2]=>
NULL
[3]=>
int(0)
}
}
bool(true)
bool(false)
bool(true)
bool(false)
bool(false)
====================================================
array(2) {
["e"]=>
array(4) {
[0]=>
int(5)
[1]=>
string(9) "Exception"
[2]=>
NULL
[3]=>
int(0)
}
["checkme"]=>
array(4) {
[0]=>
int(6)
[1]=>
NULL
[2]=>
NULL
[3]=>
int(0)
}
}
bool(true)
bool(false)
bool(true)
bool(false)
bool(false)
====================================================
array(4) {
["num"]=>
array(4) {
[0]=>
int(3)
[1]=>
NULL
[2]=>
NULL
[3]=>
int(0)
}
["checkme"]=>
array(4) {
[0]=>
int(6)
[1]=>
NULL
[2]=>
NULL
[3]=>
int(0)
}
["beans"]=>
array(4) {
[0]=>
int(6)
[1]=>
NULL
[2]=>
NULL
[3]=>
int(0)
}
["cheese"]=>
array(4) {
[0]=>
int(1)
[1]=>
NULL
[2]=>
NULL
[3]=>
int(0)
}
}
bool(true)
bool(false)
bool(true)
bool(false)
bool(false)
====================================================
array(4) {
["num"]=>
array(4) {
[0]=>
int(3)
[1]=>
NULL
[2]=>
int(2)
[3]=>
int(0)
}
["checkme"]=>
array(4) {
[0]=>
int(6)
[1]=>
NULL
[2]=>
NULL
[3]=>
int(0)
}
["beans"]=>
array(4) {
[0]=>
int(6)
[1]=>
NULL
[2]=>
NULL
[3]=>
int(0)
}
["cheese"]=>
array(4) {
[0]=>
int(1)
[1]=>
NULL
[2]=>
string(2) "hi"
[3]=>
int(0)
}
}
bool(true)
bool(false)
bool(true)
bool(false)
bool(false)
86 changes: 86 additions & 0 deletions hphp/test/slow/dv_array_hack_arr/apc.inc
@@ -0,0 +1,86 @@
<?hh
// Copyright 2004-present Facebook. All Rights Reserved.

function fail($a, $a2) {
echo "=========== Comparison Failure ==========\n";
var_dump($a);
var_dump(is_varray($a));
var_dump(is_darray($a));
var_dump(is_array($a));
var_dump(is_vec($a));
var_dump(is_dict($a));

var_dump($a2);
var_dump(is_varray($a2));
var_dump(is_darray($a2));
var_dump(is_array($a2));
var_dump(is_vec($a2));
var_dump(is_dict($a2));
}

function get($key, $a) {
$a2 = apc_fetch($key);
if ($a2 === false) {
echo "=============== Error fetching $key ==============\n";
return;
}
if ($a !== $a2) {
if (count($a) != count($a2) ||
count($a) == 0 ||
!is_object($a[0]) ||
!is_object($a2[0])) {
return fail($a, $a2);
}
}
if (is_varray($a) !== is_varray($a2)) return fail($a, $a2);
if (is_darray($a) !== is_darray($a2)) return fail($a, $a2);
if (is_array($a) !== is_array($a2)) return fail($a, $a2);
if (is_vec($a) !== is_vec($a2)) return fail($a, $a2);
if (is_dict($a) !== is_dict($a2)) return fail($a, $a2);
}

function set_all($values) {
foreach ($values as $k => $v) apc_store($k, $v);
}

function get_all($values) {
foreach ($values as $k => $v) get($k, $v);
}

function launder($v) { return __hhvm_intrinsics\launder_value($v); }

function make_circular_varray() {
$x = new stdclass;
$v = varray[$x];
$x->foo = $v;
return $v;
}

function make_circular_darray() {
$x = new stdclass;
$d = darray[0 => $x];
$x->foo = $d;
return $d;
}

$values = dict[
'varray1' => varray[],
'varray2' => varray[1, 2, 3],
'varray3' => varray['a', 'b', 'c'],
'varray4' => varray[launder(7), launder(8), launder(9)],
'varray5' => make_circular_varray(),
'darray1' => darray[],
'darray2' => darray[0 => 'a', 1 => 'b', 2 => 'c'],
'darray3' => darray['a' => 100, 'b' => 200],
'darray4' => darray[0 => launder('x'), 1 => launder('y'), 2 => launder('z')],
'darray5' => darray[launder('j') => 11, launder('k') => 222],
'darray6' => make_circular_darray()
];

if (apc_fetch('second-time') === false) {
set_all($values);
apc_store('second-time', true);
} else {
get_all($values);
echo "============ DONE ================\n";
}
4 changes: 4 additions & 0 deletions hphp/test/slow/dv_array_hack_arr/apc1.php
@@ -0,0 +1,4 @@
<?hh
// Copyright 2004-present Facebook. All Rights Reserved.

include 'apc.inc';
1 change: 1 addition & 0 deletions hphp/test/slow/dv_array_hack_arr/apc1.php.expect
@@ -0,0 +1 @@
============ DONE ================
1 change: 1 addition & 0 deletions hphp/test/slow/dv_array_hack_arr/apc1.php.hphp_opts
@@ -0,0 +1 @@
-vHackArrDVArrs=1
2 changes: 2 additions & 0 deletions hphp/test/slow/dv_array_hack_arr/apc1.php.opts
@@ -0,0 +1,2 @@
-vEval.HackArrDVArrs=true
--count=2
4 changes: 4 additions & 0 deletions hphp/test/slow/dv_array_hack_arr/apc2.php
@@ -0,0 +1,4 @@
<?hh
// Copyright 2004-present Facebook. All Rights Reserved.

include 'apc.inc';
1 change: 1 addition & 0 deletions hphp/test/slow/dv_array_hack_arr/apc2.php.expect
@@ -0,0 +1 @@
============ DONE ================
1 change: 1 addition & 0 deletions hphp/test/slow/dv_array_hack_arr/apc2.php.hphp_opts
@@ -0,0 +1 @@
-vHackArrDVArrs=1
3 changes: 3 additions & 0 deletions hphp/test/slow/dv_array_hack_arr/apc2.php.opts
@@ -0,0 +1,3 @@
-vServer.APC.MemModelTreadmill=true
-vEval.HackArrDVArrs=true
--count=2
7 changes: 7 additions & 0 deletions hphp/test/slow/dv_array_hack_arr/arr_to_varray_cast.php
@@ -0,0 +1,7 @@
<?hh
// Copyright 2004-present Facebook. All Rights Reserved.

function test(array $a) { return varray($a); }

$a = ['a' => 1, 'b' => 2, 'c' => 3];
var_dump(test(__hhvm_intrinsics\launder_value($a)));
@@ -0,0 +1,5 @@
vec(3) {
int(1)
int(2)
int(3)
}
@@ -0,0 +1 @@
-vHackArrDVArrs=1
@@ -0,0 +1 @@
-vEval.HackArrDVArrs=true
39 changes: 39 additions & 0 deletions hphp/test/slow/dv_array_hack_arr/array_merge.php
@@ -0,0 +1,39 @@
<?hh
// Copyright 2004-present Facebook. All Rights Reserved.

function test($a, $b) {
echo "====================================================\n";
var_dump($a);
var_dump($b);
$x = array_merge($a, $b);
var_dump($x);
var_dump(is_array($x));
var_dump(is_varray($x));
var_dump(is_darray($x));
}

function test_all() {
$vals = vec[
[],
['a', 'b', 'c'],
[10 => 'a', 20 => 'b', 30 => 'c'],
['a' => 123, 'b' => 456, 'c' => 789],
varray[],
varray['a', 'b', 'c'],
darray[],
darray[10 => 'a', 20 => 'b', 30 => 'c'],
darray['a' => 123, 'b' => 456, 'c' => 789],
vec[],
vec['a', 'b', 'c'],
dict[],
dict[10 => 'a', 20 => 'b', 30 => 'c'],
dict['a' => 123, 'b' => 456, 'c' => 789]
];

foreach ($vals as $v1) {
foreach ($vals as $v2) {
test($v1, $v2);
}
}
}
test_all();

0 comments on commit 9f9d44f

Please sign in to comment.