Add ListingTagsHandler

This commit is contained in:
rr- 2016-02-24 21:24:44 +01:00
parent a67f8c1472
commit d9f123c84c
3 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,16 @@
#include "tags_handlers/listing_tags_handler.h"
using namespace opustags;
ListingTagsHandler::ListingTagsHandler(
const int streamno,
std::ostream &output_stream)
: StreamTagsHandler(streamno), output_stream(output_stream)
{
}
void ListingTagsHandler::list_impl(const Tags &tags)
{
for (const auto &kv : tags.get_all())
output_stream << std::get<0>(kv) << "=" << std::get<1>(kv) << "\n";
}

View File

@ -0,0 +1,20 @@
#pragma once
#include <iostream>
#include "tags_handlers/stream_tags_handler.h"
namespace opustags {
class ListingTagsHandler : public StreamTagsHandler
{
public:
ListingTagsHandler(const int streamno, std::ostream &output_stream);
protected:
void list_impl(const Tags &) override;
private:
std::ostream &output_stream;
};
}

View File

@ -0,0 +1,22 @@
#include "tags_handlers/listing_tags_handler.h"
#include "catch.h"
#include <sstream>
using namespace opustags;
TEST_CASE("Listing tags handler test")
{
const auto streamno = 1;
Tags tags;
tags.set("z", "value1");
tags.set("a", "value2");
tags.set("y", "value3");
tags.set("c", "value4");
std::stringstream ss;
ListingTagsHandler handler(streamno, ss);
handler.list(streamno, tags);
REQUIRE(ss.str() == "z=value1\na=value2\ny=value3\nc=value4\n");
}