EventLog: implement match backwards
..based on the new IterCursor, which gives us the ability to switch the iteration direction
This commit is contained in:
parent
eb208ea145
commit
c9d113be87
4 changed files with 61 additions and 9 deletions
|
|
@ -86,7 +86,13 @@ namespace lib {
|
|||
|
||||
|
||||
void
|
||||
toggle()
|
||||
reverse(bool backwards)
|
||||
{
|
||||
if (backwards != backwards_) reverse();
|
||||
}
|
||||
|
||||
void
|
||||
reverse()
|
||||
{
|
||||
if (start_ == end_) return;
|
||||
if (backwards_)
|
||||
|
|
@ -187,7 +193,21 @@ namespace lib {
|
|||
IterCursor&
|
||||
switchDir()
|
||||
{
|
||||
this->stateCore().toggle();
|
||||
this->stateCore().reverse();
|
||||
return *this;
|
||||
}
|
||||
|
||||
IterCursor&
|
||||
switchForwards()
|
||||
{
|
||||
this->stateCore().reverse(false);
|
||||
return *this;
|
||||
}
|
||||
|
||||
IterCursor&
|
||||
switchBackwards()
|
||||
{
|
||||
this->stateCore().reverse(true);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -402,6 +402,15 @@ namespace lib {
|
|||
// standard copy operations acceptable
|
||||
|
||||
|
||||
/** access the unfiltered source iterator
|
||||
* in current state */
|
||||
IT&
|
||||
underlying()
|
||||
{
|
||||
return this->core_.source_;
|
||||
}
|
||||
|
||||
|
||||
template<typename COND>
|
||||
ExtensibleFilterIter&
|
||||
andFilter (COND conjunctiveClause)
|
||||
|
|
|
|||
|
|
@ -45,8 +45,8 @@
|
|||
|
||||
#include "lib/error.hpp"
|
||||
#include "lib/idi/entry-id.hpp"
|
||||
#include "lib/iter-adapter-stl.hpp"
|
||||
//#include "lib/time/timevalue.hpp"
|
||||
#include "lib/iter-adapter.hpp"
|
||||
#include "lib/iter-cursor.hpp"
|
||||
#include "lib/format-string.hpp"
|
||||
#include "lib/format-util.hpp"
|
||||
#include "lib/diff/record.hpp"
|
||||
|
|
@ -77,7 +77,7 @@ namespace test{
|
|||
{
|
||||
using Entry = lib::diff::Record<string>;
|
||||
using Log = std::vector<Entry>;
|
||||
using Iter = lib::RangeIter<Log::const_iterator>;
|
||||
using Iter = lib::IterCursor<Log::const_iterator>;
|
||||
using Filter = ExtensibleFilterIter<Iter>;
|
||||
|
||||
/** match predicate evaluator */
|
||||
|
|
@ -120,8 +120,8 @@ namespace test{
|
|||
}
|
||||
|
||||
/** @internal for creating EventLog matchers */
|
||||
EventMatch(Iter&& srcSeq)
|
||||
: solution_(srcSeq)
|
||||
EventMatch(Log const& srcSeq)
|
||||
: solution_(Iter(srcSeq))
|
||||
, lastMatch_("HEAD "+ solution_->get("ID"))
|
||||
{ }
|
||||
|
||||
|
|
@ -151,6 +151,7 @@ namespace test{
|
|||
EventMatch&
|
||||
before (string match)
|
||||
{
|
||||
solution_.underlying().switchForwards();
|
||||
solution_.setNewFilter(find(match));
|
||||
enforce ("match(\""+match+"\")");
|
||||
return *this;
|
||||
|
|
@ -177,7 +178,10 @@ namespace test{
|
|||
EventMatch&
|
||||
after (string match)
|
||||
{
|
||||
UNIMPLEMENTED("process combined relational match backwards");
|
||||
solution_.underlying().switchBackwards();
|
||||
solution_.setNewFilter(find(match));
|
||||
enforce ("match(\""+match+"\")", "before");
|
||||
return *this;
|
||||
}
|
||||
|
||||
EventMatch&
|
||||
|
|
@ -252,6 +256,11 @@ namespace test{
|
|||
log({"type=EventLogHeader", "ID="+logID_});
|
||||
}
|
||||
|
||||
explicit
|
||||
EventLog (const char* logID)
|
||||
: EventLog(string(logID))
|
||||
{ }
|
||||
|
||||
template<class X>
|
||||
explicit
|
||||
EventLog (const X *const obj)
|
||||
|
|
@ -308,7 +317,7 @@ namespace test{
|
|||
EventMatch
|
||||
verify (string match)
|
||||
{
|
||||
EventMatch matcher(this->begin());
|
||||
EventMatch matcher(log_);
|
||||
matcher.before (match);
|
||||
return matcher;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ namespace test{
|
|||
run (Arg)
|
||||
{
|
||||
verify_simpleUsage();
|
||||
verify_backwardMatch();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -93,6 +94,19 @@ namespace test{
|
|||
}
|
||||
|
||||
|
||||
void
|
||||
verify_backwardMatch ()
|
||||
{
|
||||
EventLog log("baked beans");
|
||||
log.event("spam");
|
||||
log.event("ham");
|
||||
|
||||
log.verify("ham").after("spam").after("beans");
|
||||
log.verify("ham").after("beans").before("spam").before("ham");
|
||||
VERIFY_ERROR (ASSERTION, log.verify("spam").after("beans").after("ham"));
|
||||
}
|
||||
|
||||
|
||||
/** @test prints TODO */
|
||||
void
|
||||
checkTODO ()
|
||||
|
|
|
|||
Loading…
Reference in a new issue