]>
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 #define BOOST_TEST_MAIN
17 #include <boost/test/unit_test.hpp>
19 typedef boost::string_ref string_ref
;
22 void interop ( const std::string
&str
, string_ref ref
) {
23 // BOOST_CHECK ( str == ref );
24 BOOST_CHECK ( str
.size () == ref
.size ());
25 BOOST_CHECK ( std::equal ( str
.begin (), str
.end (), ref
.begin ()));
26 BOOST_CHECK ( std::equal ( str
.rbegin (), str
.rend (), ref
.rbegin ()));
29 void null_tests ( const char *p
) {
30 // All zero-length string-refs should be equal
31 string_ref sr1
; // NULL, 0
32 string_ref
sr2 ( NULL
, 0 );
33 string_ref
sr3 ( p
, 0 );
37 BOOST_CHECK ( sr1
== sr2
);
38 BOOST_CHECK ( sr1
== sr3
);
39 BOOST_CHECK ( sr2
== sr3
);
40 BOOST_CHECK ( sr1
== sr4
);
43 // make sure that substrings work just like strings
44 void test_substr ( const std::string
&str
) {
45 const size_t sz
= str
.size ();
46 string_ref
ref ( str
);
48 // Substrings at the end
49 for ( size_t i
= 0; i
<= sz
; ++ i
)
50 interop ( str
.substr ( i
), ref
.substr ( i
));
52 // Substrings at the beginning
53 for ( size_t i
= 0; i
<= sz
; ++ i
)
54 interop ( str
.substr ( 0, i
), ref
.substr ( 0, i
));
56 // All possible substrings
57 for ( size_t i
= 0; i
< sz
; ++i
)
58 for ( size_t j
= i
; j
< sz
; ++j
)
59 interop ( str
.substr ( i
, j
), ref
.substr ( i
, j
));
62 // make sure that removing prefixes and suffixes work just like strings
63 void test_remove ( const std::string
&str
) {
64 const size_t sz
= str
.size ();
68 for ( size_t i
= 1; i
<= sz
; ++i
) {
71 while ( ref
.size () >= i
) {
72 interop ( work
, ref
);
74 ref
.remove_prefix (i
);
78 for ( size_t i
= 1; i
< sz
; ++ i
) {
81 while ( ref
.size () >= i
) {
82 interop ( work
, ref
);
83 work
.erase ( work
.size () - i
, i
);
84 ref
.remove_suffix (i
);
89 const char *test_strings
[] = {
92 "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
97 BOOST_AUTO_TEST_CASE( test_main
)
99 const char **p
= &test_strings
[0];
101 while ( *p
!= NULL
) {