@@ -100,6 +100,7 @@ struct TestInput {
100
100
#[ serde( default ) ]
101
101
callback : String ,
102
102
#[ serde( default ) ]
103
+ #[ serde( rename( deserialize = "option" ) ) ]
103
104
options : Vec < String > ,
104
105
#[ serde( default ) ]
105
106
#[ serde( rename( deserialize = "input" ) ) ]
@@ -109,7 +110,7 @@ struct TestInput {
109
110
#[ derive( Serialize ) ]
110
111
struct TestOutput {
111
112
success : bool ,
112
- message : String ,
113
+ message : Option < String > ,
113
114
html : String ,
114
115
}
115
116
@@ -131,6 +132,10 @@ async fn test_handler(Form(test_input): Form<TestInput>) -> Response<Body> {
131
132
html. push_str ( "\t \t </tr>\n " ) ;
132
133
}
133
134
135
+ // capture_names
136
+ // captures_len
137
+ // static_captures_len
138
+
134
139
html. push_str ( "\t </tbody>\n " ) ;
135
140
html. push_str ( "</table>" ) ;
136
141
@@ -163,18 +168,105 @@ async fn test_handler(Form(test_input): Form<TestInput>) -> Response<Body> {
163
168
html. push_str ( "<table class=\" table table-bordered table-striped\" style=\" width: auto;\" >\n " ) ;
164
169
html. push_str ( "\t <thead>\n " ) ;
165
170
html. push_str ( "\t \t <tr>\n " ) ;
171
+ html. push_str ( "\t \t \t <th>Test</th>\n " ) ;
166
172
html. push_str ( "\t \t \t <th>Input</th>\n " ) ;
167
173
html. push_str ( "\t \t \t <th>is_match</th>\n " ) ;
174
+ html. push_str ( "\t \t \t <th>find</th>\n " ) ;
175
+ html. push_str ( "\t \t \t <th>find_iter</th>\n " ) ;
176
+ html. push_str ( "\t \t \t <th>captures</th>\n " ) ;
177
+ html. push_str ( "\t \t \t <th>captures_iter</th>\n " ) ;
178
+ html. push_str ( "\t \t \t <th>split</th>\n " ) ;
179
+ // replace
180
+ // replace_all
181
+ // replacen
182
+ // shortest_match
168
183
html. push_str ( "\t \t </tr>\n " ) ;
169
184
html. push_str ( "\t </thead>\n " ) ;
170
185
html. push_str ( "\t <tbody>\n " ) ;
171
-
172
- for input in test_input. inputs {
173
- //let output = the_regex.as_ref().unwrap().replace_all(&input, &test_input.replacement);
186
+ for ( index, input) in test_input. inputs . iter ( ) . enumerate ( ) {
187
+ if input == "" {
188
+ continue ;
189
+ }
174
190
html. push_str ( "\t \t <tr>\n " ) ;
191
+ html. push_str ( & format ! ( "\t \t \t <td class=\" text-center\" >{}</td>\n " , index+1 ) ) ;
175
192
html. push_str ( & format ! ( "\t \t \t <td>{}</td>\n " , encode_text( & input) ) ) ;
176
193
let is_match = if the_regex. is_match ( & input) { "true" } else { "false" } ;
177
194
html. push_str ( & format ! ( "\t \t \t <td>{}</td>\n " , is_match) ) ;
195
+
196
+ let find = the_regex. find ( & input) ;
197
+ if find. is_none ( ) {
198
+ html. push_str ( "\t \t \t <td><i>(none)</i></td>\n " ) ;
199
+ } else {
200
+ html. push_str ( & format ! ( "\t \t \t <td>{}..{}</td>\n " , find. unwrap( ) . start( ) , find. unwrap( ) . end( ) ) ) ;
201
+ }
202
+
203
+ let finds: Vec < _ > = the_regex. find_iter ( & input) . map ( |m| m. range ( ) ) . collect ( ) ;
204
+ if finds. len ( ) == 0 {
205
+ html. push_str ( "\t \t \t <td><i>(none)</i></td>\n " ) ;
206
+ } else {
207
+ html. push_str ( "\t \t \t <td>\n " ) ;
208
+ for ( index, found) in finds. iter ( ) . enumerate ( ) {
209
+ html. push_str ( & format ! ( "\t \t \t \t [{}]: {}..{}" , index, found. start, found. end) ) ;
210
+ if index < finds. len ( ) - 1 {
211
+ html. push_str ( "<br>\n " ) ;
212
+ }
213
+ }
214
+ html. push_str ( "\t \t \t </td>\n " ) ;
215
+ }
216
+
217
+ let caps = the_regex. captures ( & input) ;
218
+ if caps. is_none ( ) {
219
+ html. push_str ( "\t \t \t <td><i>(none)</i></td>\n " ) ;
220
+ } else {
221
+ let caps = caps. unwrap ( ) ;
222
+ html. push_str ( "\t \t \t <td>\n " ) ;
223
+ for ( index, cap) in caps. iter ( ) . enumerate ( ) {
224
+ if cap. is_none ( ) {
225
+ continue ;
226
+ }
227
+ let cap = cap. unwrap ( ) ;
228
+ html. push_str ( & format ! ( "\t \t \t \t [{}]: {} ({}..{})" , index, encode_text( cap. as_str( ) ) , cap. start( ) , cap. end( ) ) ) ;
229
+ if index < caps. len ( ) - 1 {
230
+ html. push_str ( "<br>\n " ) ;
231
+ }
232
+ }
233
+ html. push_str ( "\t \t \t </td>\n " ) ;
234
+ }
235
+
236
+ let icaps: Vec < _ > = the_regex. captures_iter ( & input) . map ( |caps| caps. iter ( ) . map ( |cap| cap. map ( |c| c. as_str ( ) ) . unwrap_or ( "" ) ) . collect :: < Vec < _ > > ( ) ) . collect ( ) ;
237
+ if icaps. len ( ) == 0 {
238
+ html. push_str ( "\t \t \t <td><i>(none)</i></td>\n " ) ;
239
+ } else {
240
+ html. push_str ( "\t \t \t <td>\n " ) ;
241
+ for ( index, caps) in icaps. iter ( ) . enumerate ( ) {
242
+ html. push_str ( & format ! ( "\t \t \t \t [{}]: " , index) ) ;
243
+ for ( index, cap) in caps. iter ( ) . enumerate ( ) {
244
+ html. push_str ( & format ! ( "{}: {}" , index, cap) ) ;
245
+ if index < caps. len ( ) - 1 {
246
+ html. push_str ( ", " ) ;
247
+ }
248
+ }
249
+ if index < icaps. len ( ) - 1 {
250
+ html. push_str ( "<br>\n " ) ;
251
+ }
252
+ }
253
+ html. push_str ( "\t \t \t </td>\n " ) ;
254
+ }
255
+
256
+ let splits: Vec < _ > = the_regex. split ( & input) . collect ( ) ;
257
+ if splits. len ( ) == 0 {
258
+ html. push_str ( "\t \t \t <td><i>(none)</i></td>\n " ) ;
259
+ } else {
260
+ html. push_str ( "\t \t \t <td>\n " ) ;
261
+ for ( index, split) in splits. iter ( ) . enumerate ( ) {
262
+ html. push_str ( & format ! ( "\t \t \t \t [{}]: {}" , index, encode_text( split) ) ) ;
263
+ if index < splits. len ( ) - 1 {
264
+ html. push_str ( "<br>\n " ) ;
265
+ }
266
+ }
267
+ html. push_str ( "\t \t \t </td>\n " ) ;
268
+ }
269
+
178
270
html. push_str ( "\t \t </tr>\n " ) ;
179
271
}
180
272
@@ -189,8 +281,8 @@ fn handle_jsonp(callback: &str, html: String) -> Response<Body> {
189
281
190
282
let test_output = TestOutput {
191
283
success : true ,
192
- message : "OK" . to_string ( ) ,
193
- html : html ,
284
+ message : None ,
285
+ html,
194
286
} ;
195
287
196
288
let json_output = serde_json:: to_string ( & test_output) . unwrap ( ) ;
0 commit comments