From 7ffdd86c5c17db0e170625046e85ef3749accc1a Mon Sep 17 00:00:00 2001 From: adamska <2639980868@qq.com> Date: Sun, 15 Sep 2024 16:49:10 +0800 Subject: [PATCH] tests(buffer.hpp): test negative input --- tests/buffer_test.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/buffer_test.cpp b/tests/buffer_test.cpp index 67489b5..ee90f3f 100644 --- a/tests/buffer_test.cpp +++ b/tests/buffer_test.cpp @@ -1,7 +1,7 @@ #include #include "myxml/buffer.hpp" #include "myxml/xmlfile.hpp" -#include +#include TEST_CASE("String Buffer", "[buffer]") { @@ -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"; @@ -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"); + } } \ No newline at end of file