Add tests system
This commit is contained in:
parent
4e0cc367e6
commit
b537916c6b
1
data/tests/p.html
Normal file
1
data/tests/p.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
<p>Hello World!</p>
|
1
data/tests/text.html
Normal file
1
data/tests/text.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
Hello World!
|
@ -5,7 +5,7 @@ Defined Tokens
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<doc> ::= [<doctype>] <elem>*
|
<doc> ::= [<doctype>] (<elem> | <inner>)*
|
||||||
<doctype> ::= "<" "!" "doctype" "html" ">"
|
<doctype> ::= "<" "!" "doctype" "html" ">"
|
||||||
<elem> ::=
|
<elem> ::=
|
||||||
| "<" <ident> <attr>* ">" (<elem> | <inner>)* "<" "/" <ident> ">"
|
| "<" <ident> <attr>* ">" (<elem> | <inner>)* "<" "/" <ident> ">"
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include "fetch.hpp"
|
#include "fetch.hpp"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
@ -13,8 +15,17 @@ size_t curl_write_func(void* ptr, size_t size, size_t num, std::string* str)
|
|||||||
return size * num;
|
return size * num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string c_test_proto = "test://";
|
||||||
|
|
||||||
std::optional<std::string> fetch_url(const std::string& url)
|
std::optional<std::string> fetch_url(const std::string& url)
|
||||||
{
|
{
|
||||||
|
if (url.rfind(c_test_proto, 0) == 0) {
|
||||||
|
std::fstream file("../data/tests/" + url.substr(c_test_proto.size()), std::ios::in);
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << file.rdbuf();
|
||||||
|
file.close();
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
std::string curl_write_data;
|
std::string curl_write_data;
|
||||||
curl_easy_setopt(g_curl, CURLOPT_URL, url.c_str());
|
curl_easy_setopt(g_curl, CURLOPT_URL, url.c_str());
|
||||||
curl_easy_setopt(g_curl, CURLOPT_CA_CACHE_TIMEOUT, 604800L);
|
curl_easy_setopt(g_curl, CURLOPT_CA_CACHE_TIMEOUT, 604800L);
|
||||||
|
@ -194,9 +194,14 @@ NodeDoc Parser::parse()
|
|||||||
if (auto doc_type = parse_doc_type()) {
|
if (auto doc_type = parse_doc_type()) {
|
||||||
doc.doc_type = doc_type.value();
|
doc.doc_type = doc_type.value();
|
||||||
}
|
}
|
||||||
while (auto elem = parse_elem()) {
|
while (peek().has_value()) {
|
||||||
|
if (auto elem = parse_elem()) {
|
||||||
doc.children.push_back(elem.value());
|
doc.children.push_back(elem.value());
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
doc.children.push_back(consume().to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ struct NodeElem {
|
|||||||
|
|
||||||
struct NodeDoc {
|
struct NodeDoc {
|
||||||
std::optional<NodeDocType> doc_type {};
|
std::optional<NodeDocType> doc_type {};
|
||||||
std::vector<NodeElem> children {};
|
std::vector<std::variant<NodeElem, std::string>> children {};
|
||||||
};
|
};
|
||||||
|
|
||||||
class Parser {
|
class Parser {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include "fetch.hpp"
|
#include "fetch.hpp"
|
||||||
|
|
||||||
#include <codecvt>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
@ -14,7 +13,7 @@ int main()
|
|||||||
{
|
{
|
||||||
init_curl();
|
init_curl();
|
||||||
|
|
||||||
std::optional<std::string> page_data = fetch_url("https://example.com");
|
std::optional<std::string> page_data = fetch_url("test://text.html");
|
||||||
|
|
||||||
SetConfigFlags(ConfigFlags::FLAG_WINDOW_RESIZABLE | ConfigFlags::FLAG_MSAA_4X_HINT | ConfigFlags ::FLAG_VSYNC_HINT);
|
SetConfigFlags(ConfigFlags::FLAG_WINDOW_RESIZABLE | ConfigFlags::FLAG_MSAA_4X_HINT | ConfigFlags ::FLAG_VSYNC_HINT);
|
||||||
|
|
||||||
@ -27,7 +26,7 @@ int main()
|
|||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
bool is_editing_url = false;
|
bool is_editing_url = false;
|
||||||
std::string url_input = "https://example.com";
|
std::string url_input = "test://text.html";
|
||||||
url_input.reserve(1024);
|
url_input.reserve(1024);
|
||||||
float scroll_pos = 0.0f;
|
float scroll_pos = 0.0f;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user