6
6
7
7
class HelloWorld
8
8
{
9
- public function inputTypes (int $ i , float $ f , string $ s ) {
9
+ /**
10
+ * @param int<-1, 5> $intRange
11
+ */
12
+ public function inputTypes (int $ i , float $ f , string $ s , int $ intRange ) {
10
13
// https://3v4l.org/iXaDX
11
14
assertType ('numeric-string ' , sprintf ('%.14F ' , $ i ));
12
15
assertType ('numeric-string ' , sprintf ('%.14F ' , $ f ));
@@ -19,6 +22,9 @@ public function inputTypes(int $i, float $f, string $s) {
19
22
assertType ('numeric-string ' , sprintf ('%14F ' , $ i ));
20
23
assertType ('numeric-string ' , sprintf ('%14F ' , $ f ));
21
24
assertType ('numeric-string ' , sprintf ('%14F ' , $ s ));
25
+
26
+ assertType ("'-1'|'0'|'1'|'2'|'3'|'4'|'5' " , sprintf ('%s ' , $ intRange ));
27
+ assertType ("' 0'|' 1'|' 2'|' 3'|' 4'|' 5'|'-1' " , sprintf ('%2s ' , $ intRange ));
22
28
}
23
29
24
30
public function specifiers (int $ i ) {
@@ -53,18 +59,27 @@ public function specifiers(int $i) {
53
59
*/
54
60
public function positionalArgs ($ mixed , int $ i , float $ f , string $ s , int $ posInt , int $ negInt , int $ nonZeroIntRange , int $ intRange ) {
55
61
// https://3v4l.org/vVL0c
56
- assertType ('numeric-string ' , sprintf ('%2$14s ' , $ mixed , $ i ));
57
- assertType ('non-falsy-string&numeric-string ' , sprintf ('%2$14s ' , $ mixed , $ posInt ));
58
- assertType ('non-falsy-string&numeric-string ' , sprintf ('%2$14s ' , $ mixed , $ negInt ));
59
- assertType ('numeric-string ' , sprintf ('%2$14s ' , $ mixed , $ intRange ));
60
- assertType ('non-falsy-string&numeric-string ' , sprintf ('%2$14s ' , $ mixed , $ nonZeroIntRange ));
61
-
62
- assertType ("non-falsy-string " , sprintf ('%2$14s ' , $ mixed , 1 ));
63
- assertType ("non-falsy-string " , sprintf ('%2$14s ' , $ mixed , '1 ' ));
64
- assertType ("non-falsy-string " , sprintf ('%2$14s ' , $ mixed , 'abc ' ));
62
+ assertType ('numeric-string ' , sprintf ('%2$6s ' , $ mixed , $ i ));
63
+ assertType ('non-falsy-string&numeric-string ' , sprintf ('%2$6s ' , $ mixed , $ posInt ));
64
+ assertType ('non-falsy-string&numeric-string ' , sprintf ('%2$6s ' , $ mixed , $ negInt ));
65
+ assertType ("' 1'|' 2'|' 3'|' 4'|' 5' " , sprintf ('%2$6s ' , $ mixed , $ nonZeroIntRange ));
66
+
67
+ // https://3v4l.org/1ECIq
68
+ assertType ('non-falsy-string ' , sprintf ("%2$'#6s " , $ mixed , 1 ));
69
+ assertType ('non-falsy-string ' , sprintf ("%2$'#6s " , $ mixed , $ i ));
70
+ assertType ('non-falsy-string ' , sprintf ("%2$'#6s " , $ mixed , $ posInt ));
71
+ assertType ('non-falsy-string ' , sprintf ("%2$'#6s " , $ mixed , $ negInt ));
72
+ assertType ("' 0'|' 1'|' 2'|' 3'|' 4'|' 5'|' -1' " , sprintf ('%2$6s ' , $ mixed , $ intRange ));
73
+ assertType ('non-falsy-string ' , sprintf ("%2$'#6s " , $ mixed , $ nonZeroIntRange ));
74
+
75
+ assertType ("' 1' " , sprintf ('%2$6s ' , $ mixed , 1 ));
76
+ assertType ("' 1' " , sprintf ('%2$6s ' , $ mixed , '1 ' ));
77
+ assertType ("' abc' " , sprintf ('%2$6s ' , $ mixed , 'abc ' ));
78
+ assertType ("' 0'|' 1'|' 2'|' 3'|' 4'|' 5'|' -1' " , sprintf ('%2$6s ' , $ mixed , $ intRange ));
65
79
assertType ("'1' " , sprintf ('%2$s ' , $ mixed , 1 ));
66
80
assertType ("'1' " , sprintf ('%2$s ' , $ mixed , '1 ' ));
67
81
assertType ("'abc' " , sprintf ('%2$s ' , $ mixed , 'abc ' ));
82
+ assertType ("'-1'|'0'|'1'|'2'|'3'|'4'|'5' " , sprintf ('%2$s ' , $ mixed , $ intRange ));
68
83
69
84
assertType ('numeric-string ' , sprintf ('%2$.14F ' , $ mixed , $ i ));
70
85
assertType ('numeric-string ' , sprintf ('%2$.14F ' , $ mixed , $ f ));
0 commit comments