~singpolyma/biboumi

f653906f9de8cbcecf5717e18c696d1029fc2c8f — louiz’ 5 years ago 36252ad
Add a None type for the Iid class (when the iid is completely empty)
3 files changed, 11 insertions(+), 1 deletions(-)

M src/irc/iid.cpp
M src/irc/iid.hpp
M tests/iid.cpp
M src/irc/iid.cpp => src/irc/iid.cpp +4 -1
@@ 34,9 34,10 @@ Iid::Iid(const std::string& iid, const Bridge *bridge)

void Iid::set_type(const std::set<char>& chantypes)
{
  if (this->local.empty() && this->server.empty())
    this->type = Iid::Type::None;
  if (this->local.empty())
    return;

  if (chantypes.count(this->local[0]) == 1)
    this->type = Iid::Type::Channel;
  else


@@ 105,6 106,8 @@ namespace std {
    {
      if (iid.type == Iid::Type::Server)
        return iid.get_server();
      else if (iid.get_local().empty() && iid.get_server().empty())
        return {};
      else
        return iid.get_encoded_local() + iid.separator + iid.get_server();
    }

M src/irc/iid.hpp => src/irc/iid.hpp +1 -0
@@ 53,6 53,7 @@ public:
      Channel,
      User,
      Server,
      None,
  };
  static constexpr char separator[]{"%"};
  Iid(const std::string& iid, const std::set<char>& chantypes);

M tests/iid.cpp => tests/iid.cpp +6 -0
@@ 83,6 83,12 @@ TEST_CASE("Iid creation")
    CHECK(iid6.get_local() == "##channel");
    CHECK(iid6.get_server() == "");
    CHECK(iid6.type == Iid::Type::Channel);

    Iid iid7("", chantypes);
    CHECK(std::to_string(iid7) == "");
    CHECK(iid7.get_local() == "");
    CHECK(iid7.get_server() == "");
    CHECK(iid7.type == Iid::Type::None);
}

TEST_CASE("Iid creation in fixed_server mode")