]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/regex/test/captures/captures_test.cpp
6 * Use, modification and distribution are subject to the
7 * Boost Software License, Version 1.0. (See accompanying file
8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
13 * LOCATION: see http://www.boost.org for most recent version.
14 * FILE captures_test.cpp
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: Basic tests for additional captures information.
19 #include <boost/regex.hpp>
20 #include <boost/detail/lightweight_main.hpp>
21 #include "../test_macros.hpp"
22 #include <boost/array.hpp>
26 #include <boost/regex/icu.hpp>
29 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
32 size_t array_size(const char* (&p
)[N
])
34 for(size_t i
= 0; i
< N
; ++i
)
40 std::wstring
make_wstring(const char* p
)
42 return std::wstring(p
, p
+ std::strlen(p
));
47 void test_captures(const std::string
& regx
, const std::string
& text
, const T
& expected
)
50 void test_captures(const std::string
& regx
, const std::string
& text
, T
& expected
)
55 if(boost::regex_match(text
, what
, e
, boost::match_extra
))
59 // strange type deduction causes this test to fail on SGI:
60 BOOST_CHECK(what
.size() == ARRAY_SIZE(expected
));
62 for(i
= 0; i
< what
.size(); ++i
)
64 BOOST_CHECK(what
.captures(i
).size() == array_size(expected
[i
]));
65 for(j
= 0; j
< what
.captures(i
).size(); ++j
)
67 BOOST_CHECK(what
.captures(i
)[j
] == expected
[i
][j
]);
72 #if !defined(BOOST_NO_WREGEX)
74 std::wstring
wre(regx
.begin(), regx
.end());
75 std::wstring
wtext(text
.begin(), text
.end());
76 boost::wregex
we(wre
);
78 if(boost::regex_match(wtext
, wwhat
, we
, boost::match_extra
))
82 // strange type deduction causes this test to fail on SGI:
83 BOOST_CHECK(wwhat
.size() == ARRAY_SIZE(expected
));
85 for(i
= 0; i
< wwhat
.size(); ++i
)
87 BOOST_CHECK(wwhat
.captures(i
).size() == array_size(expected
[i
]));
88 for(j
= 0; j
< wwhat
.captures(i
).size(); ++j
)
90 BOOST_CHECK(wwhat
.captures(i
)[j
] == make_wstring(expected
[i
][j
]));
98 boost::u32regex ure
= boost::make_u32regex(regx
);
99 what
= boost::smatch();
100 if(boost::u32regex_match(text
, what
, ure
, boost::match_extra
))
104 // strange type deduction causes this test to fail on SGI:
105 BOOST_CHECK(what
.size() == ARRAY_SIZE(expected
));
107 for(i
= 0; i
< what
.size(); ++i
)
109 BOOST_CHECK(what
.captures(i
).size() == array_size(expected
[i
]));
110 for(j
= 0; j
< what
.captures(i
).size(); ++j
)
112 BOOST_CHECK(what
.captures(i
)[j
] == expected
[i
][j
]);
119 int cpp_main(int , char* [])
121 typedef const char* pchar
;
124 { "aBBcccDDDDDeeeeeeee", },
125 { "a", "BB", "ccc", "DDDDD", "eeeeeeee", },
126 { "a", "ccc", "eeeeeeee", },
129 test_captures("(([[:lower:]]+)|([[:upper:]]+))+", "aBBcccDDDDDeeeeeeee", e1
);
136 test_captures("a(b+|((c)*))+d", "abd", e2
);
142 test_captures("(.*)bar|(.*)bah", "abcbar", e3
);
149 test_captures("(.*)bar|(.*)bah", "abcbah", e4
);
152 { "now is the time for all good men to come to the aid of the party" },
153 { "now", "is", "the", "time", "for", "all", "good", "men", "to", "come", "to", "the", "aid", "of", "the", "party" },
155 test_captures("^(?:(\\w+)|(?>\\W+))*$", "now is the time for all good men to come to the aid of the party", e5
);
158 { "now is the time for all good men to come to the aid of the party" },
159 { "now", "is", "the", "time", "for", "all", "good", "men", "to", "come", "to", "the", "aid", "of", "the", "party" },
161 test_captures("^(?>(\\w+)\\W*)*$", "now is the time for all good men to come to the aid of the party", e6
);
164 { "now is the time for all good men to come to the aid of the party" },
166 { "is", "the", "time", "for", "all", "good", "men", "to", "come", "to", "the", "aid", "of", "the" },
169 test_captures("^(\\w+)\\W+(?>(\\w+)\\W+)*(\\w+)$", "now is the time for all good men to come to the aid of the party", e7
);
172 { "now is the time for all good men to come to the aid of the party" } ,
174 { "is", "for", "men", "to", "of" },
175 { "the", "time", "all", "good", "to", "come", "the", "aid", "the" },
178 test_captures("^(\\w+)\\W+(?>(\\w+)\\W+(?:(\\w+)\\W+){0,2})*(\\w+)$", "now is the time for all good men to come to the aid of the party", e8
);