Added basic test for interop with std::regex as per Issue #271.

This commit is contained in:
Neil MacIntosh 2016-08-10 19:32:00 -07:00
parent cb6996cd97
commit d6ac640271

View File

@ -23,6 +23,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include <regex>
using namespace std; using namespace std;
using namespace gsl; using namespace gsl;
@ -1243,6 +1244,29 @@ SUITE(span_tests)
}; };
CHECK_THROW(f(), fail_fast); CHECK_THROW(f(), fail_fast);
} }
TEST(interop_with_std_regex)
{
char lat[] = { '1', '2', '3', '4', '5', '6', 'E', 'F', 'G' };
span<char> s = lat;
auto f_it = s.begin() + 7;
std::match_results<span<char>::iterator> match;
std::regex_match(s.begin(), s.end(), match, std::regex(".*"));
CHECK(match.ready());
CHECK(!match.empty());
CHECK(match[0].matched);
CHECK(match[0].first == s.begin());
CHECK(match[0].second == s.end());
std::regex_search(s.begin(), s.end(), match, std::regex("F"));
CHECK(match.ready());
CHECK(!match.empty());
CHECK(match[0].matched);
CHECK(match[0].first == f_it);
CHECK(match[0].second == (f_it + 1));
}
} }
int main(int, const char* []) { return UnitTest::RunAllTests(); } int main(int, const char* []) { return UnitTest::RunAllTests(); }