Skip to content

Commit

Permalink
Add tests for array_reverse of lists with possibly undefined items
Browse files Browse the repository at this point in the history
  • Loading branch information
MoonE committed Nov 10, 2024
1 parent 0f796f1 commit 21647b0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/ArrayFunctionCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,31 @@ public function replace($a, $b): array
'$d' => 'non-empty-array<int|string, int|string>',
],
],
'arrayReverseListDontPreserveKey' => [
'code' => '<?php
/** @return list{0: int, 1: float, 2: int, 3: false, 4?: string|true, 5?: true} */
function f(): array {
return [1, 1.1, 2, false, "", true];
}
/** @return list{0: int, 1: int, 2: int, 3?: int, 4?: int} */
function g(): array { return [1,2,3]; }
$r = array_reverse(f());
$s = array_reverse(g());',
'assertions' => [
'$r' => 'list{0: bool|string, 1: bool|int|string, 2: false|float|int, 3: float|int, 4?: float|int, 5?: int}',
'$s' => 'list{0: int, 1: int, 2: int, 3?: int, 4?: int}',
],
],
'arrayReverseListInt' => [
'code' => '<?php
/** @return list<int> */
function f(): array { return []; }
$a = array_reverse(f());',
'assertions' => [
'$a' => 'list<int>',
],
],
'arrayReverseDontPreserveKeyExplicitArg' => [
'code' => '<?php
$d = array_reverse(["a", "b", 1, "d" => 4], false);',
Expand Down

0 comments on commit 21647b0

Please sign in to comment.