Nested match expression tests

Closes GH-12433
This commit is contained in:
Julien Desrosiers 2023-10-12 20:56:31 -04:00 committed by Ilija Tovilo
parent 6b73fcc2b3
commit 226b92b1dc
No known key found for this signature in database
GPG key ID: A4F5D403F118200A
2 changed files with 55 additions and 0 deletions

41
Zend/tests/match/046.phpt Normal file
View file

@ -0,0 +1,41 @@
--TEST--
Nested match expressions
--FILE--
<?php
// Nested in return expression:
$b = 'b';
echo match($b) {
'a' => 1,
'b' => match (1) {
strpos('ab', $b) => 100,
default => 15
},
default => 4
};
echo "\n";
// Nested in condition expression:
$c = 'c';
echo match($c) {
'foo' => 'bar',
match ($c) { default => 'c' } => 300
};
echo "\n";
// Nested in one of many condition expressions:
$d = 'd';
echo match($d) {
'foo' => 'bar',
match ($d) { default => 'd' },
match ($d) { default => 'e' } => 500
};
?>
--EXPECT--
100
300
500

14
Zend/tests/match/047.phpt Normal file
View file

@ -0,0 +1,14 @@
--TEST--
Match expression inside subject expression
--FILE--
<?php
echo match (match ('b') { default => 'b' }) {
'a' => 100,
'b' => 200,
'c' => 300
};
?>
--EXPECT--
200