summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp')
-rw-r--r--Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp53
1 files changed, 29 insertions, 24 deletions
diff --git a/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp
index 4a25b50..9207846 100644
--- a/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp
+++ b/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp
@@ -52,7 +52,7 @@ public:
CPPUNIT_ASSERT_EQUAL(text, part->target);
}
- static std::vector<HighlightRule> ruleFromKeyword(const std::string& keyword, bool matchCase, bool matchWholeWord)
+ static HighlightRule ruleFromKeyword(const std::string& keyword, bool matchCase, bool matchWholeWord)
{
HighlightRule rule;
std::vector<std::string> keywords;
@@ -60,26 +60,31 @@ public:
rule.setKeywords(keywords);
rule.setMatchCase(matchCase);
rule.setMatchWholeWords(matchWholeWord);
- std::vector<HighlightRule> rules;
- rules.push_back(rule);
- return rules;
+ return rule;
}
- static std::vector<HighlightRule> ruleFromKeywords(const std::vector<HighlightRule>& rules1, const std::vector<HighlightRule>& rules2)
+ static const HighlightRulesListPtr ruleListFromKeyword(const std::string& keyword, bool matchCase, bool matchWholeWord)
{
- std::vector<HighlightRule> rules = rules1;
- rules.insert(rules.end(), rules2.begin(), rules2.end());
- return rules;
+ boost::shared_ptr<HighlightManager::HighlightRulesList> list = boost::make_shared<HighlightManager::HighlightRulesList>();
+ list->addRule(ruleFromKeyword(keyword, matchCase, matchWholeWord));
+ return list;
}
- void testFullBody() {
+ static const HighlightRulesListPtr ruleListFromKeywords(const HighlightRule &rule1, const HighlightRule &rule2)
+ {
+ boost::shared_ptr<HighlightManager::HighlightRulesList> list = boost::make_shared<HighlightManager::HighlightRulesList>();
+ list->addRule(rule1);
+ list->addRule(rule2);
+ return list;
+ }
+ void testFullBody() {
const std::string no_special_message = "a message with no special content";
- ChatMessageParser testling(emoticons_, std::vector<HighlightRule>());
+ ChatMessageParser testling(emoticons_, boost::make_shared<HighlightManager::HighlightRulesList>());
ChatWindow::ChatMessage result = testling.parseMessageBody(no_special_message);
assertText(result, 0, no_special_message);
- testling = ChatMessageParser(emoticons_, ruleFromKeyword("trigger", false, false));
+ testling = ChatMessageParser(emoticons_, ruleListFromKeyword("trigger", false, false));
result = testling.parseMessageBody(":) shiny :( trigger :) http://wonderland.lit/blah http://denmark.lit boom boom");
assertEmoticon(result, 0, smile1_, smile1Path_);
assertText(result, 1, " shiny ");
@@ -94,72 +99,72 @@ public:
assertURL(result, 10, "http://denmark.lit");
assertText(result, 11, " boom boom");
- testling = ChatMessageParser(emoticons_, ruleFromKeyword("trigger", false, false));
+ testling = ChatMessageParser(emoticons_, ruleListFromKeyword("trigger", false, false));
result = testling.parseMessageBody("testtriggermessage");
assertText(result, 0, "test");
assertHighlight(result, 1, "trigger");
assertText(result, 2, "message");
- testling = ChatMessageParser(emoticons_, ruleFromKeyword("trigger", false, true));
+ testling = ChatMessageParser(emoticons_, ruleListFromKeyword("trigger", false, true));
result = testling.parseMessageBody("testtriggermessage");
assertText(result, 0, "testtriggermessage");
- testling = ChatMessageParser(emoticons_, ruleFromKeyword("trigger", true, false));
+ testling = ChatMessageParser(emoticons_, ruleListFromKeyword("trigger", true, false));
result = testling.parseMessageBody("TrIgGeR");
assertText(result, 0, "TrIgGeR");
- testling = ChatMessageParser(emoticons_, ruleFromKeyword("trigger", false, false));
+ testling = ChatMessageParser(emoticons_, ruleListFromKeyword("trigger", false, false));
result = testling.parseMessageBody("TrIgGeR");
assertHighlight(result, 0, "TrIgGeR");
- testling = ChatMessageParser(emoticons_, ruleFromKeyword("trigger", false, false));
+ testling = ChatMessageParser(emoticons_, ruleListFromKeyword("trigger", false, false));
result = testling.parseMessageBody("partialTrIgGeRmatch");
assertText(result, 0, "partial");
assertHighlight(result, 1, "TrIgGeR");
assertText(result, 2, "match");
- testling = ChatMessageParser(emoticons_, ruleFromKeywords(ruleFromKeyword("one", false, false), ruleFromKeyword("three", false, false)));
+ testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", false, false), ruleFromKeyword("three", false, false)));
result = testling.parseMessageBody("zero one two three");
assertText(result, 0, "zero ");
assertHighlight(result, 1, "one");
assertText(result, 2, " two ");
assertHighlight(result, 3, "three");
- testling = ChatMessageParser(emoticons_, ruleFromKeywords(ruleFromKeyword("one", false, false), ruleFromKeyword("three", false, false)));
+ testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", false, false), ruleFromKeyword("three", false, false)));
result = testling.parseMessageBody("zero oNe two tHrEe");
assertText(result, 0, "zero ");
assertHighlight(result, 1, "oNe");
assertText(result, 2, " two ");
assertHighlight(result, 3, "tHrEe");
- testling = ChatMessageParser(emoticons_, ruleFromKeywords(ruleFromKeyword("one", false, false), ruleFromKeyword("three", true, false)));
+ testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", false, false), ruleFromKeyword("three", true, false)));
result = testling.parseMessageBody("zero oNe two tHrEe");
assertText(result, 0, "zero ");
assertHighlight(result, 1, "oNe");
assertText(result, 2, " two tHrEe");
- testling = ChatMessageParser(emoticons_, ruleFromKeywords(ruleFromKeyword("one", true, false), ruleFromKeyword("three", true, false)));
+ testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", true, false), ruleFromKeyword("three", true, false)));
result = testling.parseMessageBody("zero oNe two tHrEe");
assertText(result, 0, "zero oNe two tHrEe");
- testling = ChatMessageParser(emoticons_, ruleFromKeywords(ruleFromKeyword("one", false, false), ruleFromKeyword("three", false, false)));
+ testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", false, false), ruleFromKeyword("three", false, false)));
result = testling.parseMessageBody("zeroonetwothree");
assertText(result, 0, "zero");
assertHighlight(result, 1, "one");
assertText(result, 2, "two");
assertHighlight(result, 3, "three");
- testling = ChatMessageParser(emoticons_, ruleFromKeywords(ruleFromKeyword("one", true, false), ruleFromKeyword("three", false, false)));
+ testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", true, false), ruleFromKeyword("three", false, false)));
result = testling.parseMessageBody("zeroOnEtwoThReE");
assertText(result, 0, "zeroOnEtwo");
assertHighlight(result, 1, "ThReE");
- testling = ChatMessageParser(emoticons_, ruleFromKeywords(ruleFromKeyword("one", false, true), ruleFromKeyword("three", false, false)));
+ testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", false, true), ruleFromKeyword("three", false, false)));
result = testling.parseMessageBody("zeroonetwothree");
assertText(result, 0, "zeroonetwo");
assertHighlight(result, 1, "three");
- testling = ChatMessageParser(emoticons_, ruleFromKeywords(ruleFromKeyword("one", false, true), ruleFromKeyword("three", false, true)));
+ testling = ChatMessageParser(emoticons_, ruleListFromKeywords(ruleFromKeyword("one", false, true), ruleFromKeyword("three", false, true)));
result = testling.parseMessageBody("zeroonetwothree");
assertText(result, 0, "zeroonetwothree");
}