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(const basic_string<charT,traits>& str);
     14 
     15 #include <string>
     16 #include <cassert>
     17 
     18 #include "test_macros.h"
     19 #include "min_allocator.h"
     20 
     21 template <class S>
     22 void
     23 test(S s, S str, S expected)
     24 {
     25     s.append(str);
     26     LIBCPP_ASSERT(s.__invariants());
     27     assert(s == expected);
     28 }
     29 
     30 int main()
     31 {
     32     {
     33     typedef std::string S;
     34     test(S(), S(), S());
     35     test(S(), S("12345"), S("12345"));
     36     test(S(), S("1234567890"), S("1234567890"));
     37     test(S(), S("12345678901234567890"), S("12345678901234567890"));
     38 
     39     test(S("12345"), S(), S("12345"));
     40     test(S("12345"), S("12345"), S("1234512345"));
     41     test(S("12345"), S("1234567890"), S("123451234567890"));
     42     test(S("12345"), S("12345678901234567890"), S("1234512345678901234567890"));
     43 
     44     test(S("1234567890"), S(), S("1234567890"));
     45     test(S("1234567890"), S("12345"), S("123456789012345"));
     46     test(S("1234567890"), S("1234567890"), S("12345678901234567890"));
     47     test(S("1234567890"), S("12345678901234567890"), S("123456789012345678901234567890"));
     48 
     49     test(S("12345678901234567890"), S(), S("12345678901234567890"));
     50     test(S("12345678901234567890"), S("12345"), S("1234567890123456789012345"));
     51     test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890"));
     52     test(S("12345678901234567890"), S("12345678901234567890"),
     53          S("1234567890123456789012345678901234567890"));
     54     }
     55 #if TEST_STD_VER >= 11
     56     {
     57     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
     58     test(S(), S(), S());
     59     test(S(), S("12345"), S("12345"));
     60     test(S(), S("1234567890"), S("1234567890"));
     61     test(S(), S("12345678901234567890"), S("12345678901234567890"));
     62 
     63     test(S("12345"), S(), S("12345"));
     64     test(S("12345"), S("12345"), S("1234512345"));
     65     test(S("12345"), S("1234567890"), S("123451234567890"));
     66     test(S("12345"), S("12345678901234567890"), S("1234512345678901234567890"));
     67 
     68     test(S("1234567890"), S(), S("1234567890"));
     69     test(S("1234567890"), S("12345"), S("123456789012345"));
     70     test(S("1234567890"), S("1234567890"), S("12345678901234567890"));
     71     test(S("1234567890"), S("12345678901234567890"), S("123456789012345678901234567890"));
     72 
     73     test(S("12345678901234567890"), S(), S("12345678901234567890"));
     74     test(S("12345678901234567890"), S("12345"), S("1234567890123456789012345"));
     75     test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890"));
     76     test(S("12345678901234567890"), S("12345678901234567890"),
     77          S("1234567890123456789012345678901234567890"));
     78     }
     79 #endif
     80 }
     81