diff options
author | Richard Maudsley <richard.maudsley@isode.com> | 2014-01-22 15:50:48 (GMT) |
---|---|---|
committer | Richard Maudsley <richard.maudsley@isode.com> | 2014-01-22 15:50:48 (GMT) |
commit | 7ddd8856819a3d7540ab1401dab6cd540ebe1210 (patch) | |
tree | d9e69a8a0bd948695c0d17a17b9b94797c8cf669 | |
parent | 4f45b7e104b8cae4f07daf9b2bd5ea2012609f63 (diff) | |
download | swift-7ddd8856819a3d7540ab1401dab6cd540ebe1210.zip swift-7ddd8856819a3d7540ab1401dab6cd540ebe1210.tar.bz2 |
Added highlight rule unit test.
Change-Id: I17fad8436ec8d021c3551f19154407c7a935b2e6
-rw-r--r-- | Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp index 414fc8e..a608bfc 100644 --- a/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp +++ b/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp @@ -42,24 +42,45 @@ public: CPPUNIT_ASSERT_EQUAL(path, part->imagePath); } + void assertHighlight(const ChatWindow::ChatMessage& result, size_t index, const std::string& text) { + boost::shared_ptr<ChatWindow::ChatHighlightingMessagePart> part = boost::dynamic_pointer_cast<ChatWindow::ChatHighlightingMessagePart>(result.getParts()[index]); + CPPUNIT_ASSERT_EQUAL(text, part->text); + } + void assertURL(const ChatWindow::ChatMessage& result, size_t index, const std::string& text) { boost::shared_ptr<ChatWindow::ChatURIMessagePart> part = boost::dynamic_pointer_cast<ChatWindow::ChatURIMessagePart>(result.getParts()[index]); CPPUNIT_ASSERT_EQUAL(text, part->target); } + static HighlightRule ruleFromKeyword(const std::string& keyword) + { + HighlightRule rule; + std::vector<std::string> keywords; + keywords.push_back(keyword); + rule.setKeywords(keywords); + return rule; + } + void testFullBody() { - ChatMessageParser testling(emoticons_, std::vector<HighlightRule>()); - ChatWindow::ChatMessage result = testling.parseMessageBody(":) shiny :( :) http://wonderland.lit/blah http://denmark.lit boom boom"); + + /* initialize rules */ + std::vector<HighlightRule> rules; + rules.push_back(ruleFromKeyword("trigger")); + + ChatMessageParser testling(emoticons_, rules); + ChatWindow::ChatMessage 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_); assertText(result, 3, " "); - assertEmoticon(result, 4, smile1_, smile1Path_); + assertHighlight(result, 4, "trigger"); assertText(result, 5, " "); - assertURL(result, 6, "http://wonderland.lit/blah"); + assertEmoticon(result, 6, smile1_, smile1Path_); assertText(result, 7, " "); - assertURL(result, 8, "http://denmark.lit"); - assertText(result, 9, " boom boom"); + assertURL(result, 8, "http://wonderland.lit/blah"); + assertText(result, 9, " "); + assertURL(result, 10, "http://denmark.lit"); + assertText(result, 11, " boom boom"); } private: |