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 //===----------------------------------------------------------------------===//
10 // XFAIL: libcpp-no-exceptions
13 // basic_string<charT,traits,Allocator>&
14 // assign(const basic_string<charT,traits>& str, size_type pos, size_type n=npos);
15 // the =npos was added for C++14
21 #include "test_macros.h"
22 #include "min_allocator.h"
26 test(S s, S str, typename S::size_type pos, typename S::size_type n, S expected)
30 s.assign(str, pos, n);
31 LIBCPP_ASSERT(s.__invariants());
32 assert(pos <= str.size());
33 assert(s == expected);
35 catch (std::out_of_range&)
37 assert(pos > str.size());
43 test_npos(S s, S str, typename S::size_type pos, S expected)
48 LIBCPP_ASSERT(s.__invariants());
49 assert(pos <= str.size());
50 assert(s == expected);
52 catch (std::out_of_range&)
54 assert(pos > str.size());
61 typedef std::string S;
62 test(S(), S(), 0, 0, S());
63 test(S(), S(), 1, 0, S());
64 test(S(), S("12345"), 0, 3, S("123"));
65 test(S(), S("12345"), 1, 4, S("2345"));
66 test(S(), S("12345"), 3, 15, S("45"));
67 test(S(), S("12345"), 5, 15, S(""));
68 test(S(), S("12345"), 6, 15, S("not happening"));
69 test(S(), S("12345678901234567890"), 0, 0, S());
70 test(S(), S("12345678901234567890"), 1, 1, S("2"));
71 test(S(), S("12345678901234567890"), 2, 3, S("345"));
72 test(S(), S("12345678901234567890"), 12, 13, S("34567890"));
73 test(S(), S("12345678901234567890"), 21, 13, S("not happening"));
75 test(S("12345"), S(), 0, 0, S());
76 test(S("12345"), S("12345"), 2, 2, S("34"));
77 test(S("12345"), S("1234567890"), 0, 100, S("1234567890"));
79 test(S("12345678901234567890"), S(), 0, 0, S());
80 test(S("12345678901234567890"), S("12345"), 1, 3, S("234"));
81 test(S("12345678901234567890"), S("12345678901234567890"), 5, 10,
84 #if TEST_STD_VER >= 11
86 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
87 test(S(), S(), 0, 0, S());
88 test(S(), S(), 1, 0, S());
89 test(S(), S("12345"), 0, 3, S("123"));
90 test(S(), S("12345"), 1, 4, S("2345"));
91 test(S(), S("12345"), 3, 15, S("45"));
92 test(S(), S("12345"), 5, 15, S(""));
93 test(S(), S("12345"), 6, 15, S("not happening"));
94 test(S(), S("12345678901234567890"), 0, 0, S());
95 test(S(), S("12345678901234567890"), 1, 1, S("2"));
96 test(S(), S("12345678901234567890"), 2, 3, S("345"));
97 test(S(), S("12345678901234567890"), 12, 13, S("34567890"));
98 test(S(), S("12345678901234567890"), 21, 13, S("not happening"));
100 test(S("12345"), S(), 0, 0, S());
101 test(S("12345"), S("12345"), 2, 2, S("34"));
102 test(S("12345"), S("1234567890"), 0, 100, S("1234567890"));
104 test(S("12345678901234567890"), S(), 0, 0, S());
105 test(S("12345678901234567890"), S("12345"), 1, 3, S("234"));
106 test(S("12345678901234567890"), S("12345678901234567890"), 5, 10,
111 typedef std::string S;
112 test_npos(S(), S(), 0, S());
113 test_npos(S(), S(), 1, S());
114 test_npos(S(), S("12345"), 0, S("12345"));
115 test_npos(S(), S("12345"), 1, S("2345"));
116 test_npos(S(), S("12345"), 3, S("45"));
117 test_npos(S(), S("12345"), 5, S(""));
118 test_npos(S(), S("12345"), 6, S("not happening"));