Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/metkit/mars/Matcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,14 @@ bool Matcher::match(const RequestLike& request, MatchMissingPolicy matchOnMissin
});
}

} // namespace metkit::mars
void Matcher::print(std::ostream& s) const {
s << "{";
const char* sep = "";
for (const auto& [key, regex] : regexMap_) {
s << sep << key << "=" << static_cast<const std::string&>(regex);
sep = ",";
}
s << "}";
}
Comment thread
mcakircali marked this conversation as resolved.

} // namespace metkit::mars
10 changes: 9 additions & 1 deletion src/metkit/mars/Matcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#pragma once

#include <functional>
#include <iosfwd>
#include <map>
#include <string>
#include <variant>
Expand Down Expand Up @@ -62,6 +63,13 @@ class Matcher {
bool match(const RequestLike& request, MatchMissingPolicy matchOnMissing = MatchOnMissing) const;
bool match(const MarsRequest& request, MatchMissingPolicy matchOnMissing = MatchOnMissing) const;

void print(std::ostream& s) const;

friend std::ostream& operator<<(std::ostream& s, const Matcher& m) {
m.print(s);
return s;
}
Comment thread
mcakircali marked this conversation as resolved.

private:

std::map<std::string, eckit::Regex> regexMap_;
Expand All @@ -85,4 +93,4 @@ class RequestLike {
virtual std::optional<values_t> get(const std::string& keyword) const = 0;
};

} // namespace metkit::mars
} // namespace metkit::mars
11 changes: 11 additions & 0 deletions tests/test_matcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "metkit/mars/MarsRequest.h"
#include "metkit/mars/Matcher.h"

#include <sstream>

using namespace eckit::testing;
using namespace metkit::mars;

Expand Down Expand Up @@ -151,6 +153,15 @@ CASE("match empty request") {
EXPECT_EQUAL(match_all.match(req, Matcher::MatchOnMissing), true);
}

CASE("streaming matcher is deterministic") {
Matcher matcher("stream=^enfo$, expver=(x[0-9a-z]{3}), number=(1|2)", Matcher::Policy::Any);

std::ostringstream oss;
oss << matcher;

EXPECT_EQUAL(oss.str(), "{expver=(x[0-9a-z]{3}),number=(1|2),stream=^enfo$}");
}

// ----------------------------------------------------------------------------------------------------------------------

} // namespace metkit::test
Expand Down
Loading