From: Christian Herdtweck Date: Wed, 8 Feb 2017 15:22:51 +0000 (+0100) Subject: Add unittests for new find/replace_html_comments X-Git-Tag: v2.9~7^2~1 X-Git-Url: http://developer.intra2net.com/git/?p=libi2ncommon;a=commitdiff_plain;h=67a3dacb25141878b25ee91cfc58c2d2a6126f89 Add unittests for new find/replace_html_comments --- diff --git a/test/stringfunc.cpp b/test/stringfunc.cpp index ee18355..bec8782 100644 --- a/test/stringfunc.cpp +++ b/test/stringfunc.cpp @@ -30,6 +30,7 @@ on this file might be covered by the GNU General Public License. #define BOOST_TEST_DYN_LINK #include +#include #include #include @@ -723,4 +724,71 @@ BOOST_AUTO_TEST_CASE(sanitize_for_logging3) BOOST_CHECK_EQUAL(string("l??uter ??mlaute utf8"), output); } +BOOST_AUTO_TEST_CASE(find_html_comments_test) +{ + string text = "bla-->" // ==> (npos, 6) + // 0 6 + "blabla-->" // ==> (16, 26), (9, 32) + // 6 9 16 26 32 + "bla" // ==> (35, 45) + // 32 35 45 + "-->"; // ==> (62, 72) + // 59 62 72 + BOOST_REQUIRE_EQUAL(text.length(), 72); + vector expect; + expect.push_back(CommentZone(string::npos, 6)); + expect.push_back(CommentZone(16, 26)); + expect.push_back(CommentZone( 9, 32)); + expect.push_back(CommentZone(35, 45)); + expect.push_back(CommentZone(string::npos, 48)); + expect.push_back(CommentZone(48, 55)); + expect.push_back(CommentZone(55, string::npos)); + expect.push_back(CommentZone(62, 72)); + vector result; + find_html_comments(text, result); + //BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), not working, requires ... + // expect.begin(), expect.end()); ... operator<<(CommentZone) + BOOST_CHECK_EQUAL(result.size(), expect.size()); + BOOST_FOREACH(const CommentZone &comment, expect) + BOOST_CHECK_MESSAGE(find(result.begin(), result.end(), comment) != result.end(), + "Find (" << comment.first << "-" << comment.second << ")"); +} + +BOOST_AUTO_TEST_CASE(remove_html_comments_test) +{ + const string original = "First line outside\n" + "text \n" + " Html cannot handle this, thinks that FOO ended above\n" + "BAR-->\n" + "This, neither. No nested comments\n" + "some text even more\n" + "FOO--> text\n" + "second line outside\n" + ""; + string text = original; + string expect = "First line outside\n" + "text text\n" + "second line outside\n"; + remove_html_comments(text); + BOOST_CHECK_EQUAL(text, expect); + remove_html_comments(text); // should not have any effect + BOOST_CHECK_EQUAL(text, expect); + + text = string("testtest"; + remove_html_comments(text); + BOOST_CHECK_EQUAL(text, "test"); +} + BOOST_AUTO_TEST_SUITE_END()