@@ -364,6 +364,53 @@ TEST(tfw_str_eq_cstr, supports_prefix)
364
364
TFW_STR_EQ_PREFIX_CASEI ));
365
365
}
366
366
367
+ TEST (tfw_str_eq_cstr_off , supports_suffix )
368
+ {
369
+ TFW_STR (s , "/foo/bar/baz.test" );
370
+ const char * p1 = "/foo/bar/baz.test" ;
371
+ const char * p2 = "foo/bar/baz.test" ;
372
+ const char * p3 = "bar/baz.test" ;
373
+ const char * p4 = "/baz.test" ;
374
+ const char * p5 = ".test" ;
375
+ const char * p6 = "" ;
376
+ const char * f1 = "/bar/foo/baz.test" ;
377
+ const char * f2 = "/foo/bar/" ;
378
+ const char * extra = "/bar/foo/baz.test100" ;
379
+ const char * i1 = "/foo/bar/baz.tesT" ;
380
+ const char * i2 = ".TeSt" ;
381
+
382
+ #define X_EXPECT_TRUE (s , p , flags ) \
383
+ do { \
384
+ int plen = strlen(p); \
385
+ EXPECT_TRUE(tfw_str_eq_cstr_off(s, s->len - plen, p, plen, flags)); \
386
+ } while(0)
387
+ #define X_EXPECT_FALSE (s , p , flags ) \
388
+ do { \
389
+ int plen = strlen(p); \
390
+ EXPECT_FALSE(tfw_str_eq_cstr_off(s, s->len - plen, p, plen, flags)); \
391
+ } while(0)
392
+
393
+ X_EXPECT_TRUE (s , p1 , TFW_STR_EQ_DEFAULT );
394
+ X_EXPECT_TRUE (s , p2 , TFW_STR_EQ_DEFAULT );
395
+ X_EXPECT_TRUE (s , p3 , TFW_STR_EQ_DEFAULT );
396
+ X_EXPECT_TRUE (s , p4 , TFW_STR_EQ_DEFAULT );
397
+ X_EXPECT_TRUE (s , p5 , TFW_STR_EQ_DEFAULT );
398
+ X_EXPECT_TRUE (s , p6 , TFW_STR_EQ_DEFAULT );
399
+
400
+ X_EXPECT_FALSE (s , f1 , TFW_STR_EQ_DEFAULT );
401
+ X_EXPECT_FALSE (s , f2 , TFW_STR_EQ_DEFAULT );
402
+
403
+ X_EXPECT_FALSE (s , extra , TFW_STR_EQ_DEFAULT );
404
+ X_EXPECT_FALSE (s , i1 , TFW_STR_EQ_DEFAULT );
405
+ X_EXPECT_FALSE (s , i2 , TFW_STR_EQ_DEFAULT );
406
+
407
+ X_EXPECT_FALSE (s , i1 , TFW_STR_EQ_DEFAULT | TFW_STR_EQ_CASEI );
408
+ X_EXPECT_FALSE (s , i2 , TFW_STR_EQ_DEFAULT | TFW_STR_EQ_CASEI );
409
+
410
+ #undef X_EXPECT_TRUE
411
+ #undef X_EXPECT_FALSE
412
+ }
413
+
367
414
static const char * foxstr = "The quick brown fox jumps over the lazy dog" ;
368
415
369
416
TEST (tfw_str_eq_cstr_pos , plain )
@@ -395,6 +442,32 @@ TEST(tfw_str_eq_cstr_pos, plain)
395
442
396
443
}
397
444
445
+ TEST (tfw_str_eq_cstr_off , plain )
446
+ {
447
+ TfwStr * fox = make_plain_str (foxstr );
448
+ long i , offset = 0 , foxlen = fox -> len ;
449
+
450
+ for (i = 0 ; i < fox -> len ; i ++ ) {
451
+ EXPECT_TRUE (tfw_str_eq_cstr_off (fox , fox -> len + i ,
452
+ foxstr + offset ,
453
+ foxlen - offset ,
454
+ TFW_STR_EQ_CASEI ));
455
+ EXPECT_FALSE (tfw_str_eq_cstr_off (fox , fox -> len + i ,
456
+ "1234567890" , 10 ,
457
+ TFW_STR_EQ_CASEI ));
458
+ ++ offset ;
459
+ }
460
+
461
+ EXPECT_TRUE (tfw_str_eq_cstr_off (fox , foxlen ,
462
+ foxstr , foxlen , TFW_STR_EQ_CASEI ));
463
+
464
+ EXPECT_FALSE (tfw_str_eq_cstr_off (fox , foxlen + 1 ,
465
+ foxstr , foxlen , TFW_STR_EQ_CASEI ));
466
+ EXPECT_FALSE (tfw_str_eq_cstr_off (fox , -1 ,
467
+ foxstr , foxlen , TFW_STR_EQ_CASEI ));
468
+
469
+ }
470
+
398
471
TEST (tfw_str_eq_cstr_pos , compound )
399
472
{
400
473
TfwStr * fox = make_compound_str (foxstr ), * c , * end ;
@@ -423,6 +496,32 @@ TEST(tfw_str_eq_cstr_pos, compound)
423
496
TFW_STR_EQ_CASEI ));
424
497
}
425
498
499
+ TEST (tfw_str_eq_cstr_off , compound )
500
+ {
501
+ TfwStr * fox = make_compound_str (foxstr );
502
+ long i , offset = 0 , foxlen = fox -> len ;
503
+
504
+ for (i = 0 ; i < fox -> len ; i ++ ) {
505
+ EXPECT_TRUE (tfw_str_eq_cstr_off (fox , fox -> len + i ,
506
+ foxstr + offset ,
507
+ foxlen - offset ,
508
+ TFW_STR_EQ_CASEI ));
509
+ EXPECT_FALSE (tfw_str_eq_cstr_off (fox , fox -> len + i ,
510
+ "1234567890" , 10 ,
511
+ TFW_STR_EQ_CASEI ));
512
+ ++ offset ;
513
+ }
514
+
515
+ EXPECT_TRUE (tfw_str_eq_cstr_off (fox , foxlen ,
516
+ foxstr , foxlen , TFW_STR_EQ_CASEI ));
517
+
518
+ EXPECT_FALSE (tfw_str_eq_cstr_off (fox , foxlen + 1 ,
519
+ foxstr , foxlen , TFW_STR_EQ_CASEI ));
520
+ EXPECT_FALSE (tfw_str_eq_cstr_off (fox , -1 ,
521
+ foxstr , foxlen , TFW_STR_EQ_CASEI ));
522
+
523
+ }
524
+
426
525
TEST_SUITE (tfw_str )
427
526
{
428
527
TEST_SETUP (create_str_pool );
@@ -449,7 +548,10 @@ TEST_SUITE(tfw_str)
449
548
TEST_RUN (tfw_str_eq_cstr , handles_empty_strs );
450
549
TEST_RUN (tfw_str_eq_cstr , supports_casei );
451
550
TEST_RUN (tfw_str_eq_cstr , supports_prefix );
551
+ TEST_RUN (tfw_str_eq_cstr_off , supports_suffix );
452
552
453
553
TEST_RUN (tfw_str_eq_cstr_pos , plain );
554
+ TEST_RUN (tfw_str_eq_cstr_off , plain );
454
555
TEST_RUN (tfw_str_eq_cstr_pos , compound );
556
+ TEST_RUN (tfw_str_eq_cstr_off , compound );
455
557
}
0 commit comments