From 7ddd8856819a3d7540ab1401dab6cd540ebe1210 Mon Sep 17 00:00:00 2001 From: Richard Maudsley Date: Wed, 22 Jan 2014 15:50:48 +0000 Subject: Added highlight rule unit test. Change-Id: I17fad8436ec8d021c3551f19154407c7a935b2e6 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 part = boost::dynamic_pointer_cast(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 part = boost::dynamic_pointer_cast(result.getParts()[index]); CPPUNIT_ASSERT_EQUAL(text, part->target); } + static HighlightRule ruleFromKeyword(const std::string& keyword) + { + HighlightRule rule; + std::vector keywords; + keywords.push_back(keyword); + rule.setKeywords(keywords); + return rule; + } + void testFullBody() { - ChatMessageParser testling(emoticons_, std::vector()); - ChatWindow::ChatMessage result = testling.parseMessageBody(":) shiny :( :) http://wonderland.lit/blah http://denmark.lit boom boom"); + + /* initialize rules */ + std::vector 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: -- cgit v0.10.2-6-g49f6