#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
+#include <boost/foreach.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <stringfunc.hxx>
BOOST_CHECK_EQUAL(string("l??uter ??mlaute utf8"), output);
}
+BOOST_AUTO_TEST_CASE(find_html_comments_test)
+{
+ string text = "bla-->" // ==> (npos, 6)
+ // 0 6
+ "bla<!--bla<!--bla-->bla-->" // ==> (16, 26), (9, 32)
+ // 6 9 16 26 32
+ "bla<!--bla-->" // ==> (35, 45)
+ // 32 35 45
+ "--><!----><!--" // ==> (npos, 48), (48, 55), (55, npos)
+ // 45 48 55 59
+ "bla<!--bla-->"; // ==> (62, 72)
+ // 59 62 72
+ BOOST_REQUIRE_EQUAL(text.length(), 72);
+ vector<CommentZone> 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<CommentZone> 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 <!--FOO\n"
+ "Inside foo\n"
+ "<!--BAR\n"
+ "foo bar, what a surprise.\n"
+ "<!-- short tag-less comment -->\n"
+ " Html cannot handle this, thinks that FOO ended above\n"
+ "BAR-->\n"
+ "This, neither. No nested comments\n"
+ "some text <!--BAZ more text\n"
+ "Aaarggh!"
+ "more text BAZ--> even more\n"
+ "FOO--> text\n"
+ "second line outside\n"
+ "<!-- second comment -->";
+ 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("test<!--") + original;
+ remove_html_comments(text);
+ BOOST_CHECK_EQUAL(text, "test");
+
+ text = original + "-->test";
+ remove_html_comments(text);
+ BOOST_CHECK_EQUAL(text, "test");
+}
+
BOOST_AUTO_TEST_SUITE_END()