// // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot 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/CPPAlliance/url // // Test that header file is self-contained. #include #include #include #include "test_suite.hpp" #include "test_bnf.hpp" #include namespace boost { namespace urls { BOOST_STATIC_ASSERT( std::is_copy_constructible< host_bnf>::value); BOOST_STATIC_ASSERT( std::is_copy_assignable< host_bnf>::value); class host_bnf_test { public: static host_bnf check( string_view s, host_type ht) { host_bnf h; error_code ec; if(! BOOST_TEST( bnf::parse_string(s, ec, h))) return {}; BOOST_TEST( h.host_type == ht); return h; } void run() { using T = host_bnf; bad("%"); good(""); good("[::]"); good("[::1.2.3.4]"); good("[v1.0]"); good("1.2.3.4"); good("boost.org"); good("999.0.0.1"); BOOST_TEST(check("", host_type::name) .host_part == ""); BOOST_TEST(check("www.example.com", host_type::name) .name.str == "www.example.com"); BOOST_TEST(check("1.2.3.999", host_type::name) .name.str == "1.2.3.999"); BOOST_TEST(check("1.2.3.4", host_type::ipv4) .ipv4.to_bytes() == ( std::array({{1,2,3,4}}))); BOOST_TEST(check( "[1:2:3:4:5:6:7:8]", host_type::ipv6) .ipv6 == make_ipv6_address( "1:2:3:4:5:6:7:8")); BOOST_TEST(check("[v1.2]", host_type::ipvfuture) .ipvfuture == "v1.2"); } }; TEST_SUITE( host_bnf_test, "boost.url.host_bnf"); } // urls } // boost