mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 02:15:45 +02:00
Add redis parser + test
This commit is contained in:
parent
2bce379341
commit
f2bc27e283
9 changed files with 958 additions and 1 deletions
86
server/test_utils.h
Normal file
86
server/test_utils.h
Normal file
|
@ -0,0 +1,86 @@
|
|||
// Copyright 2021, Beeri 15. All rights reserved.
|
||||
// Author: Roman Gershman (romange@gmail.com)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include "io/io.h"
|
||||
#include "server/redis_parser.h"
|
||||
#include "util/proactor_pool.h"
|
||||
|
||||
namespace dfly {
|
||||
|
||||
class RespMatcher {
|
||||
public:
|
||||
RespMatcher(std::string_view val, RespExpr::Type t = RespExpr::STRING) : type_(t), exp_str_(val) {
|
||||
}
|
||||
|
||||
RespMatcher(int64_t val, RespExpr::Type t = RespExpr::INT64)
|
||||
: type_(t), exp_int_(val) {
|
||||
}
|
||||
|
||||
using is_gtest_matcher = void;
|
||||
|
||||
bool MatchAndExplain(const RespExpr& e, testing::MatchResultListener*) const;
|
||||
|
||||
void DescribeTo(std::ostream* os) const;
|
||||
|
||||
void DescribeNegationTo(std::ostream* os) const;
|
||||
|
||||
private:
|
||||
RespExpr::Type type_;
|
||||
|
||||
std::string exp_str_;
|
||||
int64_t exp_int_;
|
||||
};
|
||||
|
||||
class RespTypeMatcher {
|
||||
public:
|
||||
RespTypeMatcher(RespExpr::Type type) : type_(type) {
|
||||
}
|
||||
|
||||
using is_gtest_matcher = void;
|
||||
|
||||
bool MatchAndExplain(const RespExpr& e, testing::MatchResultListener*) const;
|
||||
|
||||
void DescribeTo(std::ostream* os) const;
|
||||
|
||||
void DescribeNegationTo(std::ostream* os) const;
|
||||
|
||||
private:
|
||||
RespExpr::Type type_;
|
||||
};
|
||||
|
||||
inline ::testing::PolymorphicMatcher<RespMatcher> StrArg(std::string_view str) {
|
||||
return ::testing::MakePolymorphicMatcher(RespMatcher(str));
|
||||
}
|
||||
|
||||
inline ::testing::PolymorphicMatcher<RespMatcher> ErrArg(std::string_view str) {
|
||||
return ::testing::MakePolymorphicMatcher(RespMatcher(str, RespExpr::ERROR));
|
||||
}
|
||||
|
||||
inline ::testing::PolymorphicMatcher<RespMatcher> IntArg(int64_t ival) {
|
||||
return ::testing::MakePolymorphicMatcher(RespMatcher(ival));
|
||||
}
|
||||
|
||||
inline ::testing::PolymorphicMatcher<RespMatcher> ArrLen(size_t len) {
|
||||
return ::testing::MakePolymorphicMatcher(RespMatcher(len, RespExpr::ARRAY));
|
||||
}
|
||||
|
||||
inline ::testing::PolymorphicMatcher<RespTypeMatcher> ArgType(RespExpr::Type t) {
|
||||
return ::testing::MakePolymorphicMatcher(RespTypeMatcher(t));
|
||||
}
|
||||
|
||||
inline bool operator==(const RespExpr& left, const char* s) {
|
||||
return left.type == RespExpr::STRING && ToAbsl(left.GetBuf()) == s;
|
||||
}
|
||||
|
||||
void PrintTo(const RespExpr::Vec& vec, std::ostream* os);
|
||||
|
||||
MATCHER_P(RespEq, val, "") {
|
||||
return ::testing::ExplainMatchResult(::testing::ElementsAre(StrArg(val)), arg, result_listener);
|
||||
}
|
||||
|
||||
} // namespace dfly
|
Loading…
Add table
Add a link
Reference in a new issue