Implement URI unit tests

This commit is contained in:
RYAN 2024-09-03 02:31:22 +02:00
parent 92cae4a5df
commit 428d4f0a27
Signed by: RYAN
GPG Key ID: 3BD93EABD1407B82
4 changed files with 344 additions and 2 deletions

View File

@ -1,6 +1,9 @@
intf_libs = # Interface dependencies.
impl_libs = # Implementation dependencies.
test_libs = # Test dependencies.
import test_libs =+ libarc-validate%lib{arc-validate}
./: lib{arc-uri}: libul{arc-uri}
libul{arc-uri}: {hxx ixx txx cxx}{** -**.test... -version} \
@ -21,8 +24,9 @@ for t: cxx{**.test...}
d = $directory($t)
n = $name($t)...
./: $d/exe{$n}: $t $d/{hxx ixx txx}{+$n} $d/testscript{+$n}
$d/exe{$n}: libul{arc-uri}: bin.whole = false
./: $d/exe{$n}: $t $d/{hxx ixx txx}{+$n} $d/testscript{+$n} $test_libs
$d/exe{$n}: lib{arc-uri}: bin.whole = false
$d/exe{$n}: test.arguments = --print-failure
}
hxx{version}: in{version} $src_root/manifest

333
arc/uri/uri.test.cxx Normal file
View File

@ -0,0 +1,333 @@
#include <arc/validate/main.hxx>
#include <arc/validate/asserts.hxx>
#define ARC_VALIDATE_UNPREFIXED_MACROS
#include <arc/validate/test.hxx>
#include <arc/uri/uri.hxx>
#include <functional>
#include <memory>
#include <iostream>
using namespace arc::validate::asserts;
DEFINE_TEST(test_01)
{
auto opt_uri = arc::uri::try_parse("");
assert_true((bool)opt_uri);
auto uri = *opt_uri;
assert_false((bool)uri.scheme());
assert_false((bool)uri.userinfo());
assert_false((bool)uri.host());
assert_false((bool)uri.port());
assert_false((bool)uri.query());
assert_false((bool)uri.fragment());
assert_true(uri.path_str().empty());
}
DEFINE_TEST(test_02)
{
auto opt_uri = arc::uri::try_parse("http:///index.html");
assert_true((bool)opt_uri);
auto uri = *opt_uri;
assert_equal((bool)uri.scheme(), true);
assert_equal((bool)uri.userinfo(), false);
assert_equal((bool)uri.host(), true);
assert_equal((bool)uri.port(), false);
assert_equal((bool)uri.query(), false);
assert_equal((bool)uri.fragment(), false);
assert_equal(uri.scheme_str(), "http");
assert_equal(uri.host_str(), "");
assert_equal(uri.path_str(), "/index.html");
}
DEFINE_TEST(test_03)
{
auto opt_uri = arc::uri::try_parse("http://host.domain./index.html");
assert_true((bool)opt_uri);
auto uri = *opt_uri;
assert_true((bool)uri.scheme());
assert_false((bool)uri.userinfo());
assert_true((bool)uri.host());
assert_false((bool)uri.port());
assert_false((bool)uri.query());
assert_false((bool)uri.fragment());
assert_equal(uri.scheme_str(), "http");
assert_equal(uri.host_str(), "host.domain.");
assert_equal(uri.path_str(), "/index.html");
}
DEFINE_TEST(test_04)
{
auto opt_uri = arc::uri::try_parse("https://host.domain.:8443/index.html");
assert_true((bool)opt_uri);
auto uri = *opt_uri;
assert_true((bool)uri.scheme());
assert_false((bool)uri.userinfo());
assert_true((bool)uri.host());
assert_true((bool)uri.port());
assert_false((bool)uri.query());
assert_false((bool)uri.fragment());
assert_equal(uri.scheme_str(), "https");
assert_equal(uri.host_str(), "host.domain.");
assert_equal(uri.port_str(), "8443");
assert_equal(uri.path_str(), "/index.html");
}
DEFINE_TEST(test_05)
{
auto opt_uri = arc::uri::try_parse("https://host.domain.:8443/search?q=hamsters");
assert_true((bool)opt_uri);
auto uri = *opt_uri;
assert_true((bool)uri.scheme());
assert_false((bool)uri.userinfo());
assert_true((bool)uri.host());
assert_true((bool)uri.port());
assert_true((bool)uri.query());
assert_false((bool)uri.fragment());
assert_equal(uri.scheme_str(), "https");
assert_equal(uri.host_str(), "host.domain.");
assert_equal(uri.port_str(), "8443");
assert_equal(uri.path_str(), "/search");
assert_equal(uri.query_str(), "q=hamsters");
}
DEFINE_TEST(test_06)
{
auto opt_uri = arc::uri::try_parse("https://host.domain.:8443/search?q=hamsters#results");
assert_true((bool)opt_uri);
auto uri = *opt_uri;
assert_true((bool)uri.scheme());
assert_false((bool)uri.userinfo());
assert_true((bool)uri.host());
assert_true((bool)uri.port());
assert_true((bool)uri.query());
assert_true((bool)uri.fragment());
assert_equal(uri.scheme_str(), "https");
assert_equal(uri.host_str(), "host.domain.");
assert_equal(uri.port_str(), "8443");
assert_equal(uri.path_str(), "/search");
assert_equal(uri.query_str(), "q=hamsters");
assert_equal(uri.fragment_str(), "results");
}
DEFINE_TEST(test_07)
{
auto opt_uri = arc::uri::try_parse(
"https://admin:qwerty@host.domain.:8443/search?q=hamsters#results"
);
assert_true((bool)opt_uri);
auto uri = *opt_uri;
assert_true((bool)uri.scheme());
assert_true((bool)uri.userinfo());
assert_true((bool)uri.host());
assert_true((bool)uri.port());
assert_true((bool)uri.query());
assert_true((bool)uri.fragment());
assert_equal(uri.scheme_str(), "https");
assert_equal(uri.userinfo_str(), "admin:qwerty");
assert_equal(uri.host_str(), "host.domain.");
assert_equal(uri.port_str(), "8443");
assert_equal(uri.path_str(), "/search");
assert_equal(uri.query_str(), "q=hamsters");
assert_equal(uri.fragment_str(), "results");
}
DEFINE_TEST(test_08)
{
auto opt_uri = arc::uri::try_parse("//host.domain./index.html");
assert_true((bool)opt_uri);
auto uri = *opt_uri;
assert_false((bool)uri.scheme());
assert_false((bool)uri.userinfo());
assert_true((bool)uri.host());
assert_false((bool)uri.port());
assert_false((bool)uri.query());
assert_false((bool)uri.fragment());
assert_equal(uri.host_str(), "host.domain.");
assert_equal(uri.path_str(), "/index.html");
}
DEFINE_TEST(test_09)
{
auto opt_uri = arc::uri::try_parse("/index.html");
assert_true((bool)opt_uri);
auto uri = *opt_uri;
assert_equal((bool)uri.scheme(), false);
assert_false((bool)uri.userinfo());
assert_false((bool)uri.host());
assert_false((bool)uri.port());
assert_false((bool)uri.query());
assert_false((bool)uri.fragment());
assert_equal(uri.path_str(), "/index.html");
}
DEFINE_TEST(test_10)
{
auto opt_uri = arc::uri::try_parse("index.html");
assert_true((bool)opt_uri);
auto uri = *opt_uri;
assert_equal((bool)uri.scheme(), false);
assert_false((bool)uri.userinfo());
assert_false((bool)uri.host());
assert_false((bool)uri.port());
assert_false((bool)uri.query());
assert_false((bool)uri.fragment());
assert_equal(uri.path_str(), "index.html");
}
DEFINE_TEST(test_11)
{
auto opt_uri = arc::uri::try_parse("/files/index:1.html");
assert_true((bool)opt_uri);
auto uri = *opt_uri;
assert_equal((bool)uri.scheme(), false);
assert_equal((bool)uri.userinfo(), false);
assert_equal((bool)uri.host(), false);
assert_equal((bool)uri.port(), false);
assert_equal((bool)uri.query(), false);
assert_equal((bool)uri.fragment(), false);
assert_equal(uri.path_str(), "/files/index:1.html");
}
DEFINE_TEST(test_12)
{
auto opt_uri = arc::uri::try_parse("files/index:1.html");
assert_true((bool)opt_uri);
auto uri = *opt_uri;
assert_equal((bool)uri.scheme(), false);
assert_equal((bool)uri.userinfo(), false);
assert_equal((bool)uri.host(), false);
assert_equal((bool)uri.port(), false);
assert_equal((bool)uri.query(), false);
assert_equal((bool)uri.fragment(), false);
assert_equal(uri.path_str(), "files/index:1.html");
}
DEFINE_TEST(test_13)
{
auto opt_uri = arc::uri::try_parse("?q=hamsters");
assert_true((bool)opt_uri);
auto uri = *opt_uri;
assert_equal((bool)uri.scheme(), false);
assert_equal((bool)uri.userinfo(), false);
assert_equal((bool)uri.host(), false);
assert_equal((bool)uri.port(), false);
assert_equal((bool)uri.query(), true);
assert_equal((bool)uri.fragment(), false);
assert_equal(uri.query_str(), "q=hamsters");
}
DEFINE_TEST(test_14)
{
auto opt_uri = arc::uri::try_parse("?q=hamsters#results");
assert_true((bool)opt_uri);
auto uri = *opt_uri;
assert_equal((bool)uri.scheme(), false);
assert_equal((bool)uri.userinfo(), false);
assert_equal((bool)uri.host(), false);
assert_equal((bool)uri.port(), false);
assert_equal((bool)uri.query(), true);
assert_equal((bool)uri.fragment(), true);
assert_equal(uri.query_str(), "q=hamsters");
assert_equal(uri.fragment_str(), "results");
}
DEFINE_TEST(test_15)
{
auto opt_uri = arc::uri::try_parse("#results");
assert_true((bool)opt_uri);
auto uri = *opt_uri;
assert_equal((bool)uri.scheme(), false);
assert_equal((bool)uri.userinfo(), false);
assert_equal((bool)uri.host(), false);
assert_equal((bool)uri.port(), false);
assert_equal((bool)uri.query(), false);
assert_equal((bool)uri.fragment(), true);
assert_equal(uri.fragment_str(), "results");
}
DEFINE_TEST(test_16)
{
auto opt_uri = arc::uri::try_parse("#results?gui-sort=asc");
assert_true((bool)opt_uri);
auto uri = *opt_uri;
assert_equal((bool)uri.scheme(), false);
assert_equal((bool)uri.userinfo(), false);
assert_equal((bool)uri.host(), false);
assert_equal((bool)uri.port(), false);
assert_equal((bool)uri.query(), false);
assert_equal((bool)uri.fragment(), true);
assert_equal(uri.fragment_str(), "results?gui-sort=asc");
}
int
main(int argc, char* argv[])
{
return arc::validate::main(argc, argv);
}

View File

@ -9,3 +9,4 @@ url: https://www.helloryan.se/arc-project/
email: arc-project@helloryan.se
depends: * build2 >= 0.17.0
depends: * bpkg >= 0.17.0
depends: libarc-validate ^0.1.0

View File

@ -5,3 +5,7 @@ summary: libarc-uri project repository
role: prerequisite
location: https://pkg.cppget.org/1/beta
trust: 70:64:FE:E4:E0:F3:60:F1:B4:51:E1:FA:12:5C:E0:B3:DB:DF:96:33:39:B9:2E:E5:C2:68:63:4C:A6:47:39:43
:
role: prerequisite
location: https://code.helloryan.se/arc/libarc-validate.git##HEAD