Skip to content

Commit 682e96d

Browse files
committed
Use lang.Enum directly
1 parent 24f95be commit 682e96d

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace lang\ast\unittest\emit;
22

3+
use lang\Enum;
34
use unittest\actions\VerifyThat;
45
use unittest\{Assert, Action, Test};
56

@@ -68,6 +69,20 @@ public static function run($order= self::ASC) {
6869
Assert::equals('ASC', $t->getMethod('run')->invoke(null));
6970
}
7071

72+
#[Test]
73+
public function overwritten_parameter_default_value() {
74+
$t= $this->type('enum <T> {
75+
case ASC;
76+
case DESC;
77+
78+
public static function run($order= self::ASC) {
79+
return $order->name;
80+
}
81+
}');
82+
83+
Assert::equals('DESC', $t->getMethod('run')->invoke(null, [Enum::valueOf($t, 'DESC')]));
84+
}
85+
7186
#[Test]
7287
public function value_property_of_backed_enum() {
7388
$t= $this->type('enum <T>: string {
@@ -148,36 +163,28 @@ public static function run($arg) {
148163

149164
#[Test]
150165
public function enum_values() {
151-
$t= $this->type('use lang\Enum; enum <T> {
166+
$t= $this->type('enum <T> {
152167
case Hearts;
153168
case Diamonds;
154169
case Clubs;
155170
case Spades;
156-
157-
public static function run() {
158-
return Enum::valuesOf(self::class);
159-
}
160171
}');
161172

162173
Assert::equals(
163174
['Hearts', 'Diamonds', 'Clubs', 'Spades'],
164-
array_map(function($suit) { return $suit->name; }, $t->getMethod('run')->invoke(null))
175+
array_map(function($suit) { return $suit->name; }, Enum::valuesOf($t))
165176
);
166177
}
167178

168179
#[Test]
169180
public function enum_value() {
170-
$t= $this->type('use lang\Enum; enum <T> {
181+
$t= $this->type('enum <T> {
171182
case Hearts;
172183
case Diamonds;
173184
case Clubs;
174185
case Spades;
175-
176-
public static function run() {
177-
return Enum::valueOf(self::class, "Hearts")->name;
178-
}
179186
}');
180187

181-
Assert::equals('Hearts', $t->getMethod('run')->invoke(null));
188+
Assert::equals('Hearts', Enum::valueOf($t, 'Hearts')->name);
182189
}
183190
}

0 commit comments

Comments
 (0)