Refactor HasCall sequence diagram test cases matcher
This commit is contained in:
@@ -42,9 +42,6 @@ TEST_CASE("t20018", "[test-case][sequence]")
|
|||||||
"__print(int)__"));
|
"__print(int)__"));
|
||||||
REQUIRE_THAT(puml,
|
REQUIRE_THAT(puml,
|
||||||
HasCall(_A("Factorial<5>"), _A("Factorial<4>"), "__print(int)__"));
|
HasCall(_A("Factorial<5>"), _A("Factorial<4>"), "__print(int)__"));
|
||||||
REQUIRE_THAT(puml,
|
|
||||||
!HasCallWithResponse(
|
|
||||||
_A("Factorial<5>"), _A("Factorial<4>"), "__print(int)__"));
|
|
||||||
REQUIRE_THAT(puml,
|
REQUIRE_THAT(puml,
|
||||||
HasCall(_A("Factorial<4>"), _A("Factorial<3>"), "__print(int)__"));
|
HasCall(_A("Factorial<4>"), _A("Factorial<3>"), "__print(int)__"));
|
||||||
REQUIRE_THAT(puml,
|
REQUIRE_THAT(puml,
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ TEST_CASE("t20021", "[test-case][sequence]")
|
|||||||
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("A"), "a2()"));
|
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("A"), "a2()"));
|
||||||
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("A"), "a3()"));
|
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("A"), "a3()"));
|
||||||
|
|
||||||
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B"), "b1()"));
|
REQUIRE_THAT(puml, !HasCall(_A("tmain()"), _A("B"), "b1()"));
|
||||||
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B"), "b2()"));
|
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B"), "b2()"));
|
||||||
|
|
||||||
save_puml(
|
save_puml(
|
||||||
|
|||||||
@@ -82,26 +82,19 @@ template <typename T, typename... Ts> constexpr bool has_type() noexcept
|
|||||||
return (std::is_same_v<T, Ts> || ... || false);
|
return (std::is_same_v<T, Ts> || ... || false);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Public {
|
struct Public { };
|
||||||
};
|
|
||||||
|
|
||||||
struct Protected {
|
struct Protected { };
|
||||||
};
|
|
||||||
|
|
||||||
struct Private {
|
struct Private { };
|
||||||
};
|
|
||||||
|
|
||||||
struct Abstract {
|
struct Abstract { };
|
||||||
};
|
|
||||||
|
|
||||||
struct Static {
|
struct Static { };
|
||||||
};
|
|
||||||
|
|
||||||
struct Const {
|
struct Const { };
|
||||||
};
|
|
||||||
|
|
||||||
struct Default {
|
struct Default { };
|
||||||
};
|
|
||||||
|
|
||||||
struct HasCallWithResultMatcher : ContainsMatcher {
|
struct HasCallWithResultMatcher : ContainsMatcher {
|
||||||
HasCallWithResultMatcher(
|
HasCallWithResultMatcher(
|
||||||
@@ -122,12 +115,51 @@ struct HasCallWithResultMatcher : ContainsMatcher {
|
|||||||
CasedString m_resultComparator;
|
CasedString m_resultComparator;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T> class HasCallMatcher : public Catch::MatcherBase<T> {
|
||||||
|
T m_from, m_to, m_message;
|
||||||
|
|
||||||
|
public:
|
||||||
|
HasCallMatcher(T from, T to, T message)
|
||||||
|
: m_from(from)
|
||||||
|
, m_to{to}
|
||||||
|
, m_message{message}
|
||||||
|
{
|
||||||
|
util::replace_all(m_message, "(", "\\(");
|
||||||
|
util::replace_all(m_message, "*", "\\*");
|
||||||
|
util::replace_all(m_message, ")", "\\)");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool match(T const &in) const override
|
||||||
|
{
|
||||||
|
std::istringstream fin(in);
|
||||||
|
std::string line;
|
||||||
|
std::regex r{fmt::format("{} -> {} "
|
||||||
|
"(\\[\\[.*\\]\\] )?: {}",
|
||||||
|
m_from, m_to, m_message)};
|
||||||
|
while (std::getline(fin, line)) {
|
||||||
|
std::smatch base_match;
|
||||||
|
std::regex_search(in, base_match, r);
|
||||||
|
if (base_match.size() > 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string describe() const override
|
||||||
|
{
|
||||||
|
std::ostringstream ss;
|
||||||
|
ss << "has call "
|
||||||
|
<< fmt::format("{} -> {} : {}", m_from, m_to, m_message);
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
auto HasCall(std::string const &from, std::string const &to,
|
auto HasCall(std::string const &from, std::string const &to,
|
||||||
std::string const &message,
|
std::string const &message,
|
||||||
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
|
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
|
||||||
{
|
{
|
||||||
return ContainsMatcher(
|
return HasCallMatcher(from, to, message);
|
||||||
CasedString(fmt::format("{} -> {}", from, to), caseSensitivity));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto HasCall(std::string const &from, std::string const &message,
|
auto HasCall(std::string const &from, std::string const &message,
|
||||||
@@ -140,9 +172,9 @@ auto HasCallWithResponse(std::string const &from, std::string const &to,
|
|||||||
std::string const &message,
|
std::string const &message,
|
||||||
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
|
CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes)
|
||||||
{
|
{
|
||||||
return HasCallWithResultMatcher(
|
return ContainsMatcher(CasedString(
|
||||||
CasedString(fmt::format("{} -> {}", from, to), caseSensitivity),
|
fmt::format("{} --> {}", to, from), caseSensitivity)) &&
|
||||||
CasedString(fmt::format("{} --> {}", to, from), caseSensitivity));
|
HasCallMatcher(from, to, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
ContainsMatcher HasEntrypoint(std::string const &to, std::string const &message,
|
ContainsMatcher HasEntrypoint(std::string const &to, std::string const &message,
|
||||||
|
|||||||
Reference in New Issue
Block a user