Skip to content

Commit fae72a8

Browse files
committed
Add tests for issue #101
1 parent 33d1e9c commit fae72a8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,35 @@ public function run($arg) {
162162
}
163163
}', SEEK_END);
164164
}
165+
166+
#[Test]
167+
public function match_without_arg_inside_fn() {
168+
$r= $this->run('class <T> {
169+
public function run() {
170+
return fn($arg) => match {
171+
$arg >= 10 => "10+ items",
172+
$arg === 1 => "one item",
173+
$arg === 0 => "no items",
174+
default => $arg." items",
175+
};
176+
}
177+
}');
178+
179+
Assert::equals('10+ items', $r(10));
180+
}
181+
182+
#[Test]
183+
public function match_with_arg_inside_fn() {
184+
$r= $this->run('class <T> {
185+
public function run() {
186+
return fn($arg) => match ($arg) {
187+
0 => "no items",
188+
1 => "one item",
189+
default => $arg." items",
190+
};
191+
}
192+
}');
193+
194+
Assert::equals('one item', $r(1));
195+
}
165196
}

0 commit comments

Comments
 (0)