]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/utility/test/string_ref_test1.cpp
2 Copyright (c) Marshall Clow 2012-2012.
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 For more information, see http://www.boost.org
14 #include <boost/utility/string_ref.hpp>
16 #include <boost/core/lightweight_test.hpp>
18 typedef boost::string_ref string_ref
;
21 void interop ( const std::string
&str
, string_ref ref
) {
22 // BOOST_TEST ( str == ref );
23 BOOST_TEST ( str
.size () == ref
.size ());
24 BOOST_TEST ( std::equal ( str
.begin (), str
.end (), ref
.begin ()));
25 BOOST_TEST ( std::equal ( str
.rbegin (), str
.rend (), ref
.rbegin ()));
28 void null_tests ( const char *p
) {
29 // All zero-length string-refs should be equal
30 string_ref sr1
; // NULL, 0
31 string_ref
sr2 ( NULL
, 0 );
32 string_ref
sr3 ( p
, 0 );
36 BOOST_TEST ( sr1
== sr2
);
37 BOOST_TEST ( sr1
== sr3
);
38 BOOST_TEST ( sr2
== sr3
);
39 BOOST_TEST ( sr1
== sr4
);
42 // make sure that substrings work just like strings
43 void test_substr ( const std::string
&str
) {
44 const size_t sz
= str
.size ();
45 string_ref
ref ( str
);
47 // Substrings at the end
48 for ( size_t i
= 0; i
<= sz
; ++ i
)
49 interop ( str
.substr ( i
), ref
.substr ( i
));
51 // Substrings at the beginning
52 for ( size_t i
= 0; i
<= sz
; ++ i
)
53 interop ( str
.substr ( 0, i
), ref
.substr ( 0, i
));
55 // All possible substrings
56 for ( size_t i
= 0; i
< sz
; ++i
)
57 for ( size_t j
= i
; j
< sz
; ++j
)
58 interop ( str
.substr ( i
, j
), ref
.substr ( i
, j
));
61 // make sure that removing prefixes and suffixes work just like strings
62 void test_remove ( const std::string
&str
) {
63 const size_t sz
= str
.size ();
67 for ( size_t i
= 1; i
<= sz
; ++i
) {
70 while ( ref
.size () >= i
) {
71 interop ( work
, ref
);
73 ref
.remove_prefix (i
);
77 for ( size_t i
= 1; i
< sz
; ++ i
) {
80 while ( ref
.size () >= i
) {
81 interop ( work
, ref
);
82 work
.erase ( work
.size () - i
, i
);
83 ref
.remove_suffix (i
);
88 const char *test_strings
[] = {
91 "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
98 const char **p
= &test_strings
[0];
100 while ( *p
!= NULL
) {
109 return boost::report_errors();