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 | // basic_string<charT,traits,Allocator>& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 13 | // assign(basic_string<charT,traits>&& str); |
| 14 | |
| 15 | #include <string> |
Marshall Clow | 6b913d7 | 2015-01-09 20:25:52 +0000 | [diff] [blame] | 16 | #include <utility> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 17 | #include <cassert> |
| 18 | |
Eric Fiselier | 375e2f6 | 2016-04-28 22:28:23 +0000 | [diff] [blame] | 19 | #include "test_macros.h" |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 20 | #include "min_allocator.h" |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 21 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 22 | template <class S> |
| 23 | void |
| 24 | test(S s, S str, S expected) |
| 25 | { |
| 26 | s.assign(std::move(str)); |
Eric Fiselier | 375e2f6 | 2016-04-28 22:28:23 +0000 | [diff] [blame] | 27 | LIBCPP_ASSERT(s.__invariants()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 28 | assert(s == expected); |
| 29 | } |
| 30 | |
| 31 | int main() |
| 32 | { |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 33 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 34 | typedef std::string S; |
| 35 | test(S(), S(), S()); |
| 36 | test(S(), S("12345"), S("12345")); |
| 37 | test(S(), S("1234567890"), S("1234567890")); |
| 38 | test(S(), S("12345678901234567890"), S("12345678901234567890")); |
| 39 | |
| 40 | test(S("12345"), S(), S()); |
| 41 | test(S("12345"), S("12345"), S("12345")); |
| 42 | test(S("12345"), S("1234567890"), S("1234567890")); |
| 43 | test(S("12345"), S("12345678901234567890"), S("12345678901234567890")); |
| 44 | |
| 45 | test(S("1234567890"), S(), S()); |
| 46 | test(S("1234567890"), S("12345"), S("12345")); |
| 47 | test(S("1234567890"), S("1234567890"), S("1234567890")); |
| 48 | test(S("1234567890"), S("12345678901234567890"), S("12345678901234567890")); |
| 49 | |
| 50 | test(S("12345678901234567890"), S(), S()); |
| 51 | test(S("12345678901234567890"), S("12345"), S("12345")); |
| 52 | test(S("12345678901234567890"), S("1234567890"), S("1234567890")); |
| 53 | test(S("12345678901234567890"), S("12345678901234567890"), |
| 54 | S("12345678901234567890")); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 55 | } |
Marshall Clow | df9db31 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 56 | #if TEST_STD_VER >= 11 |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 57 | { |
| 58 | typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; |
| 59 | test(S(), S(), S()); |
| 60 | test(S(), S("12345"), S("12345")); |
| 61 | test(S(), S("1234567890"), S("1234567890")); |
| 62 | test(S(), S("12345678901234567890"), S("12345678901234567890")); |
| 63 | |
| 64 | test(S("12345"), S(), S()); |
| 65 | test(S("12345"), S("12345"), S("12345")); |
| 66 | test(S("12345"), S("1234567890"), S("1234567890")); |
| 67 | test(S("12345"), S("12345678901234567890"), S("12345678901234567890")); |
| 68 | |
| 69 | test(S("1234567890"), S(), S()); |
| 70 | test(S("1234567890"), S("12345"), S("12345")); |
| 71 | test(S("1234567890"), S("1234567890"), S("1234567890")); |
| 72 | test(S("1234567890"), S("12345678901234567890"), S("12345678901234567890")); |
| 73 | |
| 74 | test(S("12345678901234567890"), S(), S()); |
| 75 | test(S("12345678901234567890"), S("12345"), S("12345")); |
| 76 | test(S("12345678901234567890"), S("1234567890"), S("1234567890")); |
| 77 | test(S("12345678901234567890"), S("12345678901234567890"), |
| 78 | S("12345678901234567890")); |
| 79 | } |
| 80 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 81 | } |