1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // basic_string<charT,traits,Allocator>& assign(const charT* s);
18 #include "test_macros.h"
19 #include "min_allocator.h"
23 test(S s, const typename S::value_type* str, S expected)
26 LIBCPP_ASSERT(s.__invariants());
27 assert(s == expected);
33 typedef std::string S;
35 test(S(), "12345", S("12345"));
36 test(S(), "12345678901234567890", S("12345678901234567890"));
38 test(S("12345"), "", S());
39 test(S("12345"), "12345", S("12345"));
40 test(S("12345"), "1234567890", S("1234567890"));
42 test(S("12345678901234567890"), "", S());
43 test(S("12345678901234567890"), "12345", S("12345"));
44 test(S("12345678901234567890"), "12345678901234567890",
45 S("12345678901234567890"));
47 #if TEST_STD_VER >= 11
49 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
51 test(S(), "12345", S("12345"));
52 test(S(), "12345678901234567890", S("12345678901234567890"));
54 test(S("12345"), "", S());
55 test(S("12345"), "12345", S("12345"));
56 test(S("12345"), "1234567890", S("1234567890"));
58 test(S("12345678901234567890"), "", S());
59 test(S("12345678901234567890"), "12345", S("12345"));
60 test(S("12345678901234567890"), "12345678901234567890",
61 S("12345678901234567890"));
65 { // test assignment to self
66 typedef std::string S;
68 S s_long = "Lorem ipsum dolor sit amet, consectetur/";
70 s_short.assign(s_short.c_str());
71 assert(s_short == "123/");
72 s_short.assign(s_short.c_str() + 2);
73 assert(s_short == "3/");
75 s_long.assign(s_long.c_str() + 30);
76 assert(s_long == "nsectetur/");