Implements piping StringView into streams.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-07-08 13:28:43 +02:00
parent 97b15650f1
commit 950464ae79
2 changed files with 23 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
#ifdef TESTS_BUILD
#include <cstring>
#include <sstream>
#include <unordered_map>
#include "../extern/catch.hpp"
#include "../src/StringView.hpp"
@@ -11,7 +12,7 @@ TEST_CASE("Initialize compile time", "[Utilities]") {
TEST_CASE("Compare compile time", "[Utilities]") { static_assert("foo"_cnc != "bar"_cnc); }
TEST_CASE("Compare compile time with CaseInsensitiveConstString", "[Utilities]") {
TEST_CASE("Compare compile time with CaseInsensitiveStringview", "[Utilities]") {
static_assert("foo"_cnc == ArbUt::StringViewLiteral("foo"));
}
@@ -34,18 +35,30 @@ TEST_CASE("Use case insensitive const string in switch case", "[Utilities]") {
}
}
TEST_CASE("Literal conststring to non literal, then use", "[Utilities]") {
TEST_CASE("Literal stringview to non literal, then use", "[Utilities]") {
ArbUt::StringView val;
{ val = "foobar"_cnc; }
INFO(val.c_str());
REQUIRE(strcmp(val.c_str(), "foobar") == 0);
}
TEST_CASE("Pipe stringview into strean", "[Utilities]") {
std::stringstream ss;
ArbUt::StringView val = "foo";
ss << val;
REQUIRE(ss.str() == "foo");
ss << val;
REQUIRE(ss.str() == "foofoo");
ArbUt::StringView val2 = "bar";
ss << val2;
REQUIRE(ss.str() == "foofoobar");
}
#ifndef WINDOWS
__attribute__((optnone))
#endif
static ArbUt::StringView
TestCreateConstString() {
TestCreateStringview() {
char originalVal[7];
originalVal[0] = 'f';
originalVal[1] = 'o';
@@ -58,7 +71,7 @@ TestCreateConstString() {
}
TEST_CASE("Out of scope char* doesn't lose reference", "[Utilities]") {
ArbUt::StringView val = TestCreateConstString();
ArbUt::StringView val = TestCreateStringview();
INFO(val.c_str());
REQUIRE(strcmp(val.c_str(), "foobar") == 0);
}