MCPcopy Create free account
hub / github.com/HelenOS/helenos / test_find

Method test_find

uspace/lib/cpp/src/__bits/test/string.cpp:396–638  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

394 }
395
396 void string_test::test_find()
397 {
398 std::string target{"ABC"};
399 auto miss = std::string::npos;
400
401 std::string str1{"xxABCxx"};
402
403 auto idx = str1.find(target, 0);
404 test_eq(
405 "find from start (success)",
406 idx, 2ul
407 );
408
409 idx = str1.find(target, 3);
410 test_eq(
411 "find from start (fail, late start)",
412 idx, miss
413 );
414
415 idx = str1.rfind(target, miss);
416 test_eq(
417 "rfind from end (success)",
418 idx, 2ul
419 );
420
421 idx = str1.rfind(target, 1);
422 test_eq(
423 "rfind from start (fail, late start)",
424 idx, miss
425 );
426
427 idx = str1.find('B', 2);
428 test_eq(
429 "find char from middle (success)",
430 idx, 3ul
431 );
432
433 idx = str1.rfind('B', 2);
434 test_eq(
435 "rfind char from middle (success)",
436 idx, 3ul
437 );
438
439 std::string str2{"xxABCxxABCxx"};
440
441 idx = str2.find(target, 0);
442 test_eq(
443 "find from start (success, multiple)",
444 idx, 2ul
445 );
446
447 idx = str2.find(target, 5);
448 test_eq(
449 "find from middle (success, multiple)",
450 idx, 7ul
451 );
452
453 idx = str2.rfind(target, miss);

Callers

nothing calls this directly

Calls 7

rfindMethod · 0.80
find_first_ofMethod · 0.80
find_last_ofMethod · 0.80
find_first_not_ofMethod · 0.80
find_last_not_ofMethod · 0.80
findMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected