Skip to content

Commit 2fc6a5b

Browse files
committed
Verify cases() for backed enums
1 parent e83972a commit 2fc6a5b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/test/php/lang/ast/unittest/emit/EnumTest.class.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static function run() {
2929
}
3030

3131
#[Test]
32-
public function cases_method() {
32+
public function cases_method_for_unit_enums() {
3333
$t= $this->type('enum <T> {
3434
case Hearts;
3535
case Diamonds;
@@ -43,6 +43,21 @@ public function cases_method() {
4343
);
4444
}
4545

46+
#[Test]
47+
public function cases_method_for_backed_enums() {
48+
$t= $this->type('enum <T>: string {
49+
case Hearts = "♥";
50+
case Diamonds = "♦";
51+
case Clubs = "♣";
52+
case Spades = "♠";
53+
}');
54+
55+
Assert::equals(
56+
['Hearts', 'Diamonds', 'Clubs', 'Spades'],
57+
array_map(function($suit) { return $suit->name; }, $t->getMethod('cases')->invoke(null))
58+
);
59+
}
60+
4661
#[Test]
4762
public function cases_method_does_not_yield_constants() {
4863
$t= $this->type('enum <T> {

0 commit comments

Comments
 (0)