mirror of
https://github.com/fmang/opustags.git
synced 2024-11-13 00:42:46 +01:00
Add ListingTagsHandler
This commit is contained in:
parent
a67f8c1472
commit
d9f123c84c
16
src/tags_handlers/listing_tags_handler.cc
Normal file
16
src/tags_handlers/listing_tags_handler.cc
Normal 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";
|
||||
}
|
20
src/tags_handlers/listing_tags_handler.h
Normal file
20
src/tags_handlers/listing_tags_handler.h
Normal 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;
|
||||
};
|
||||
|
||||
}
|
22
tests/tags_handlers/listing_tags_handler_test.cc
Normal file
22
tests/tags_handlers/listing_tags_handler_test.cc
Normal 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");
|
||||
}
|
Loading…
Reference in New Issue
Block a user