UnitTests: add tests for KeywordSearch conflict resolution
parent
9d07edda13
commit
1b302b750c
@ -0,0 +1,48 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include "apps/openmw/mwdialogue/keywordsearch.hpp"
|
||||||
|
|
||||||
|
struct KeywordSearchTest : public ::testing::Test
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
virtual void SetUp()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void TearDown()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(KeywordSearchTest, keyword_test_conflict_resolution)
|
||||||
|
{
|
||||||
|
// test to make sure the longest keyword in a chain of conflicting keywords gets chosen
|
||||||
|
MWDialogue::KeywordSearch<std::string, int> search;
|
||||||
|
search.seed("foo bar", 0);
|
||||||
|
search.seed("bar lock", 0);
|
||||||
|
search.seed("lock switch", 0);
|
||||||
|
|
||||||
|
std::string text = "foo bar lock switch";
|
||||||
|
|
||||||
|
std::vector<MWDialogue::KeywordSearch<std::string, int>::Match> matches;
|
||||||
|
search.highlightKeywords(text.begin(), text.end(), matches);
|
||||||
|
|
||||||
|
// Should contain: "foo bar", "lock switch"
|
||||||
|
ASSERT_TRUE (matches.size() == 2);
|
||||||
|
ASSERT_TRUE (std::string(matches.front().mBeg, matches.front().mEnd) == "foo bar");
|
||||||
|
ASSERT_TRUE (std::string(matches.rbegin()->mBeg, matches.rbegin()->mEnd) == "lock switch");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(KeywordSearchTest, keyword_test_conflict_resolution2)
|
||||||
|
{
|
||||||
|
MWDialogue::KeywordSearch<std::string, int> search;
|
||||||
|
search.seed("the dwemer", 0);
|
||||||
|
search.seed("dwemer language", 0);
|
||||||
|
|
||||||
|
std::string text = "the dwemer language";
|
||||||
|
|
||||||
|
std::vector<MWDialogue::KeywordSearch<std::string, int>::Match> matches;
|
||||||
|
search.highlightKeywords(text.begin(), text.end(), matches);
|
||||||
|
|
||||||
|
ASSERT_TRUE (matches.size() == 1);
|
||||||
|
ASSERT_TRUE (std::string(matches.front().mBeg, matches.front().mEnd) == "dwemer language");
|
||||||
|
}
|
Loading…
Reference in New Issue