c55b7ccc9f
Doesn't support things like custom entities, but should be good enough for the boostbook/docbook that quickbook generates.
68 lines
2.1 KiB
C++
68 lines
2.1 KiB
C++
|
|
/*=============================================================================
|
|
Copyright (c) 2017 Daniel James
|
|
|
|
Use, modification and distribution is subject to the Boost Software
|
|
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
|
http://www.boost.org/LICENSE_1_0.txt)
|
|
=============================================================================*/
|
|
|
|
#include <boost/detail/lightweight_test.hpp>
|
|
#include "utils.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
void linkify_test()
|
|
{
|
|
using quickbook::detail::linkify;
|
|
|
|
BOOST_TEST(linkify("abc", "link") == "<link linkend=\"link\">abc</link>");
|
|
BOOST_TEST(
|
|
linkify("<link linkend=\"something\">abc</link>", "link") ==
|
|
"<link linkend=\"something\">abc</link>");
|
|
BOOST_TEST(
|
|
linkify("abc <link linkend=\"something\">def</link>", "link") ==
|
|
"abc <link linkend=\"something\">def</link>");
|
|
BOOST_TEST(
|
|
linkify("<link linkend=\"something\">abc</link> def", "link") ==
|
|
"<link linkend=\"something\">abc</link> def");
|
|
}
|
|
|
|
void decode_string_test()
|
|
{
|
|
using quickbook::detail::decode_string;
|
|
BOOST_TEST_EQ(std::string("<A&B>"), decode_string("<A&B>"));
|
|
BOOST_TEST_EQ(std::string("<A&B>"), decode_string("<A&B>"));
|
|
BOOST_TEST_EQ(std::string("a"), decode_string("a"));
|
|
BOOST_TEST_EQ(std::string("OO"), decode_string("OO"));
|
|
// Unicode examples taken from wikipedia.
|
|
// https://en.wikipedia.org/wiki/UTF-8#Examples
|
|
BOOST_TEST_EQ(
|
|
std::string("\x24\xc2\xa2\xe2\x82\xAC\xF0\x90\x8D\x88"),
|
|
decode_string("$¢€𐍈"));
|
|
}
|
|
|
|
void encode_string_test()
|
|
{
|
|
using quickbook::detail::encode_string;
|
|
BOOST_TEST_EQ(std::string("<A&B>"), encode_string("<A&B>"));
|
|
}
|
|
|
|
void escape_uri_test()
|
|
{
|
|
using quickbook::detail::escape_uri;
|
|
using quickbook::detail::partially_escape_uri;
|
|
|
|
BOOST_TEST_EQ(std::string("%2520%2525%25"), escape_uri("%20%25%"));
|
|
BOOST_TEST_EQ(std::string("%20%25%25"), partially_escape_uri("%20%25%"));
|
|
}
|
|
|
|
int main()
|
|
{
|
|
linkify_test();
|
|
decode_string_test();
|
|
encode_string_test();
|
|
escape_uri_test();
|
|
return boost::report_errors();
|
|
}
|