]>
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 int array_size(const char* (&p
)[N
])
34 for(int 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 std::wstring
wre(regx
.begin(), regx
.end());
73 std::wstring
wtext(text
.begin(), text
.end());
74 boost::wregex
we(wre
);
76 if(boost::regex_match(wtext
, wwhat
, we
, boost::match_extra
))
80 // strange type deduction causes this test to fail on SGI:
81 BOOST_CHECK(wwhat
.size() == ARRAY_SIZE(expected
));
83 for(i
= 0; i
< wwhat
.size(); ++i
)
85 BOOST_CHECK(wwhat
.captures(i
).size() == array_size(expected
[i
]));
86 for(j
= 0; j
< wwhat
.captures(i
).size(); ++j
)
88 BOOST_CHECK(wwhat
.captures(i
)[j
] == make_wstring(expected
[i
][j
]));
94 boost::u32regex ure
= boost::make_u32regex(regx
);
95 what
= boost::smatch();
96 if(boost::u32regex_match(text
, what
, ure
, boost::match_extra
))
100 // strange type deduction causes this test to fail on SGI:
101 BOOST_CHECK(what
.size() == ARRAY_SIZE(expected
));
103 for(i
= 0; i
< what
.size(); ++i
)
105 BOOST_CHECK(what
.captures(i
).size() == array_size(expected
[i
]));
106 for(j
= 0; j
< what
.captures(i
).size(); ++j
)
108 BOOST_CHECK(what
.captures(i
)[j
] == expected
[i
][j
]);
115 int cpp_main(int , char* [])
117 typedef const char* pchar
;
120 { "aBBcccDDDDDeeeeeeee", },
121 { "a", "BB", "ccc", "DDDDD", "eeeeeeee", },
122 { "a", "ccc", "eeeeeeee", },
125 test_captures("(([[:lower:]]+)|([[:upper:]]+))+", "aBBcccDDDDDeeeeeeee", e1
);
132 test_captures("a(b+|((c)*))+d", "abd", e2
);
138 test_captures("(.*)bar|(.*)bah", "abcbar", e3
);
145 test_captures("(.*)bar|(.*)bah", "abcbah", e4
);
148 { "now is the time for all good men to come to the aid of the party" },
149 { "now", "is", "the", "time", "for", "all", "good", "men", "to", "come", "to", "the", "aid", "of", "the", "party" },
151 test_captures("^(?:(\\w+)|(?>\\W+))*$", "now is the time for all good men to come to the aid of the party", e5
);
154 { "now is the time for all good men to come to the aid of the party" },
155 { "now", "is", "the", "time", "for", "all", "good", "men", "to", "come", "to", "the", "aid", "of", "the", "party" },
157 test_captures("^(?>(\\w+)\\W*)*$", "now is the time for all good men to come to the aid of the party", e6
);
160 { "now is the time for all good men to come to the aid of the party" },
162 { "is", "the", "time", "for", "all", "good", "men", "to", "come", "to", "the", "aid", "of", "the" },
165 test_captures("^(\\w+)\\W+(?>(\\w+)\\W+)*(\\w+)$", "now is the time for all good men to come to the aid of the party", e7
);
168 { "now is the time for all good men to come to the aid of the party" } ,
170 { "is", "for", "men", "to", "of" },
171 { "the", "time", "all", "good", "to", "come", "the", "aid", "the" },
174 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
);