foreseen

A text-based gemini browser with prefetching
git clone git://git.laack.co/foreseen.git
Log | Files | Refs | README | LICENSE

commit 965b9203d358a9ff145334ffc8b3c38aab7def5a
parent 303dcae8bdd942081f39036274cc32607a6a9f3c
Author: Andrew Laack <andrew@laack.co>
Date:   Tue, 29 Sep 2026 21:49:06 -0500

Added tests for input

Diffstat:
Mtests/puppet-test.cpp | 103++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
1 file changed, 68 insertions(+), 35 deletions(-)

diff --git a/tests/puppet-test.cpp b/tests/puppet-test.cpp @@ -147,42 +147,75 @@ TEST_CASE("Handle redirect rejection") { REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "about://newtab"); } +TEST_CASE("Enter an input") { + Browser b {}; + DrawState ds {}; + + REQUIRE(mainLoop(ds, b, 'o')); + REQUIRE(mainLoop(ds, b, 't')); + REQUIRE(mainLoop(ds, b, 'l')); + REQUIRE(mainLoop(ds, b, 'g')); + REQUIRE(mainLoop(ds, b, 's')); + REQUIRE(mainLoop(ds, b, '.')); + REQUIRE(mainLoop(ds, b, 'o')); + REQUIRE(mainLoop(ds, b, 'n')); + REQUIRE(mainLoop(ds, b, 'e')); + REQUIRE(mainLoop(ds, b, '\n')); + + REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one"); + + REQUIRE(mainLoop(ds,b,'o')); + REQUIRE(mainLoop(ds,b,'2')); + REQUIRE(mainLoop(ds, b, '\n')); + REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one/search"); + std::string rnd = genRandom(10); + + INFO(rnd); + + for(auto& ch : rnd) { + REQUIRE(mainLoop(ds, b, ch)); + } -//TEST_CASE("Enter an input") { -// Browser b {}; -// DrawState ds {}; -// -// REQUIRE(mainLoop(ds, b, 'o')); -// REQUIRE(mainLoop(ds, b, 't')); -// REQUIRE(mainLoop(ds, b, 'l')); -// REQUIRE(mainLoop(ds, b, 'g')); -// REQUIRE(mainLoop(ds, b, 's')); -// REQUIRE(mainLoop(ds, b, '.')); -// REQUIRE(mainLoop(ds, b, 'o')); -// REQUIRE(mainLoop(ds, b, 'n')); -// REQUIRE(mainLoop(ds, b, 'e')); -// REQUIRE(mainLoop(ds, b, '\n')); -// -// REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one"); -// -// REQUIRE(mainLoop(ds,b,'o')); -// REQUIRE(mainLoop(ds,b,'2')); -// REQUIRE(mainLoop(ds, b, '\n')); -// -// REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one/search"); -// -// std::string rnd = genRandom(10); -// -// INFO(rnd); -// -// for(auto& ch : rnd) { -// REQUIRE(mainLoop(ds, b, ch)); -// } -// -// REQUIRE(mainLoop(ds, b, '\n')); -// -// REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one/search?" + urlEncode(rnd)); -//} + REQUIRE(mainLoop(ds, b, '\n')); + + REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one/search?" + urlEncode(rnd)); +} + +TEST_CASE("Enter an input and then cancel") { + Browser b {}; + DrawState ds {}; + + REQUIRE(mainLoop(ds, b, 'o')); + REQUIRE(mainLoop(ds, b, 't')); + REQUIRE(mainLoop(ds, b, 'l')); + REQUIRE(mainLoop(ds, b, 'g')); + REQUIRE(mainLoop(ds, b, 's')); + REQUIRE(mainLoop(ds, b, '.')); + REQUIRE(mainLoop(ds, b, 'o')); + REQUIRE(mainLoop(ds, b, 'n')); + REQUIRE(mainLoop(ds, b, 'e')); + REQUIRE(mainLoop(ds, b, '\n')); + + REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one"); + + REQUIRE(mainLoop(ds,b,'o')); + REQUIRE(mainLoop(ds,b,'2')); + REQUIRE(mainLoop(ds, b, '\n')); + + REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one/search"); + + std::string rnd = genRandom(10); + + INFO(rnd); + + for(auto& ch : rnd) { + REQUIRE(mainLoop(ds, b, ch)); + } + + REQUIRE(mainLoop(ds, b, 27)); // escape + + REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one"); +}