Skip to content

Commit

Permalink
tests(buffer.hpp): test negative input
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamska1008 committed Sep 15, 2024
1 parent 4f6daca commit 7ffdd86
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion tests/buffer_test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <catch2/catch_test_macros.hpp>
#include "myxml/buffer.hpp"
#include "myxml/xmlfile.hpp"
#include <iostream>
#include <random>

TEST_CASE("String Buffer", "[buffer]")
{
Expand All @@ -22,6 +22,18 @@ TEST_CASE("String Buffer", "[buffer]")
REQUIRE(sb.peek_n(2) == std::nullopt);
}

SECTION("Negative test")
{
myxml::string_buffer sb = "No matter";
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(INT32_MIN, -1);
REQUIRE(sb.take_n(dis(gen)) == std::nullopt);
REQUIRE(sb.peek_n(dis(gen)) == std::nullopt);
REQUIRE(sb.after_n(dis(gen)) == std::nullopt);
REQUIRE(sb.after_n_m(dis(gen), dis(gen)) == std::nullopt);
}

SECTION("Take test")
{
myxml::string_buffer sb = "Hello";
Expand All @@ -46,4 +58,12 @@ TEST_CASE("String Buffer", "[buffer]")
REQUIRE(sb.take_n(3) == "Lin");
REQUIRE(sb.cur_loc() == std::make_tuple(1, 3));
}

SECTION("Move constructor")
{
std::string owner("Own the value");
myxml::string_buffer sb(std::move(owner));

REQUIRE(sb.take_n(3) == "Own");
}
}

0 comments on commit 7ffdd86

Please sign in to comment.