Tests and fixes for url_encode
This commit is contained in:
52
test/test_path.c
Normal file
52
test/test_path.c
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "path.h"
|
||||
#include "noh.h"
|
||||
|
||||
void check_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;
|
||||
|
||||
url_encode(&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;
|
||||
|
||||
check_string(&good, &bad,
|
||||
"abcdefghijklmnopqrstuvwxyz1023456789ABCDEFGHIJKLMNOPQRSTUVWXYZ()*!-._",
|
||||
"abcdefghijklmnopqrstuvwxyz1023456789ABCDEFGHIJKLMNOPQRSTUVWXYZ()*!-._");
|
||||
|
||||
check_string(&good, &bad,
|
||||
"~!@#$%^&*()_+-=",
|
||||
"%7e!%40%23%24%25%5e%26*()_%2b-%3d");
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user