Updating submodules
[hiphop-php.git] / hphp / test / slow / ext_array / array_intersect_key_coercion2.php
blob74cca7c71143d12d22c53b779039699e419fe594
1 <?hh
2 // This is like array_intersect_key_coercion.php but the left container is
3 // larger than the right and has holes, so we can test the other
4 // array_intersect_key code path
6 function nextBit(inout int $x): bool {
7 $ret = (bool)($x & 1);
8 $x >>= 1;
9 return $ret;
12 function testOne(int $case): void {
13 $left = nextBit(inout $case) ? Map{} : dict[];
14 $right = nextBit(inout $case) ? Map{} : dict[];
15 $left['hole1'] = true;
16 if (nextBit(inout $case)) $left['a'] = 'a';
17 $left['hole2'] = true;
18 if (nextBit(inout $case)) $left[1] = 'i';
19 $left['hole3'] = true;
20 if (nextBit(inout $case)) $left['1'] = 's';
21 unset($left['hole1']);
22 unset($left['hole2']);
23 unset($left['hole3']);
24 if (nextBit(inout $case)) $right['a'] = 'x';
25 if (nextBit(inout $case)) $right[1] = 'y';
26 if (nextBit(inout $case)) $right['1'] = 'z';
28 // skip boring cases
29 if (count($left) === 0 || count($right) === 0) return;
31 $left['junk1'] = true;
32 $left[2] = true;
33 $left['junk3'] = true;
35 $res = array_intersect_key($left, $right);
36 echo
37 $left is Map<_> ? 'm' : 'd',
38 isset($left['a']) ? 'a' : ' ',
39 isset($left[1]) ? 'i' : ' ',
40 isset($left['1']) ? 's' : ' ',
41 ' + ',
42 $right is Map<_> ? 'm' : 'd',
43 isset($right['a']) ? 'a' : ' ',
44 isset($right[1]) ? 'i' : ' ',
45 isset($right['1']) ? 's' : ' ',
46 ' = \'',
47 $res['a'] ?? ' ',
48 $res[1] ?? ' ',
49 $res['1'] ?? ' ',
50 "'\n";
53 <<__EntryPoint>>
54 function main(): void {
55 for ($i = 0; $i < 256; $i++) testOne($i);