1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <string> 11 12 // basic_string<charT,traits,Allocator>& 13 // assign(size_type n, charT c); 14 15 #include <string> 16 #include <cassert> 17 18 #include "test_macros.h" 19 #include "min_allocator.h" 20 21 template <class S> 22 void 23 test(S s, typename S::size_type n, typename S::value_type c, S expected) 24 { 25 s.assign(n, c); 26 LIBCPP_ASSERT(s.__invariants()); 27 assert(s == expected); 28 } 29 30 int main() 31 { 32 { 33 typedef std::string S; 34 test(S(), 0, 'a', S()); 35 test(S(), 1, 'a', S(1, 'a')); 36 test(S(), 10, 'a', S(10, 'a')); 37 test(S(), 100, 'a', S(100, 'a')); 38 39 test(S("12345"), 0, 'a', S()); 40 test(S("12345"), 1, 'a', S(1, 'a')); 41 test(S("12345"), 10, 'a', S(10, 'a')); 42 43 test(S("12345678901234567890"), 0, 'a', S()); 44 test(S("12345678901234567890"), 1, 'a', S(1, 'a')); 45 test(S("12345678901234567890"), 10, 'a', S(10, 'a')); 46 } 47 #if TEST_STD_VER >= 11 48 { 49 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; 50 test(S(), 0, 'a', S()); 51 test(S(), 1, 'a', S(1, 'a')); 52 test(S(), 10, 'a', S(10, 'a')); 53 test(S(), 100, 'a', S(100, 'a')); 54 55 test(S("12345"), 0, 'a', S()); 56 test(S("12345"), 1, 'a', S(1, 'a')); 57 test(S("12345"), 10, 'a', S(10, 'a')); 58 59 test(S("12345678901234567890"), 0, 'a', S()); 60 test(S("12345678901234567890"), 1, 'a', S(1, 'a')); 61 test(S("12345678901234567890"), 10, 'a', S(10, 'a')); 62 } 63 #endif 64 } 65