Changeset 9315761 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:
b1b500b
Parents:
dc0fff11
git-author:
Jaroslav Jindrak <dzejrou@…> (2017-10-30 13:48:33)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:18)
Message:

cpp: added tests for string::append and string::operator+=

Location:
uspace/lib/cpp
Files:
2 edited

Legend:

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

    rdc0fff11 r9315761  
    6767        private:
    6868            void test_construction_and_assignment();
     69            void test_append();
    6970    };
    7071}
  • uspace/lib/cpp/src/internal/test/string.cpp

    rdc0fff11 r9315761  
    3737    {
    3838        test_construction_and_assignment();
     39        test_append();
    3940
    4041        return true;
     
    8182        std::string str4{};
    8283        test_eq(
    83             "default constrcutor empty",
     84            "default constructor empty",
    8485            str4.size(), 0ul
    8586        );
     
    8788        str4.assign(str3, 2ul, 2ul);
    8889        test_eq(
    89             "assign substring to empty string",
     90            "assign substring to an empty string",
    9091            str4.begin(), str4.end(),
    9192            str3.begin() + 2, str3.begin() + 4
     
    99100        );
    100101    }
     102
     103    void string_test::test_append()
     104    {
     105        std::string check{"hello, world"};
     106
     107        std::string str1{"hello, "};
     108        str1.append("world");
     109        test_eq(
     110            "append cstring",
     111            str1.begin(), str1.end(),
     112            check.begin(), check.end()
     113        );
     114
     115        std::string str2{"hello, "};
     116        str2.append(std::string{"world"});
     117        test_eq(
     118            "append rvalue string",
     119            str2.begin(), str2.end(),
     120            check.begin(), check.end()
     121        );
     122
     123        std::string str3{"hello, "};
     124        std::string apendee{"world"};
     125        str3.append(apendee);
     126        test_eq(
     127            "append lvalue string",
     128            str3.begin(), str3.end(),
     129            check.begin(), check.end()
     130        );
     131
     132        std::string str4{"hello, "};
     133        str4.append(apendee.begin(), apendee.end());
     134        test_eq(
     135            "append iterator range",
     136            str4.begin(), str4.end(),
     137            check.begin(), check.end()
     138        );
     139
     140        std::string str5{"hello, "};
     141        str5.append({'w', 'o', 'r', 'l', 'd', '\0'});
     142        test_eq(
     143            "append initializer list",
     144            str5.begin(), str5.end(),
     145            check.begin(), check.end()
     146        );
     147
     148        std::string str6{"hello, "};
     149        str6 += "world";
     150        test_eq(
     151            "append using +=",
     152            str6.begin(), str6.end(),
     153            check.begin(), check.end()
     154        );
     155    }
    101156}
Note: See TracChangeset for help on using the changeset viewer.