commit 4228c2f922a980c015332e4cc96fc70d3540a1ac
parent 8b78d253db57b5f8eb03c77b4a6382299f8c0ad5
Author: Andrew Laack <andrew@laack.co>
Date: Mon, 28 Sep 2026 16:42:28 -0500
Added rapid check tests
Diffstat:
3 files changed, 48 insertions(+), 11 deletions(-)
diff --git a/include/shared.hpp b/include/shared.hpp
@@ -5,7 +5,7 @@
#ifdef DEBUG_MODE
- const std::string DEFAULT_SEARCH_ENGINE = "gemini://notasearchengine.somethingelse/search?";
+ const std::string DEFAULT_SEARCH_ENGINE = "gemini://laack.co/search?"; // this doesn't exist.
#else
const std::string DEFAULT_SEARCH_ENGINE = "gemini://tlgs.one/search?";
#endif
diff --git a/tests/browser-test.cpp b/tests/browser-test.cpp
@@ -1,8 +1,10 @@
#include <catch2/catch_test_macros.hpp>
+#include <rapidcheck.h>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <filesystem>
+#include <rapidcheck/Assertions.h>
#include <utility>
#include "../include/browser.hpp"
#include "../include/utils.hpp"
@@ -92,3 +94,22 @@ TEST_CASE("Sanitize characters to draw tests") {
}
}
+TEST_CASE("Never crash from weird user inputs") {
+ rc::check("Never crash from weird inputs", [] (std::vector<std::string> const ls) {
+ Browser b {};
+ if(ls.size() > 20) {
+ return;
+ }
+ for(auto& str : ls) {
+ auto res = handleDestinationResolution(str, false);
+ if(res.t == STRING_DESTINATION) {
+ bool result = b.goToSite(res.destination);
+ } else if (res.t == NUMBER_DESTINATION) {
+ bool result = b.followLinkNumber(res.linkNumber);
+ }
+ b.refresh();
+ b.goBack();
+ RC_ASSERT(b.getCurrentLink()->getLinkDestination().to_string() == "about://newtab");
+ }
+ });
+}
diff --git a/tests/pure-test.cpp b/tests/pure-test.cpp
@@ -1,5 +1,6 @@
// Testing pure functions
+#include <rapidcheck.h>
#include <catch2/catch_test_macros.hpp>
#include <climits>
#include <cstdlib>
@@ -100,7 +101,6 @@ TEST_CASE("Test width invariant") {
for(auto& res: result) {
REQUIRE(res.first.size() <= 80);
}
-
}
TEST_CASE("Test lots of spaces") {
@@ -187,17 +187,33 @@ TEST_CASE("Test line parsing handles whitespace correctly") {
std::string acc = options[rand() % 2];
- for(int x = 0; x < 10; ++x) {
- for(int i = 0; i < 10; ++i) {
- std::string check = "=>" + acc + "gemini://laack.co" + acc + "link human text";
- auto ln = lineToLine(check, std::nullopt, 1, false);
- REQUIRE(ln->type() == LINK);
- REQUIRE(ln->textToDraw() == "[1] link human text\n");
- acc += options[rand() % 2];
- }
- }
+ rc::check("any non-zero number of whitespaces results in the same link text",
+ [](const std::vector<bool> &l0) {
+ std::string acc = "";
+ if(l0.size() == 0) {
+ if(rand() % 2 == 0) {
+ acc = " ";
+ } else {
+ acc = "\t";
+ }
+ }
+ for(bool i : l0) {
+ if(i) {
+ acc += '\t';
+ } else {
+ acc += ' ';
+ }
+ }
+ std::string check = "=>" + acc + "gemini://laack.co" + acc + "link human text";
+ auto ln = lineToLine(check, std::nullopt, 1, false);
+ RC_ASSERT(ln->type() == LINK);
+ RC_ASSERT(ln->textToDraw() == "[1] link human text\n");
+ REQUIRE(ln->type() == LINK);
+ REQUIRE(ln->textToDraw() == "[1] link human text\n");
+ });
}
+
TEST_CASE("Proper whitespace compliance") {
auto res1 = lineToLine("", std::nullopt, -1, false);
REQUIRE(res1->type() == PLAINTEXT);