summaryrefslogtreecommitdiffstats
path: root/src/boost/tools/quickbook/test/unit/utils_test.cpp
blob: 6a54dccfe6d72a8f3fd3c108259fd5ab11f1c712 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*=============================================================================
    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("&lt;A&amp;B&gt;"));
    BOOST_TEST_EQ(std::string("<A&B>"), decode_string("&lt;A&B&gt;"));
    BOOST_TEST_EQ(std::string("a"), decode_string("&#97;"));
    BOOST_TEST_EQ(std::string("OO"), decode_string("&#x4f;&#x4F;"));
    // 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("&#x24;&#xA2;&#x20AC;&#x10348;"));
}

void encode_string_test()
{
    using quickbook::detail::encode_string;
    BOOST_TEST_EQ(std::string("&lt;A&amp;B&gt;"), 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();
}