// // 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 #include "test_suite.hpp" namespace boost { namespace urls { BOOST_STATIC_ASSERT( grammar::is_range::value); BOOST_STATIC_ASSERT( grammar::is_range::value); BOOST_STATIC_ASSERT( grammar::is_range::value); BOOST_STATIC_ASSERT( grammar::is_range::value); class paths_rule_test { public: template void good(string_view s) { T t; error_code ec; if(! BOOST_TEST( grammar::parse_string(s, ec, t))) BOOST_TEST(ec.failed()); else BOOST_TEST(! ec.failed()); } template void bad(string_view s) { T t; error_code ec; if(! BOOST_TEST( ! grammar::parse_string(s, ec, t))) BOOST_TEST(! ec.failed()); else BOOST_TEST(ec.failed()); } /* ASCII HEX % 25 . 2e / 2f : 3a */ void test_path_abempty_rule() { // path-abempty = *( "/" segment ) using T = path_abempty_rule; good(""); good("/"); good("//"); good("/x"); good("/:"); good("/x/"); good("/%3a/"); good("/%20"); good("/%20"); good("/%25"); good("/%25%2e"); bad("."); bad(":"); bad("x"); bad("%20"); bad("%2f"); bad("a/"); bad(" "); } void test_path_absolute_rule() { // path-absolute = "/" [ segment-nz *( "/" segment ) ] using T = path_absolute_rule; good("/"); good("/x"); good("/x/"); good("/:/"); good("/x//"); good("/%20"); good("/:%20"); good("/%20"); good("/%25"); good("/%25%2e"); bad(""); bad("//"); bad("."); bad(":"); bad("x"); bad("%20"); bad("%2f"); bad("a/"); bad(" "); } void test_path_noscheme_rule() { // path-noscheme = segment-nz-nc *( "/" segment ) using T = path_noscheme_rule; good("."); good("x"); good("%20"); good("%2f"); good("a/"); good("a//"); good("a/x"); good("a/x/"); good("a/x//"); good("a///"); bad(""); bad(" "); bad(":"); bad("/"); bad("/x"); bad("//"); bad("/x/"); bad("/:/"); bad("/x//"); bad("/%20"); bad("/:%20"); bad("/%20"); bad("/%25"); bad("/%25%2e"); } void test_path_rootless_rule() { // path-rootless = segment-nz *( "/" segment ) using T = path_rootless_rule; good("."); good(":"); good(":/"); good("::/"); good("://"); good(":/:/"); good("x"); good("%20"); good("%2f"); good("a/"); good("a//"); good("a/x"); good("a/x/"); good("a/x//"); good("a///"); bad(""); bad(" "); bad("/"); bad("/x"); bad("//"); bad("/x/"); bad("/:/"); bad("/x//"); bad("/%20"); bad("/:%20"); bad("/%20"); bad("/%25"); bad("/%25%2e"); } void run() { test_path_abempty_rule(); test_path_absolute_rule(); test_path_noscheme_rule(); test_path_rootless_rule(); } }; TEST_SUITE( paths_rule_test, "boost.url.paths_rule"); } // urls } // boost