From d9f123c84c4ce91e1b1eb09509223fb61b29978a Mon Sep 17 00:00:00 2001 From: rr- Date: Wed, 24 Feb 2016 21:24:44 +0100 Subject: [PATCH] Add ListingTagsHandler --- src/tags_handlers/listing_tags_handler.cc | 16 ++++++++++++++ src/tags_handlers/listing_tags_handler.h | 20 +++++++++++++++++ .../listing_tags_handler_test.cc | 22 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 src/tags_handlers/listing_tags_handler.cc create mode 100644 src/tags_handlers/listing_tags_handler.h create mode 100644 tests/tags_handlers/listing_tags_handler_test.cc diff --git a/src/tags_handlers/listing_tags_handler.cc b/src/tags_handlers/listing_tags_handler.cc new file mode 100644 index 0000000..1013667 --- /dev/null +++ b/src/tags_handlers/listing_tags_handler.cc @@ -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"; +} diff --git a/src/tags_handlers/listing_tags_handler.h b/src/tags_handlers/listing_tags_handler.h new file mode 100644 index 0000000..9b6f613 --- /dev/null +++ b/src/tags_handlers/listing_tags_handler.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#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; + }; + +} diff --git a/tests/tags_handlers/listing_tags_handler_test.cc b/tests/tags_handlers/listing_tags_handler_test.cc new file mode 100644 index 0000000..65998a6 --- /dev/null +++ b/tests/tags_handlers/listing_tags_handler_test.cc @@ -0,0 +1,22 @@ +#include "tags_handlers/listing_tags_handler.h" +#include "catch.h" +#include + +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"); +}