您最多能選擇 25 個主題
主題必須以字母或數字為開頭,可包含連接號「-」且最長為 35 個字元。
50 行
3.7 KiB
50 行
3.7 KiB
#include <algorithm> |
|
#include <iostream> |
|
#include <memory> |
|
#include <string> |
|
#include "../../src/URL.h" |
|
|
|
void test_parser(std::string url, std::string scheme, std::string userinfo, |
|
std::string host, int port, std::string path, std::string query, std::string fragment) { |
|
//std::unique_ptr<URL> |
|
std::tuple<std::unique_ptr<URL>,enum URIParseError> result = parseUri(url); |
|
if (std::get<1>(result) != URI_PARSE_ERROR_NONE) { |
|
// TODO We probably wanna handle this better.. |
|
std::cerr << "error parsing uri" << std::endl; |
|
return; |
|
} |
|
std::unique_ptr<URL> uri = std::move(std::get<0>(result)); |
|
if (uri->scheme == scheme && uri->userinfo == userinfo && |
|
uri->host == host && uri->port == port && |
|
uri->path == path && uri->query == query && uri->fragment == fragment) { |
|
std::cout << "noice" << std::endl; |
|
} else { |
|
std::cout << "nope" << std::endl; |
|
std::cout << uri->scheme << " vs " << scheme << std::endl; |
|
std::cout << uri->userinfo << " vs " << userinfo << std::endl; |
|
std::cout << uri->host << " vs " << host << std::endl; |
|
std::cout << uri->port << " vs " << port << std::endl; |
|
std::cout << uri->path << " vs " << path << std::endl; |
|
std::cout << uri->query << " vs " << query << std::endl; |
|
std::cout << uri->fragment << " vs " << fragment << std::endl; |
|
} |
|
} |
|
|
|
int main(void) { |
|
test_parser("HTTP://username:password@www.example.org:8080/", "http", "username:password", "www.example.org", 8080, "/", "", ""); |
|
test_parser("http://username:password@www.example.org:8080/", "http", "username:password", "www.example.org", 8080, "/", "", ""); |
|
test_parser("http://www.example.org:8080/", "http", "", "www.example.org", 8080, "/", "", ""); |
|
test_parser("http://www.example.org/", "http", "", "www.example.org", 80, "/", "", ""); |
|
test_parser("http://www.example.org", "http", "", "www.example.org", 80, "/", "", ""); |
|
//test_parser("http://www.example.org//", "http", "", "www.example.org", 80, "/", "", ""); |
|
test_parser("http://www.example.org/this/path", "http", "", "www.example.org", 80, "/this/path", "", ""); |
|
test_parser("http://www.example.org:/this/path", "http", "", "www.example.org", 80, "/this/path", "", ""); |
|
test_parser("http://username:password@www.example.org:/this/path", "http", "username:password", "www.example.org", 80, "/this/path", "", ""); |
|
test_parser("http://username:password@www.example.org/", "http", "username:password", "www.example.org", 80, "/", "", ""); |
|
test_parser("http://username:passwor:d@www.example.org/", "http", "username:passwor:d", "www.example.org", 80, "/", "", ""); |
|
test_parser("http://username:passwor:d@www.example.org:9090/", "http", "username:passwor:d", "www.example.org", 9090, "/", "", ""); |
|
test_parser("http://username:passwor:d@www.example.org:9090/this/path?query", "http", "username:passwor:d", "www.example.org", 9090, "/this/path", "query", ""); |
|
test_parser("http://www.example.org:9090/this/path?query", "http", "", "www.example.org", 9090, "/this/path", "query", ""); |
|
test_parser("http://www.example.org/this/path?query", "http", "", "www.example.org", 80, "/this/path", "query", ""); |
|
test_parser("http://www.example.org?query", "http", "", "www.example.org", 80, "/", "query", ""); |
|
}
|
|
|