-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix, optimize code, refactor arraylist/map ctor: Allow array as ctor …
…method parameter
- Loading branch information
Showing
11 changed files
with
130 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--TEST-- | ||
swoole_thread: arraylist | ||
--SKIPIF-- | ||
<?php | ||
require __DIR__ . '/../include/skipif.inc'; | ||
skip_if_nts(); | ||
?> | ||
--FILE-- | ||
<?php | ||
require __DIR__ . '/../include/bootstrap.php'; | ||
|
||
use Swoole\Thread\ArrayList; | ||
|
||
$array = [ | ||
random_int(1, 999999999999999999), | ||
random_bytes(128), | ||
uniqid(), | ||
time(), | ||
]; | ||
|
||
$l = new ArrayList($array); | ||
Assert::eq($l->toArray(), $array); | ||
|
||
for ($i = 0; $i < count($array); $i++) { | ||
Assert::eq($l[$i], $array[$i]); | ||
} | ||
|
||
$array2 = [ | ||
'key' => 'value', | ||
'hello' => 'world', | ||
]; | ||
$l[] = $array2; | ||
|
||
Assert::eq($l[4]->toArray(), $array2); | ||
|
||
try { | ||
$l2 = new ArrayList($array2); | ||
echo "never here\n"; | ||
} catch (Throwable $e) { | ||
Assert::contains($e->getMessage(), 'must be an array of type list'); | ||
} | ||
?> | ||
--EXPECTF-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--TEST-- | ||
swoole_thread: map | ||
--SKIPIF-- | ||
<?php | ||
require __DIR__ . '/../include/skipif.inc'; | ||
skip_if_nts(); | ||
?> | ||
--FILE-- | ||
<?php | ||
require __DIR__ . '/../include/bootstrap.php'; | ||
|
||
use Swoole\Thread\Map; | ||
|
||
$array = [ | ||
'a' => random_int(1, 999999999999999999), | ||
'b' => random_bytes(128), | ||
'c' => uniqid(), | ||
'd' => time(), | ||
]; | ||
|
||
$m = new Map($array); | ||
Assert::eq($m->toArray(), $array); | ||
|
||
foreach ($array as $k => $v) { | ||
Assert::eq($m[$k], $array[$k]); | ||
} | ||
|
||
$array2 = [ | ||
'key' => 'value', | ||
'hello' => 'world', | ||
]; | ||
$m['map'] = $array2; | ||
|
||
Assert::eq($m['map']->toArray(), $array2); | ||
?> | ||
--EXPECTF-- |