blob: adf24ac49877e37458df8f0154d7af8dbc1bf3be [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
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
Marshall Clow061d0cc2013-11-26 20:58:02 +000018#include "min_allocator.h"
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000019
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000020template <class S>
21void
22test(S s, const typename S::value_type* str, S expected)
23{
24 s.assign(str);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070025 assert(s.__invariants());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000026 assert(s == expected);
27}
28
29int main()
30{
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000031 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000032 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"));
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000045 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070046#if __cplusplus >= 201103L
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000047 {
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
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000063}