| 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); |
nothing calls this directly
no test coverage detected