Home | History | Annotate | Download | only in string_assign
      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>& assign(const charT* s);
     13 
     14 #include <string>
     15 #include <stdexcept>
     16 #include <cassert>
     17 
     18 #include "min_allocator.h"
     19 
     20 template <class S>
     21 void
     22 test(S s, const typename S::value_type* str, S expected)
     23 {
     24     s.assign(str);
     25     assert(s.__invariants());
     26     assert(s == expected);
     27 }
     28 
     29 int main()
     30 {
     31     {
     32     typedef std::string S;
     33     test(S(), "", S());
     34     test(S(), "12345", S("12345"));
     35     test(S(), "12345678901234567890", S("12345678901234567890"));
     36 
     37     test(S("12345"), "", S());
     38     test(S("12345"), "12345", S("12345"));
     39     test(S("12345"), "1234567890", S("1234567890"));
     40 
     41     test(S("12345678901234567890"), "", S());
     42     test(S("12345678901234567890"), "12345", S("12345"));
     43     test(S("12345678901234567890"), "12345678901234567890",
     44          S("12345678901234567890"));
     45     }
     46 #if __cplusplus >= 201103L
     47     {
     48     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
     49     test(S(), "", S());
     50     test(S(), "12345", S("12345"));
     51     test(S(), "12345678901234567890", S("12345678901234567890"));
     52 
     53     test(S("12345"), "", S());
     54     test(S("12345"), "12345", S("12345"));
     55     test(S("12345"), "1234567890", S("1234567890"));
     56 
     57     test(S("12345678901234567890"), "", S());
     58     test(S("12345678901234567890"), "12345", S("12345"));
     59     test(S("12345678901234567890"), "12345678901234567890",
     60          S("12345678901234567890"));
     61     }
     62 #endif
     63 }
     64