File tree Expand file tree Collapse file tree 6 files changed +254
-0
lines changed
ext/standard/tests/strings Expand file tree Collapse file tree 6 files changed +254
-0
lines changed Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Test strrev() function : basic functionality
3
+ --FILE--
4
+ <?php
5
+ /* Prototype : string strrev(string $str);
6
+ * Description: Reverse a string
7
+ * Source code: ext/standard/string.c
8
+ */
9
+
10
+ echo "*** Testing strrev() : basic functionality *** \n" ;
11
+ $ heredoc = <<<EOD
12
+ Hello, world
13
+ EOD ;
14
+
15
+ //regular string
16
+ var_dump ( strrev ("Hello, World " ) );
17
+ var_dump ( strrev ('Hello, World ' ) );
18
+
19
+ //single character
20
+ var_dump ( strrev ("H " ) );
21
+ var_dump ( strrev ('H ' ) );
22
+
23
+ //string containing simalr chars
24
+ var_dump ( strrev ("HHHHHH " ) );
25
+ var_dump ( strrev ("HhhhhH " ) );
26
+
27
+ //string containing escape char
28
+ var_dump ( strrev ("Hello, World \n" ) );
29
+ var_dump ( strrev ('Hello, World\n ' ) );
30
+
31
+ //heredoc string
32
+ var_dump ( strrev ($ heredoc ) );
33
+ echo "*** Done *** " ;
34
+ ?>
35
+ --EXPECTF--
36
+ *** Testing strrev() : basic functionality ***
37
+ string(12) "dlroW ,olleH"
38
+ string(12) "dlroW ,olleH"
39
+ string(1) "H"
40
+ string(1) "H"
41
+ string(6) "HHHHHH"
42
+ string(6) "HhhhhH"
43
+ string(13) "
44
+ dlroW ,olleH"
45
+ string(14) "n\dlroW ,olleH"
46
+ string(12) "dlrow ,olleH"
47
+ *** Done ***
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Test strrev() function : error conditions
3
+ --FILE--
4
+ <?php
5
+ /* Prototype : string strrev(string $str);
6
+ * Description: Reverse a string
7
+ * Source code: ext/standard/string.c
8
+ */
9
+
10
+ echo "*** Testing strrev() : error conditions *** \n" ;
11
+ echo "-- Testing strrev() function with Zero arguments -- " ;
12
+ var_dump ( strrev () );
13
+
14
+ echo "\n-- Testing strrev() function with more than expected no. of arguments -- " ;
15
+ var_dump ( strrev ("string " , 'extra_arg ' ) );
16
+ echo "*** Done *** " ;
17
+ ?>
18
+ --EXPECTF--
19
+ *** Testing strrev() : error conditions ***
20
+ -- Testing strrev() function with Zero arguments --
21
+ Warning: Wrong parameter count for strrev() in %s on line %d
22
+ NULL
23
+
24
+ -- Testing strrev() function with more than expected no. of arguments --
25
+ Warning: Wrong parameter count for strrev() in %s on line %d
26
+ NULL
27
+ *** Done ***
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Test strrev() function : usage variations - unexpected inputs
3
+ --FILE--
4
+ <?php
5
+ /* Prototype : string strrev(string $str);
6
+ * Description: Reverse a string
7
+ * Source code: ext/standard/string.c
8
+ */
9
+
10
+ /* Testing strrev() function with unexpected inputs for 'str' */
11
+
12
+ echo "*** Testing strrev() : unexpected inputs for 'str' *** \n" ;
13
+ //class declaration
14
+ class sample {
15
+ public function __toString (){
16
+ return "object " ;
17
+ }
18
+ }
19
+
20
+ //get the resource
21
+ $ resource = fopen (__FILE__ , "r " );
22
+
23
+ //get an unset variable
24
+ $ unset_var = 10 ;
25
+ unset ($ unset_var );
26
+
27
+ //array of values to iterate over
28
+ $ values = array (
29
+
30
+ // int data
31
+ 0 ,
32
+ 1 ,
33
+ 12345 ,
34
+ -2345 ,
35
+
36
+ // float data
37
+ 10.5 ,
38
+ -10.5 ,
39
+ 10.5e10 ,
40
+ 10.6E-10 ,
41
+ .5 ,
42
+
43
+ // array data
44
+ array (),
45
+ array (0 ),
46
+ array (1 ),
47
+ array (1 , 2 ),
48
+ array ('color ' => 'red ' , 'item ' => 'pen ' ),
49
+
50
+ // null data
51
+ NULL ,
52
+ null ,
53
+
54
+ // boolean data
55
+ true ,
56
+ false ,
57
+ TRUE ,
58
+ FALSE ,
59
+
60
+ // empty data
61
+ "" ,
62
+ '' ,
63
+
64
+ // object data
65
+ new sample (),
66
+
67
+ // resource
68
+ $ resource ,
69
+
70
+ // undefined data
71
+ @$ undefined_var ,
72
+
73
+ // unset data
74
+ @$ unset_var
75
+ );
76
+
77
+ // loop through each element of the array for str
78
+
79
+ $ count = 1 ;
80
+ foreach ($ values as $ value ) {
81
+ echo "\n-- Iterator $ count -- \n" ;
82
+ var_dump ( strrev ($ value ) );
83
+ $ count ++;
84
+ };
85
+
86
+ fclose ($ resource ); //closing the file handle
87
+
88
+ echo "*** Done *** " ;
89
+ ?>
90
+ --EXPECTF--
91
+ *** Testing strrev() : unexpected inputs for 'str' ***
92
+
93
+ -- Iterator 1 --
94
+ string(1) "0"
95
+
96
+ -- Iterator 2 --
97
+ string(1) "1"
98
+
99
+ -- Iterator 3 --
100
+ string(5) "54321"
101
+
102
+ -- Iterator 4 --
103
+ string(5) "5432-"
104
+
105
+ -- Iterator 5 --
106
+ string(4) "5.01"
107
+
108
+ -- Iterator 6 --
109
+ string(5) "5.01-"
110
+
111
+ -- Iterator 7 --
112
+ string(12) "000000000501"
113
+
114
+ -- Iterator 8 --
115
+ string(7) "9-E60.1"
116
+
117
+ -- Iterator 9 --
118
+ string(3) "5.0"
119
+
120
+ -- Iterator 10 --
121
+
122
+ Notice: Array to string conversion in %s on line %d
123
+ string(5) "yarrA"
124
+
125
+ -- Iterator 11 --
126
+
127
+ Notice: Array to string conversion in %s on line %d
128
+ string(5) "yarrA"
129
+
130
+ -- Iterator 12 --
131
+
132
+ Notice: Array to string conversion in %s on line %d
133
+ string(5) "yarrA"
134
+
135
+ -- Iterator 13 --
136
+
137
+ Notice: Array to string conversion in %s on line %d
138
+ string(5) "yarrA"
139
+
140
+ -- Iterator 14 --
141
+
142
+ Notice: Array to string conversion in %s on line %d
143
+ string(5) "yarrA"
144
+
145
+ -- Iterator 15 --
146
+ string(0) ""
147
+
148
+ -- Iterator 16 --
149
+ string(0) ""
150
+
151
+ -- Iterator 17 --
152
+ string(1) "1"
153
+
154
+ -- Iterator 18 --
155
+ string(0) ""
156
+
157
+ -- Iterator 19 --
158
+ string(1) "1"
159
+
160
+ -- Iterator 20 --
161
+ string(0) ""
162
+
163
+ -- Iterator 21 --
164
+ string(0) ""
165
+
166
+ -- Iterator 22 --
167
+ string(0) ""
168
+
169
+ -- Iterator 23 --
170
+ string(6) "tcejbo"
171
+
172
+ -- Iterator 24 --
173
+ string(14) "%d# di ecruoseR"
174
+
175
+ -- Iterator 25 --
176
+ string(0) ""
177
+
178
+ -- Iterator 26 --
179
+ string(0) ""
180
+ *** Done ***
You can’t perform that action at this time.
0 commit comments