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 // append(const basic_string<charT,traits>& str, size_type pos, size_type n = npos);
15 // the "= npos" was added for C++14
21 #include "min_allocator.h"
25 test(S s, S str, typename S::size_type pos, typename S::size_type n, S expected)
29 s.append(str, pos, n);
30 assert(s.__invariants());
31 assert(pos <= str.size());
32 assert(s == expected);
34 catch (std::out_of_range&)
36 assert(pos > str.size());
42 test_npos(S s, S str, typename S::size_type pos, S expected)
47 assert(s.__invariants());
48 assert(pos <= str.size());
49 assert(s == expected);
51 catch (std::out_of_range&)
53 assert(pos > str.size());
60 typedef std::string S;
61 test(S(), S(), 0, 0, S());
62 test(S(), S(), 1, 0, S());
63 test(S(), S("12345"), 0, 3, S("123"));
64 test(S(), S("12345"), 1, 4, S("2345"));
65 test(S(), S("12345"), 3, 15, S("45"));
66 test(S(), S("12345"), 5, 15, S(""));
67 test(S(), S("12345"), 6, 15, S("not happening"));
68 test(S(), S("12345678901234567890"), 0, 0, S());
69 test(S(), S("12345678901234567890"), 1, 1, S("2"));
70 test(S(), S("12345678901234567890"), 2, 3, S("345"));
71 test(S(), S("12345678901234567890"), 12, 13, S("34567890"));
72 test(S(), S("12345678901234567890"), 21, 13, S("not happening"));
74 test(S("12345"), S(), 0, 0, S("12345"));
75 test(S("12345"), S("12345"), 2, 2, S("1234534"));
76 test(S("12345"), S("1234567890"), 0, 100, S("123451234567890"));
78 test(S("12345678901234567890"), S(), 0, 0, S("12345678901234567890"));
79 test(S("12345678901234567890"), S("12345"), 1, 3, S("12345678901234567890234"));
80 test(S("12345678901234567890"), S("12345678901234567890"), 5, 10,
81 S("123456789012345678906789012345"));
83 #if TEST_STD_VER >= 11
85 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
86 test(S(), S(), 0, 0, S());
87 test(S(), S(), 1, 0, S());
88 test(S(), S("12345"), 0, 3, S("123"));
89 test(S(), S("12345"), 1, 4, S("2345"));
90 test(S(), S("12345"), 3, 15, S("45"));
91 test(S(), S("12345"), 5, 15, S(""));
92 test(S(), S("12345"), 6, 15, S("not happening"));
93 test(S(), S("12345678901234567890"), 0, 0, S());
94 test(S(), S("12345678901234567890"), 1, 1, S("2"));
95 test(S(), S("12345678901234567890"), 2, 3, S("345"));
96 test(S(), S("12345678901234567890"), 12, 13, S("34567890"));
97 test(S(), S("12345678901234567890"), 21, 13, S("not happening"));
99 test(S("12345"), S(), 0, 0, S("12345"));
100 test(S("12345"), S("12345"), 2, 2, S("1234534"));
101 test(S("12345"), S("1234567890"), 0, 100, S("123451234567890"));
103 test(S("12345678901234567890"), S(), 0, 0, S("12345678901234567890"));
104 test(S("12345678901234567890"), S("12345"), 1, 3, S("12345678901234567890234"));
105 test(S("12345678901234567890"), S("12345678901234567890"), 5, 10,
106 S("123456789012345678906789012345"));
110 typedef std::string S;
111 test_npos(S(), S(), 0, S());
112 test_npos(S(), S(), 1, S());
113 test_npos(S(), S("12345"), 0, S("12345"));
114 test_npos(S(), S("12345"), 1, S("2345"));
115 test_npos(S(), S("12345"), 3, S("45"));
116 test_npos(S(), S("12345"), 5, S(""));
117 test_npos(S(), S("12345"), 6, S("not happening"));