Skip to content

Add tests for match expressions #12433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Zend/tests/match/046.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be on two lines

};


?>
--EXPECT--
100
300
500
14 changes: 14 additions & 0 deletions Zend/tests/match/047.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Match expression inside subject expression
--FILE--
<?php

echo match ( match ('b') { default => 'b' } ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the spaces around the inner match.

'a' => 100,
'b' => 200,
'c' => 300
};

?>
--EXPECT--
200