Skip to content

Commit

Permalink
add tests for int-like string array keys
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmuffme committed Mar 21, 2024
1 parent 4ea41cb commit 59c4844
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions tests/ArrayKeysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,36 +130,36 @@ public function test(): array {
* @psalm-type TAlias = 123
*/
class a {}
/**
* @psalm-import-type TAlias from a
* @template TKey as array-key
* @template TValue as array-key
* @template T as array<TKey, TValue>
*
*
* @template TOrig as a|b
* @template TT as class-string<TOrig>
*
*
* @template TBool as bool
*/
class b {
/**
* @var array<TAlias, int>
/**
* @var array<TAlias, int>
*/
private array $a = [123 => 123];
/** @var array<value-of<T>, int> */
public array $c = [];
/** @var array<key-of<T>, int> */
public array $d = [];
/** @var array<TT, int> */
public array $e = [];
/** @var array<key-of<array<int, string>>, int> */
private array $f = [123 => 123];
/** @var array<value-of<array<int, string>>, int> */
private array $g = ["test" => 123];
Expand All @@ -173,7 +173,7 @@ public function test(bool $v): array {
return $v ? ["a" => 123] : [123 => 123];
}
}
/** @var b<"testKey", "testValue", array<"testKey", "testValue">, b, class-string<b>, true> */
$b = new b;
$b->d["testKey"] = 123;
Expand All @@ -183,6 +183,26 @@ public function test(bool $v): array {
//$b->e["b"] = 123;
',
],
'intStringKeyAsInt' => [
'code' => '<?php
$a = ["15" => "a"];
$b = ["15.7" => "a"];
// since PHP 8 this is_numeric but will not be int key
$c = ["15 " => "a"];
$d = ["-15" => "a"];
// see https://github.com/php/php-src/issues/9029#issuecomment-1186226676
$e = ["+15" => "a"];
$f = ["015" => "a"];
',
'assertions' => [
'$a===' => "array{15: 'a'}",
'$b===' => "array{'15.7': 'a'}",
'$c===' => "array{'15 ': 'a'}",
'$d===' => "array{-15: 'a'}",
'$e===' => "array{'+15': 'a'}",
'$f===' => "array{'015': 'a'}",
],
],
];
}

Expand Down

0 comments on commit 59c4844

Please sign in to comment.