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