Add support for approximate matching in NFA matcher unit tests

This commit is contained in:
Anatoly Burakov
2017-02-10 15:44:16 +00:00
committed by Matthew Barr
parent 4c2b7cc04f
commit 9f72dede5c
3 changed files with 45 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Intel Corporation
* Copyright (c) 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -76,7 +76,7 @@ class MatchesTest: public TestWithParam<MatchesTestParams> {
static const MatchesTestParams matchesTests[] = {
// EOD and anchored patterns
// these should produce no matches
// these should produce no matches
{ "^foobar", "foolish", {}, 0, false, true},
{ "^foobar$", "ze foobar", {}, 0, false, true},
{ "^foobar$", "foobar ", {}, 0, false, true},
@@ -212,10 +212,19 @@ TEST_P(MatchesTest, Check) {
bool utf8 = (t.flags & HS_FLAG_UTF8) > 0;
set<pair<size_t, size_t>> matches;
findMatches(*g, rm, t.input, matches, t.notEod, t.som, utf8);
findMatches(*g, rm, t.input, matches, 0, t.notEod, utf8);
set<pair<size_t, size_t>> expected(begin(t.matches), end(t.matches));
// findMatches returns matches with SOM, so zero them out if not SOM
if (!t.som) {
set<pair<size_t, size_t>> new_matches;
for (auto &m : matches) {
new_matches.emplace(0, m.second);
}
matches.swap(new_matches);
}
ASSERT_EQ(expected, matches) << "Pattern '" << t.pattern
<< "' against input '" << t.input << "'";
}