Home | History | Annotate | Download | only in string_op_plus_equal
      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 //   operator+=(const basic_string<charT,traits,Allocator>& str);
     14 
     15 #include <string>
     16 #include <cassert>
     17 
     18 template <class S>
     19 void
     20 test(S s, S str, S expected)
     21 {
     22     s += str;
     23     assert(s.__invariants());
     24     assert(s == expected);
     25 }
     26 
     27 int main()
     28 {
     29     typedef std::string S;
     30     test(S(), S(), S());
     31     test(S(), S("12345"), S("12345"));
     32     test(S(), S("1234567890"), S("1234567890"));
     33     test(S(), S("12345678901234567890"), S("12345678901234567890"));
     34 
     35     test(S("12345"), S(), S("12345"));
     36     test(S("12345"), S("12345"), S("1234512345"));
     37     test(S("12345"), S("1234567890"), S("123451234567890"));
     38     test(S("12345"), S("12345678901234567890"), S("1234512345678901234567890"));
     39 
     40     test(S("1234567890"), S(), S("1234567890"));
     41     test(S("1234567890"), S("12345"), S("123456789012345"));
     42     test(S("1234567890"), S("1234567890"), S("12345678901234567890"));
     43     test(S("1234567890"), S("12345678901234567890"), S("123456789012345678901234567890"));
     44 
     45     test(S("12345678901234567890"), S(), S("12345678901234567890"));
     46     test(S("12345678901234567890"), S("12345"), S("1234567890123456789012345"));
     47     test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890"));
     48     test(S("12345678901234567890"), S("12345678901234567890"),
     49          S("1234567890123456789012345678901234567890"));
     50 }
     51