C and C++ web framework.
http://rapida.vilor.one/docs
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.6 KiB
59 lines
1.6 KiB
/* SPDX-License-Identifier: GPL-3.0-or-later */ |
|
/* Copyright 2022 Ivan Polyakov */ |
|
|
|
#include "Url.hxx" |
|
#include "tests.hxx" |
|
|
|
using namespace rpd; |
|
|
|
TEST_CASE("URL processing") |
|
{ |
|
rpd_url url { NULL, 0 }; |
|
|
|
SECTION("\"/some/route\" parsing") |
|
{ |
|
REQUIRE(rpd_url_parse(&url, "/some/route") == 0); |
|
REQUIRE(url.parts_len == 2); |
|
REQUIRE(std::string(url.parts[0]) == "some"); |
|
REQUIRE(std::string(url.parts[1]) == "route"); |
|
} |
|
|
|
SECTION("Invalid route without slashes should be ignored") |
|
{ |
|
REQUIRE(rpd_url_parse(&url, "someroute") == 0); |
|
REQUIRE(url.parts_len == 0); |
|
} |
|
|
|
SECTION("Empty part (\"//\") in the routes should be ignored") |
|
{ |
|
REQUIRE(rpd_url_parse(&url, "/some//route/") == 0); |
|
REQUIRE(url.parts_len == 2); |
|
REQUIRE(std::string(url.parts[0]) == "some"); |
|
REQUIRE(std::string(url.parts[1]) == "route"); |
|
} |
|
|
|
SECTION("Dynamic parameters should be saved") |
|
{ |
|
REQUIRE(rpd_url_parse(&url, "/some/:param") == 0); |
|
REQUIRE(url.parts_len == 2); |
|
REQUIRE(std::string(url.parts[0]) == "some"); |
|
REQUIRE(std::string(url.parts[1]) == ":param"); |
|
} |
|
|
|
SECTION("Test valid route using the C++ wrapper") |
|
{ |
|
Url cxxurl; |
|
REQUIRE(cxxurl.parse("/some/route") == 0); |
|
REQUIRE(cxxurl.length() == 2); |
|
REQUIRE(std::string(cxxurl[0]) == "some"); |
|
REQUIRE(std::string(cxxurl[1]) == "route"); |
|
} |
|
|
|
SECTION("Cleaning") |
|
{ |
|
rpd_url_parse(&url, "/some/route"); |
|
rpd_url_cleanup(&url); |
|
REQUIRE(url.parts_len == 0); |
|
REQUIRE(url.parts == 0); |
|
} |
|
}
|
|
|