@@ -264,6 +264,69 @@ bool test_iter_capture_names() {
264
264
return passed ;
265
265
}
266
266
267
+ bool test_iter_split () {
268
+ bool passed = true;
269
+
270
+ rure * re = rure_compile_must ("[ \t]+" );
271
+
272
+ const uint8_t * haystack = (const uint8_t * )" \t a b \t c\td e" ;
273
+ size_t haystack_len = strlen ((const char * )haystack );
274
+
275
+ rure_iter_split * it = rure_iter_split_new (re , haystack , haystack_len );
276
+
277
+ char * match ;
278
+ bool result = rure_iter_split_next (it , & match );
279
+ if (!result ) {
280
+ if (DEBUG ) {
281
+ fprintf (stderr ,
282
+ "[test_iter_split] expected a match, "
283
+ "but got none\n" );
284
+ }
285
+ passed = false;
286
+ goto done ;
287
+ }
288
+
289
+ result = rure_iter_split_next (it , & match );
290
+ passed = (strcmp (match , "a" ) == 0 );
291
+ if (!passed ) {
292
+ goto done ;
293
+ }
294
+
295
+ result = rure_iter_split_next (it , & match );
296
+ passed = (strcmp (match , "b" ) == 0 );
297
+ if (!passed ) {
298
+ goto done ;
299
+ }
300
+
301
+ result = rure_iter_split_next (it , & match );
302
+ passed = (strcmp (match , "c" ) == 0 );
303
+ if (!passed ) {
304
+ goto done ;
305
+ }
306
+
307
+ result = rure_iter_split_next (it , & match );
308
+ passed = (strcmp (match , "d" ) == 0 );
309
+ if (!passed ) {
310
+ goto done ;
311
+ }
312
+
313
+ result = rure_iter_split_next (it , & match );
314
+ passed = (strcmp (match , "e" ) == 0 );
315
+ if (!passed ) {
316
+ goto done ;
317
+ }
318
+
319
+ result = rure_iter_split_next (it , & match );
320
+ passed = !result ;
321
+ if (!passed ) {
322
+ goto done ;
323
+ }
324
+ done :
325
+ rure_iter_split_free (it );
326
+ rure_free (re );
327
+ return passed ;
328
+ }
329
+
267
330
/*
268
331
* This tests whether we can set the flags correctly. In this case, we disable
269
332
* all flags, which includes disabling Unicode mode. When we disable Unicode
@@ -574,6 +637,7 @@ int main() {
574
637
run_test (test_captures , "test_captures" , & passed );
575
638
run_test (test_iter , "test_iter" , & passed );
576
639
run_test (test_iter_capture_names , "test_iter_capture_names" , & passed );
640
+ run_test (test_iter_split , "test_iter_split" , & passed );
577
641
run_test (test_flags , "test_flags" , & passed );
578
642
run_test (test_compile_error , "test_compile_error" , & passed );
579
643
run_test (test_compile_error_size_limit , "test_compile_error_size_limit" ,
0 commit comments