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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
//
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
//
// Distributed under 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)
//
// Official repository: https://github.com/boostorg/url
//
// Test that header file is self-contained.
#include <boost/url/segments_view.hpp>
#include <boost/url/parse.hpp>
#include <boost/url/parse_path.hpp>
#include <boost/url/url.hpp>
#include <boost/static_assert.hpp>
#include <boost/core/ignore_unused.hpp>
#include "test_suite.hpp"
#include <sstream>
#ifdef assert
#undef assert
#endif
#define assert BOOST_TEST
namespace boost {
namespace urls {
BOOST_STATIC_ASSERT(
std::is_default_constructible<
segments_view>::value);
BOOST_STATIC_ASSERT(
std::is_copy_constructible<
segments_view>::value);
BOOST_STATIC_ASSERT(
std::is_copy_assignable<
segments_view>::value);
BOOST_STATIC_ASSERT(
std::is_default_constructible<
segments_view::iterator>::value);
struct segments_view_test
{
void
testSpecialMembers()
{
// segments_view()
{
segments_view ps;
BOOST_TEST(ps.empty());
BOOST_TEST(! ps.is_absolute());
BOOST_TEST_EQ(ps.buffer(), "");
BOOST_TEST_EQ(ps.size(), 0);
}
// segments_view(segments_view)
{
segments_view ps0 =
parse_path("/path/to/file.txt").value();
segments_view ps1(ps0);
BOOST_TEST_EQ(
ps0.buffer().data(),
ps1.buffer().data());
}
// segments_view(core::string_view)
{
try
{
core::string_view s = "/path/to/file.txt";
segments_view ps(s);
BOOST_TEST_PASS();
BOOST_TEST_EQ(
ps.buffer().data(), s.data());
BOOST_TEST_EQ(ps.buffer(), s);
}
catch(std::exception const&)
{
BOOST_TEST_FAIL();
}
// reserved character
BOOST_TEST_THROWS(segments_view("?"), system::system_error);
// invalid percent-escape
BOOST_TEST_THROWS(segments_view("%"), system::system_error);
BOOST_TEST_THROWS(segments_view("%F"), system::system_error);
BOOST_TEST_THROWS(segments_view("%FX"), system::system_error);
BOOST_TEST_THROWS(segments_view("%%"), system::system_error);
BOOST_TEST_THROWS(segments_view("FA%"), system::system_error);
}
// operator=(segments_view)
{
segments_view ps0("/path/to/file.txt");
segments_view ps1("/index.htm");
ps0 = ps1;
BOOST_TEST_EQ(
ps0.buffer().data(),
ps1.buffer().data());
}
// ostream
{
segments_view ps = parse_path(
"/path/to/file.txt").value();
std::stringstream ss;
ss << ps;
BOOST_TEST_EQ(ss.str(),
"/path/to/file.txt");
}
}
void
testJavadocs()
{
// {class}
{
url_view u( "/path/to/file.txt" );
segments_view ps = u.segments();
assert( ps.buffer().data() == u.buffer().data() );
ignore_unused(ps);
}
}
void
run()
{
testSpecialMembers();
testJavadocs();
}
};
TEST_SUITE(
segments_view_test,
"boost.url.segments_view");
} // urls
} // boost
|