blob: 6044dc10473d100100337ca327b4d29a0b25c3d6 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <string>
11
Howard Hinnant6e0a1f42010-08-22 00:47:54 +000012// basic_string<charT,traits,Allocator>&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000013// assign(size_type n, charT c);
14
15#include <string>
16#include <cassert>
17
18template <class S>
19void
20test(S s, typename S::size_type n, typename S::value_type c, S expected)
21{
22 s.assign(n, c);
23 assert(s.__invariants());
24 assert(s == expected);
25}
26
27int main()
28{
29 typedef std::string S;
30 test(S(), 0, 'a', S());
31 test(S(), 1, 'a', S(1, 'a'));
32 test(S(), 10, 'a', S(10, 'a'));
33 test(S(), 100, 'a', S(100, 'a'));
34
35 test(S("12345"), 0, 'a', S());
36 test(S("12345"), 1, 'a', S(1, 'a'));
37 test(S("12345"), 10, 'a', S(10, 'a'));
38
39 test(S("12345678901234567890"), 0, 'a', S());
40 test(S("12345678901234567890"), 1, 'a', S(1, 'a'));
41 test(S("12345678901234567890"), 10, 'a', S(10, 'a'));
42}