Changeset 923b0c8f in mainline


Ignore:
Timestamp:
2018-07-05T21:41:18Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d3bca35
Parents:
173a246
git-author:
Jaroslav Jindrak <dzejrou@…> (2017-11-01 21:02:29)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:18)
Message:

cpp: added some basic std::string::{r,}find tests

Location:
uspace/lib/cpp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/internal/test/tests.hpp

    r173a246 r923b0c8f  
    7272            void test_replace();
    7373            void test_copy();
     74            void test_find();
    7475    };
    7576}
  • uspace/lib/cpp/src/internal/test/string.cpp

    r173a246 r923b0c8f  
    4242        test_replace();
    4343        test_copy();
     44        test_find();
    4445
    4546        return true;
     
    387388        );
    388389    }
     390
     391    void string_test::test_find()
     392    {
     393        std::string target{"ABC"};
     394        auto miss = std::string::npos;
     395
     396        std::string str1{"xxABCxx"};
     397
     398        auto idx = str1.find(target, 0);
     399        test_eq(
     400            "find from start (success)",
     401            idx, 2ul
     402        );
     403
     404        idx = str1.find(target, 3);
     405        test_eq(
     406            "find from start (fail, late start)",
     407            idx, miss
     408        );
     409
     410        idx = str1.rfind(target, miss);
     411        test_eq(
     412            "rfind from start (success)",
     413            idx, 2ul
     414        );
     415
     416        idx = str1.rfind(target, 1);
     417        test_eq(
     418            "rfind from start (fail, late start)",
     419            idx, miss
     420        );
     421
     422        std::string str2{"xxABCxxABCxx"};
     423
     424        idx = str2.find(target, 0);
     425        test_eq(
     426            "find from start (success, multiple)",
     427            idx, 2ul
     428        );
     429    }
    389430}
Note: See TracChangeset for help on using the changeset viewer.