Home | History | Annotate | Download | only in string_append
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <string>
     11 
     12 // basic_string<charT,traits,Allocator>&
     13 //   append(basic_string_view<charT,traits> sv);
     14 
     15 #include <string>
     16 #include <string_view>
     17 #include <cassert>
     18 
     19 #include "test_macros.h"
     20 #include "min_allocator.h"
     21 
     22 template <class S, class SV>
     23 void
     24 test(S s, SV sv, S expected)
     25 {
     26     s.append(sv);
     27     LIBCPP_ASSERT(s.__invariants());
     28     assert(s == expected);
     29 }
     30 
     31 int main()
     32 {
     33     {
     34     typedef std::string S;
     35     typedef std::string_view SV;
     36     test(S(), SV(), S());
     37     test(S(), SV("12345"), S("12345"));
     38     test(S(), SV("1234567890"), S("1234567890"));
     39     test(S(), SV("12345678901234567890"), S("12345678901234567890"));
     40 
     41     test(S("12345"), SV(), S("12345"));
     42     test(S("12345"), SV("12345"), S("1234512345"));
     43     test(S("12345"), SV("1234567890"), S("123451234567890"));
     44     test(S("12345"), SV("12345678901234567890"), S("1234512345678901234567890"));
     45 
     46     test(S("1234567890"), SV(), S("1234567890"));
     47     test(S("1234567890"), SV("12345"), S("123456789012345"));
     48     test(S("1234567890"), SV("1234567890"), S("12345678901234567890"));
     49     test(S("1234567890"), SV("12345678901234567890"), S("123456789012345678901234567890"));
     50 
     51     test(S("12345678901234567890"), SV(), S("12345678901234567890"));
     52     test(S("12345678901234567890"), SV("12345"), S("1234567890123456789012345"));
     53     test(S("12345678901234567890"), SV("1234567890"), S("123456789012345678901234567890"));
     54     test(S("12345678901234567890"), SV("12345678901234567890"),
     55          S("1234567890123456789012345678901234567890"));
     56     }
     57 #if TEST_STD_VER >= 11
     58     {
     59     typedef std::basic_string     <char, std::char_traits<char>, min_allocator<char>> S;
     60     typedef std::basic_string_view<char, std::char_traits<char> > SV;
     61     test(S(), SV(), S());
     62     test(S(), SV("12345"), S("12345"));
     63     test(S(), SV("1234567890"), S("1234567890"));
     64     test(S(), SV("12345678901234567890"), S("12345678901234567890"));
     65 
     66     test(S("12345"), SV(), S("12345"));
     67     test(S("12345"), SV("12345"), S("1234512345"));
     68     test(S("12345"), SV("1234567890"), S("123451234567890"));
     69     test(S("12345"), SV("12345678901234567890"), S("1234512345678901234567890"));
     70 
     71     test(S("1234567890"), SV(), S("1234567890"));
     72     test(S("1234567890"), SV("12345"), S("123456789012345"));
     73     test(S("1234567890"), SV("1234567890"), S("12345678901234567890"));
     74     test(S("1234567890"), SV("12345678901234567890"), S("123456789012345678901234567890"));
     75 
     76     test(S("12345678901234567890"), SV(), S("12345678901234567890"));
     77     test(S("12345678901234567890"), SV("12345"), S("1234567890123456789012345"));
     78     test(S("12345678901234567890"), SV("1234567890"), S("123456789012345678901234567890"));
     79     test(S("12345678901234567890"), SV("12345678901234567890"),
     80          S("1234567890123456789012345678901234567890"));
     81     }
     82 #endif
     83 }
     84