From c9d113be87783fdbc76ed0563106d47e45fd1649 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 6 Dec 2015 03:35:07 +0100 Subject: [PATCH] EventLog: implement match backwards ..based on the new IterCursor, which gives us the ability to switch the iteration direction --- src/lib/iter-cursor.hpp | 24 ++++++++++++++++++++-- src/lib/itertools.hpp | 9 ++++++++ src/lib/test/event-log.hpp | 23 ++++++++++++++------- tests/library/test/test-event-log-test.cpp | 14 +++++++++++++ 4 files changed, 61 insertions(+), 9 deletions(-) diff --git a/src/lib/iter-cursor.hpp b/src/lib/iter-cursor.hpp index 4c455cbd1..1e4ffa2b8 100644 --- a/src/lib/iter-cursor.hpp +++ b/src/lib/iter-cursor.hpp @@ -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; } }; diff --git a/src/lib/itertools.hpp b/src/lib/itertools.hpp index 2bd1f9915..b23501466 100644 --- a/src/lib/itertools.hpp +++ b/src/lib/itertools.hpp @@ -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 ExtensibleFilterIter& andFilter (COND conjunctiveClause) diff --git a/src/lib/test/event-log.hpp b/src/lib/test/event-log.hpp index 560bd3ef9..b73de2111 100644 --- a/src/lib/test/event-log.hpp +++ b/src/lib/test/event-log.hpp @@ -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; using Log = std::vector; - using Iter = lib::RangeIter; + using Iter = lib::IterCursor; using Filter = ExtensibleFilterIter; /** 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 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; } diff --git a/tests/library/test/test-event-log-test.cpp b/tests/library/test/test-event-log-test.cpp index 4595bbf42..e4dc239d2 100644 --- a/tests/library/test/test-event-log-test.cpp +++ b/tests/library/test/test-event-log-test.cpp @@ -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 ()