summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Maudsley <richard.maudsley@isode.com>2014-01-23 09:17:05 (GMT)
committerRichard Maudsley <richard.maudsley@isode.com>2014-01-23 09:17:05 (GMT)
commitced0c04c6424c0f1df1f4fa4f86fcdb9bc596ee3 (patch)
tree7f66f89a5ecdf2548a0040d546ba3f971e87fa7e
parent7ddd8856819a3d7540ab1401dab6cd540ebe1210 (diff)
downloadswift-ced0c04c6424c0f1df1f4fa4f86fcdb9bc596ee3.zip
swift-ced0c04c6424c0f1df1f4fa4f86fcdb9bc596ee3.tar.bz2
Added more unit tests.
Change-Id: Idea96a336617632c18ad12e29d8aef7613dd8e59
-rw-r--r--Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp96
1 files changed, 88 insertions, 8 deletions
diff --git a/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp
index a608bfc..4a25b50 100644
--- a/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp
+++ b/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp
@@ -52,23 +52,35 @@ public:
CPPUNIT_ASSERT_EQUAL(text, part->target);
}
- static HighlightRule ruleFromKeyword(const std::string& keyword)
+ static std::vector<HighlightRule> ruleFromKeyword(const std::string& keyword, bool matchCase, bool matchWholeWord)
{
HighlightRule rule;
std::vector<std::string> keywords;
keywords.push_back(keyword);
rule.setKeywords(keywords);
- return rule;
+ rule.setMatchCase(matchCase);
+ rule.setMatchWholeWords(matchWholeWord);
+ std::vector<HighlightRule> rules;
+ rules.push_back(rule);
+ return rules;
+ }
+
+ static std::vector<HighlightRule> ruleFromKeywords(const std::vector<HighlightRule>& rules1, const std::vector<HighlightRule>& rules2)
+ {
+ std::vector<HighlightRule> rules = rules1;
+ rules.insert(rules.end(), rules2.begin(), rules2.end());
+ return rules;
}
void testFullBody() {
- /* initialize rules */
- std::vector<HighlightRule> rules;
- rules.push_back(ruleFromKeyword("trigger"));
+ const std::string no_special_message = "a message with no special content";
+ ChatMessageParser testling(emoticons_, std::vector<HighlightRule>());
+ ChatWindow::ChatMessage result = testling.parseMessageBody(no_special_message);
+ assertText(result, 0, no_special_message);
- ChatMessageParser testling(emoticons_, rules);
- ChatWindow::ChatMessage result = testling.parseMessageBody(":) shiny :( trigger :) http://wonderland.lit/blah http://denmark.lit boom boom");
+ testling = ChatMessageParser(emoticons_, ruleFromKeyword("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 ");
assertEmoticon(result, 2, smile2_, smile2Path_);
@@ -81,6 +93,75 @@ public:
assertText(result, 9, " ");
assertURL(result, 10, "http://denmark.lit");
assertText(result, 11, " boom boom");
+
+ testling = ChatMessageParser(emoticons_, ruleFromKeyword("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));
+ result = testling.parseMessageBody("testtriggermessage");
+ assertText(result, 0, "testtriggermessage");
+
+ testling = ChatMessageParser(emoticons_, ruleFromKeyword("trigger", true, false));
+ result = testling.parseMessageBody("TrIgGeR");
+ assertText(result, 0, "TrIgGeR");
+
+ testling = ChatMessageParser(emoticons_, ruleFromKeyword("trigger", false, false));
+ result = testling.parseMessageBody("TrIgGeR");
+ assertHighlight(result, 0, "TrIgGeR");
+
+ testling = ChatMessageParser(emoticons_, ruleFromKeyword("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)));
+ 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)));
+ 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)));
+ 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)));
+ 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)));
+ 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)));
+ result = testling.parseMessageBody("zeroOnEtwoThReE");
+ assertText(result, 0, "zeroOnEtwo");
+ assertHighlight(result, 1, "ThReE");
+
+ testling = ChatMessageParser(emoticons_, ruleFromKeywords(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)));
+ result = testling.parseMessageBody("zeroonetwothree");
+ assertText(result, 0, "zeroonetwothree");
}
private:
@@ -92,4 +173,3 @@ private:
};
CPPUNIT_TEST_SUITE_REGISTRATION(ChatMessageParserTest);
-