68 lines
2.0 KiB
C
68 lines
2.0 KiB
C
#include <stdio.h>
|
|
|
|
#include "path.h"
|
|
#include "noh.h"
|
|
|
|
void check_string(void (*fut)(Noh_String *), size_t *good, size_t *bad, const char* input, const char *expected) {
|
|
Noh_String test = noh_string_from_cstr(input);
|
|
Noh_String_View expected_sv = noh_sv_from_cstr(expected);
|
|
|
|
Noh_Log_Options *opts = noh_log_get_opts();
|
|
|
|
opts->write_lf = false;
|
|
noh_log(NOH_INFO, "Testing: \"%s\"...", input);
|
|
opts->write_lf = true;
|
|
opts->write_prefix = false;
|
|
|
|
fut(&test);
|
|
bool correct = noh_sv_eq(noh_sv_from_string(test), expected_sv);
|
|
|
|
if (!correct) {
|
|
noh_log(NOH_ERROR, " Incorrect.");
|
|
opts->write_prefix = true;
|
|
noh_log(NOH_ERROR, "Expected: \""Nsv_Fmt"\"", Nsv_Arg(expected_sv));
|
|
noh_log(NOH_ERROR, "Got : \""Nsv_Fmt"\"", Nsv_Arg(test));
|
|
(*bad)++;
|
|
} else {
|
|
noh_log(NOH_INFO, " Ok.");
|
|
opts->write_prefix = true;
|
|
(*good)++;
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
size_t good = 0;
|
|
size_t bad = 0;
|
|
|
|
noh_log(NOH_INFO, "");
|
|
noh_log(NOH_INFO, "url_encode:");
|
|
|
|
check_string(url_encode, &good, &bad,
|
|
"abcdefghijklmnopqrstuvwxyz1023456789ABCDEFGHIJKLMNOPQRSTUVWXYZ()*!-._/",
|
|
"abcdefghijklmnopqrstuvwxyz1023456789ABCDEFGHIJKLMNOPQRSTUVWXYZ()*!-._/");
|
|
|
|
check_string(url_encode, &good, &bad,
|
|
"~!@#$%^&*()_+-=",
|
|
"%7e!%40%23%24%25%5e%26*()_%2b-%3d");
|
|
|
|
noh_log(NOH_INFO, "");
|
|
noh_log(NOH_INFO, "url_decode:");
|
|
|
|
check_string(url_decode, &good, &bad,
|
|
"abcdefghijklmnopqrstuvwxyz1023456789ABCDEFGHIJKLMNOPQRSTUVWXYZ()*!-._/",
|
|
"abcdefghijklmnopqrstuvwxyz1023456789ABCDEFGHIJKLMNOPQRSTUVWXYZ()*!-._/");
|
|
|
|
check_string(url_decode, &good, &bad,
|
|
"%7e!%40%23%24%25%5e%26*()_%2b-%3d",
|
|
"~!@#$%^&*()_+-=");
|
|
|
|
noh_log(NOH_INFO, "");
|
|
if (bad == 0) {
|
|
noh_log(NOH_INFO, "%zu/%zu tests passed.", good, good);
|
|
return 0;
|
|
} else {
|
|
noh_log(NOH_ERROR, "%zu/%zu tests passed. %zu failures.", good, good + bad, bad);
|
|
return 1;
|
|
}
|
|
}
|