]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/21_strings/basic_string/modifiers/append/char/1.cc
3 // Copyright (C) 1999-2014 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 21.3.5.2 basic_string::append
24 #include <testsuite_hooks.h>
28 bool test
__attribute__((unused
)) = true;
29 typedef std::string::size_type csize_type
;
30 typedef std::string::const_reference cref
;
31 typedef std::string::reference ref
;
34 const char str_lit01
[] = "point bolivar, texas";
35 const std::string
str01(str_lit01
);
36 const std::string
str02("corpus, ");
37 const std::string str03
;
41 // string& append(const string&)
44 VERIFY( str05
== "corpus, corpus, " );
46 VERIFY( str05
== "corpus, corpus, point bolivar, texas" );
48 VERIFY( str05
== "corpus, corpus, point bolivar, texas" );
51 VERIFY( str06
== str05
);
54 // string& append(const string&, size_type pos, size_type n)
59 str06
.append(str03
, csz01
+ 1, 0);
62 catch(std::out_of_range
& fail
) {
71 str06
.append(str01
, csz01
+ 1, 0);
74 catch(std::out_of_range
& fail
) {
82 str05
.append(str01
, 0, std::string::npos
);
83 VERIFY( str05
== "corpus, point bolivar, texas" );
84 VERIFY( str05
!= str02
);
87 str06
.append(str01
, 15, std::string::npos
);
88 VERIFY( str06
== "corpus, texas" );
89 VERIFY( str02
!= str06
);
92 // string& append(const char* s)
96 VERIFY( str05
== str03
);
98 str05
.append(str_lit01
);
99 VERIFY( str05
== str01
);
102 str06
.append("corpus, ");
103 VERIFY( str06
== "corpus, corpus, " );
106 // string& append(const char* s, size_type n)
110 VERIFY( str05
.size() == 0 );
111 VERIFY( str05
== str03
);
113 str05
.append(str_lit01
, sizeof(str_lit01
) - 1);
114 VERIFY( str05
== str01
);
117 str06
.append("corpus, ", 6);
118 VERIFY( str06
== "corpus, corpus" );
121 str06
.append("corpus, ", 12);
122 VERIFY( str06
!= "corpus, corpus, " );
125 // string& append(size_type n, char c)
128 str05
.append(0, 'a');
129 VERIFY( str05
== str03
);
130 str06
.append(8, '.');
131 VERIFY( str06
== "........" );
134 // template<typename InputIter>
135 // string& append(InputIter first, InputIter last)
138 str05
.append(str03
.begin(), str03
.end());
139 VERIFY( str05
== str03
);
142 str06
.append(str01
.begin(), str01
.begin() + str01
.find('r'));
143 VERIFY( str06
== "corpus, point boliva" );
144 VERIFY( str06
!= str01
);
145 VERIFY( str06
!= str02
);
148 str05
.append(str05
.begin(), str05
.begin() + str05
.find('r'));
149 VERIFY( str05
== "point bolivar, texaspoint boliva" );
150 VERIFY( str05
!= str01
);