Skip to content

Commit

Permalink
correct operator+ for Tiny type (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
s1Sharp authored Nov 18, 2023
1 parent 85983df commit f2abed3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
7 changes: 5 additions & 2 deletions include/VaultClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ template <typename Name, typename T> struct Tiny {
return os << object.value();
}
friend std::string operator+(const Tiny &tiny, const Tiny &other) {
return tiny.value() + tiny.value();
return tiny.value() + other.value();
}
template<typename U>
friend std::string operator+(const Tiny &tiny, const Tiny<U, T> &other) {
return tiny.value() + other.value();
}

friend std::string operator+(const Tiny &tiny, const char *string) {
return tiny.toString() + string;
}
Expand Down
29 changes: 29 additions & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <catch2/catch.hpp>
#include <optional>
#include <utility>
#include <sstream>

#include "VaultClient.h"

Expand Down Expand Up @@ -134,6 +135,34 @@ TEST_CASE("HttpClient#is_success when status 200") {
REQUIRE(Vault::HttpClient::is_success(response));
}

TEST_CASE("Tiny#base operators check") {
{
const auto token1 = Vault::Token{"hello"};
const auto token2 = Vault::Token{"token"};

REQUIRE(token1 + token2 == "hellotoken");
REQUIRE(token2 + token1 == "tokenhello");
}
{
const auto host = Vault::Host{"example.com"};
const auto port = Vault::Port{":6000"};
const auto url = std::string{"http://"} + host + port;

REQUIRE(url == "http://example.com:6000");
}
{
std::stringstream outStream;
outStream << "http://" << Vault::Host{"example.com"} << ":" << std::to_string(6000ul);

REQUIRE(outStream.str() == "http://example.com:6000");
}
{
REQUIRE(Vault::Url{Vault::Host{"example.com"} + Vault::Port{":6000"}}.value() == "example.com:6000");
REQUIRE(Vault::Url{ "example.com" + Vault::Port{":6000"}}.value() == "example.com:6000");
REQUIRE(Vault::Url{Vault::Host{"example.com"} + ":6000" }.value() == "example.com:6000");
}
}

TEST_CASE("VaultConfig#make default") {
config = Vault::ConfigBuilder().build();

Expand Down

0 comments on commit f2abed3

Please sign in to comment.