[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.modifiers / string_assign / pointer.pass.cpp
blob325c354c56ae70254e4fbeda6f15a9e675718209
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // <string>
11 // basic_string<charT,traits,Allocator>& assign(const charT* s);
13 #include <string>
14 #include <stdexcept>
15 #include <cassert>
17 #include "test_macros.h"
18 #include "min_allocator.h"
20 template <class S>
21 void
22 test(S s, const typename S::value_type* str, S expected)
24 s.assign(str);
25 LIBCPP_ASSERT(s.__invariants());
26 assert(s == expected);
29 int main(int, char**)
32 typedef std::string S;
33 test(S(), "", S());
34 test(S(), "12345", S("12345"));
35 test(S(), "12345678901234567890", S("12345678901234567890"));
37 test(S("12345"), "", S());
38 test(S("12345"), "12345", S("12345"));
39 test(S("12345"), "1234567890", S("1234567890"));
41 test(S("12345678901234567890"), "", S());
42 test(S("12345678901234567890"), "12345", S("12345"));
43 test(S("12345678901234567890"), "12345678901234567890",
44 S("12345678901234567890"));
46 #if TEST_STD_VER >= 11
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"));
53 test(S("12345"), "", S());
54 test(S("12345"), "12345", S("12345"));
55 test(S("12345"), "1234567890", S("1234567890"));
57 test(S("12345678901234567890"), "", S());
58 test(S("12345678901234567890"), "12345", S("12345"));
59 test(S("12345678901234567890"), "12345678901234567890",
60 S("12345678901234567890"));
62 #endif
64 { // test assignment to self
65 typedef std::string S;
66 S s_short = "123/";
67 S s_long = "Lorem ipsum dolor sit amet, consectetur/";
69 s_short.assign(s_short.c_str());
70 assert(s_short == "123/");
71 s_short.assign(s_short.c_str() + 2);
72 assert(s_short == "3/");
74 s_long.assign(s_long.c_str() + 30);
75 assert(s_long == "nsectetur/");
78 return 0;