Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <string> |
| 11 | |
Howard Hinnant | 6e0a1f4 | 2010-08-22 00:47:54 +0000 | [diff] [blame] | 12 | // template<class InputIterator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 13 | // basic_string& append(InputIterator first, InputIterator last); |
| 14 | |
| 15 | #include <string> |
| 16 | #include <cassert> |
| 17 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 18 | #include "../../input_iterator.h" |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 19 | #include "min_allocator.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 20 | |
| 21 | template <class S, class It> |
| 22 | void |
| 23 | test(S s, It first, It last, S expected) |
| 24 | { |
| 25 | s.append(first, last); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 26 | assert(s.__invariants()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 27 | assert(s == expected); |
| 28 | } |
| 29 | |
| 30 | int main() |
| 31 | { |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 32 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 33 | typedef std::string S; |
| 34 | const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; |
| 35 | test(S(), s, s, S()); |
| 36 | test(S(), s, s+1, S("A")); |
| 37 | test(S(), s, s+10, S("ABCDEFGHIJ")); |
| 38 | test(S(), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); |
| 39 | |
| 40 | test(S("12345"), s, s, S("12345")); |
| 41 | test(S("12345"), s, s+1, S("12345A")); |
| 42 | test(S("12345"), s, s+10, S("12345ABCDEFGHIJ")); |
| 43 | test(S("12345"), s, s+52, S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); |
| 44 | |
| 45 | test(S("1234567890"), s, s, S("1234567890")); |
| 46 | test(S("1234567890"), s, s+1, S("1234567890A")); |
| 47 | test(S("1234567890"), s, s+10, S("1234567890ABCDEFGHIJ")); |
| 48 | test(S("1234567890"), s, s+52, S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); |
| 49 | |
| 50 | test(S("12345678901234567890"), s, s, S("12345678901234567890")); |
| 51 | test(S("12345678901234567890"), s, s+1, S("12345678901234567890""A")); |
| 52 | test(S("12345678901234567890"), s, s+10, S("12345678901234567890""ABCDEFGHIJ")); |
| 53 | test(S("12345678901234567890"), s, s+52, |
| 54 | S("12345678901234567890""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); |
| 55 | |
| 56 | test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s), S()); |
| 57 | test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s+1), S("A")); |
| 58 | test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s+10), |
| 59 | S("ABCDEFGHIJ")); |
| 60 | test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s+52), |
| 61 | S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); |
| 62 | |
| 63 | test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s), |
| 64 | S("12345")); |
| 65 | test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+1), |
| 66 | S("12345A")); |
| 67 | test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+10), |
| 68 | S("12345ABCDEFGHIJ")); |
| 69 | test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+52), |
| 70 | S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); |
| 71 | |
| 72 | test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s), |
| 73 | S("1234567890")); |
| 74 | test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1), |
| 75 | S("1234567890A")); |
| 76 | test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10), |
| 77 | S("1234567890ABCDEFGHIJ")); |
| 78 | test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52), |
| 79 | S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); |
| 80 | |
| 81 | test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s), |
| 82 | S("12345678901234567890")); |
| 83 | test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1), |
| 84 | S("12345678901234567890""A")); |
| 85 | test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10), |
| 86 | S("12345678901234567890""ABCDEFGHIJ")); |
| 87 | test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52), |
| 88 | S("12345678901234567890""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 89 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 90 | #if __cplusplus >= 201103L |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 91 | { |
| 92 | typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; |
| 93 | const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; |
| 94 | test(S(), s, s, S()); |
| 95 | test(S(), s, s+1, S("A")); |
| 96 | test(S(), s, s+10, S("ABCDEFGHIJ")); |
| 97 | test(S(), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); |
| 98 | |
| 99 | test(S("12345"), s, s, S("12345")); |
| 100 | test(S("12345"), s, s+1, S("12345A")); |
| 101 | test(S("12345"), s, s+10, S("12345ABCDEFGHIJ")); |
| 102 | test(S("12345"), s, s+52, S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); |
| 103 | |
| 104 | test(S("1234567890"), s, s, S("1234567890")); |
| 105 | test(S("1234567890"), s, s+1, S("1234567890A")); |
| 106 | test(S("1234567890"), s, s+10, S("1234567890ABCDEFGHIJ")); |
| 107 | test(S("1234567890"), s, s+52, S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); |
| 108 | |
| 109 | test(S("12345678901234567890"), s, s, S("12345678901234567890")); |
| 110 | test(S("12345678901234567890"), s, s+1, S("12345678901234567890""A")); |
| 111 | test(S("12345678901234567890"), s, s+10, S("12345678901234567890""ABCDEFGHIJ")); |
| 112 | test(S("12345678901234567890"), s, s+52, |
| 113 | S("12345678901234567890""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); |
| 114 | |
| 115 | test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s), S()); |
| 116 | test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s+1), S("A")); |
| 117 | test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s+10), |
| 118 | S("ABCDEFGHIJ")); |
| 119 | test(S(), input_iterator<const char*>(s), input_iterator<const char*>(s+52), |
| 120 | S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); |
| 121 | |
| 122 | test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s), |
| 123 | S("12345")); |
| 124 | test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+1), |
| 125 | S("12345A")); |
| 126 | test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+10), |
| 127 | S("12345ABCDEFGHIJ")); |
| 128 | test(S("12345"), input_iterator<const char*>(s), input_iterator<const char*>(s+52), |
| 129 | S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); |
| 130 | |
| 131 | test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s), |
| 132 | S("1234567890")); |
| 133 | test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1), |
| 134 | S("1234567890A")); |
| 135 | test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10), |
| 136 | S("1234567890ABCDEFGHIJ")); |
| 137 | test(S("1234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52), |
| 138 | S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); |
| 139 | |
| 140 | test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s), |
| 141 | S("12345678901234567890")); |
| 142 | test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+1), |
| 143 | S("12345678901234567890""A")); |
| 144 | test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+10), |
| 145 | S("12345678901234567890""ABCDEFGHIJ")); |
| 146 | test(S("12345678901234567890"), input_iterator<const char*>(s), input_iterator<const char*>(s+52), |
| 147 | S("12345678901234567890""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); |
| 148 | } |
| 149 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 150 | } |