Skip to content

Commit 79ec47c

Browse files
committed
Add tests for partial function application.
1 parent a07e75a commit 79ec47c

File tree

7 files changed

+148
-0
lines changed

7 files changed

+148
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Inlined partials.
3+
--FILE--
4+
<?php
5+
6+
function volume(int $x, int $y, int $z): int {
7+
return $x * $y * $z;
8+
}
9+
10+
$arr = [1, 2, 3];
11+
12+
function mul(float $x, float $y) {
13+
return $x * $y;
14+
}
15+
16+
$result = array_map(mul(2, ?), $arr);
17+
18+
print_r($result);
19+
20+
--EXPECTF--
21+
Array
22+
(
23+
[0] => 2
24+
[1] => 4
25+
[2] => 6
26+
)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Methods.
3+
--FILE--
4+
<?php
5+
6+
class Action {
7+
function volume(int $x, int $y, int $z): int {
8+
return $x * $y * $z;
9+
}
10+
}
11+
12+
$a = new Action();
13+
14+
$p1 = $a->volume(3, 5, ?);
15+
$p2 = $a->volume(3, ?, 9);
16+
$p3 = $a->volume(?, 5, 9);
17+
18+
print $p1(9);
19+
print $p2(5);
20+
print $p3(3);
21+
22+
--EXPECTF--
23+
135
24+
135
25+
135
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Multi-parameter function to single-parameter function.
3+
--FILE--
4+
<?php
5+
6+
function volume(int $x, int $y, int $z): int {
7+
return $x * $y * $z;
8+
}
9+
10+
$p1 = volume(3, 5, ?);
11+
$p2 = volume(3, ?, 9);
12+
$p3 = volume(?, 5, 9);
13+
14+
print $p1(9);
15+
print $p2(5);
16+
print $p3(3);
17+
18+
--EXPECTF--
19+
135
20+
135
21+
135
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Multi-parameter function to multi-parameter function.
3+
--FILE--
4+
<?php
5+
6+
function volume(int $x, int $y, int $z): int {
7+
return $x * $y * $z;
8+
}
9+
10+
$p1 = volume(3, ?, ?);
11+
$p2 = volume(?, ?, 9);
12+
$p3 = volume(?, 5, ?);
13+
14+
print $p1(5, 9);
15+
print $p2(3, 5);
16+
print $p3(3, 9);
17+
18+
--EXPECTF--
19+
135
20+
135
21+
135
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Nested partials.
3+
--FILE--
4+
<?php
5+
6+
function volume(int $x, int $y, int $z): int {
7+
return $x * $y * $z;
8+
}
9+
10+
$p1 = volume(3, ?, ?);
11+
$p2 = $p1(?, 9);
12+
13+
print $p1(5);
14+
15+
--EXPECTF--
16+
135
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Single parameter function.
3+
--FILE--
4+
<?php
5+
6+
function test1(int $a) {
7+
return $a + 1;
8+
}
9+
10+
$p = test1(?);
11+
12+
print p(3);
13+
14+
--EXPECTF--
15+
4
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Ensure reflected types inherit.
3+
--FILE--
4+
<?php
5+
6+
function volume(int $x, int $y, int $z): int {
7+
return $x * $y * $z;
8+
}
9+
10+
$p1 = volume(3, 5, ?);
11+
12+
$r = new ReflectionFunction($p1);
13+
14+
print $r->getNumberOfParameters();
15+
16+
$params = $r->getParameters();
17+
print $params[0]->getType();
18+
19+
print $r->getReturnType();
20+
21+
--EXPECTF--
22+
1
23+
int
24+
int

0 commit comments

Comments
 (0)