From 8d0ce0dd3aa948a2b413609228bc70f08ac31338 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Wed, 10 Dec 2014 04:33:53 +0100 Subject: [PATCH] experiment with how to represent a fixed inline diff sequence for the test ...also the first time to get this diff representation draft through the compiler TODO: implementation of the actual diff step application functions --- tests/library/diff-list-application-test.cpp | 61 ++++++++++++++++++-- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/tests/library/diff-list-application-test.cpp b/tests/library/diff-list-application-test.cpp index 391c30757..112f3dada 100644 --- a/tests/library/diff-list-application-test.cpp +++ b/tests/library/diff-list-application-test.cpp @@ -24,6 +24,7 @@ #include "lib/test/run.hpp" #include "lib/verb-token.hpp" #include "lib/util.hpp" +#include "lib/iter-adapter-stl.hpp" //#include "lib/format-string.hpp" //#include @@ -57,12 +58,17 @@ namespace test{ }; using DiffVerb = VerbToken; + using VerbTok = std::tuple; struct DiffStep - : std::tuple + : VerbTok { DiffVerb& verb() { return std::get<0>(*this); } - E const& elm() { return std::get<1>(*this); } + E elm() { return std::get<1>(*this); } + + DiffStep(DiffVerb verb, E e) + : VerbTok(verb,e) + { } operator string() const { @@ -77,7 +83,7 @@ namespace test{ }; #define DiffStep_CTOR(_ID_) \ - DiffStep _ID_(E e) { return {DiffVerb(&Receiver::_ID_, STRINGIFY(_ID_)), e}; } + static DiffStep _ID_(E e) { return {DiffVerb(&Receiver::_ID_, STRINGIFY(_ID_)), e }; } DiffStep_CTOR(ins) DiffStep_CTOR(del) @@ -153,7 +159,31 @@ namespace test{ protected: }; + namespace { + template + struct _OnceT + { + typedef typename SEQ::value_type value_type; + typedef iter_stl::IterSnapshot iterator; + }; + } + template + inline typename _OnceT::iterator + onceEach(CON const& con) + { + using OnceIter = typename _OnceT::iterator; + return OnceIter(con); + } + + template + inline iter_stl::IterSnapshot + onceEach(std::initializer_list const& ili) + { + using OnceIter = iter_stl::IterSnapshot; + return OnceIter(begin(ili), end(ili)); + } + namespace { using DataSeq = vector; @@ -162,6 +192,29 @@ namespace test{ string TOK(a1), TOK(a2), TOK(a3), TOK(a4), TOK(a5); string TOK(b1), TOK(b2), TOK(b3), TOK(b4); + + struct TestDiff + : DiffLanguage + { + using DiffSeq = typename _OnceT>::iterator; + + static DiffSeq + generate() + { + return onceEach({del(a1) + , del(a2) + , ins(b1) + , pick(a3) + , push(a5) + , pick(a5) + , ins(b2) + , ins(b3) + , pick(a4) + , ins(b4) + }); + + } + }; } @@ -188,7 +241,7 @@ namespace test{ run (Arg) { DataSeq src({a1,a2,a3,a4,a5}); - DiffSeq diff = generate_test_diff(); + auto diff = TestDiff::generate(); CHECK (!isnil (diff)); DataSeq target = src;