From e5f25d8453945c9721ed9fc2b1916e4d7b335a03 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 3 Sep 2016 20:17:46 +0200 Subject: [PATCH] third part of unit-test: value assignment --- .../diff/tree-mutator-binding-test.cpp | 69 ++++++------------- 1 file changed, 21 insertions(+), 48 deletions(-) diff --git a/tests/library/diff/tree-mutator-binding-test.cpp b/tests/library/diff/tree-mutator-binding-test.cpp index 010ccfb42..2c8d8e95c 100644 --- a/tests/library/diff/tree-mutator-binding-test.cpp +++ b/tests/library/diff/tree-mutator-binding-test.cpp @@ -567,7 +567,7 @@ namespace test{ CHECK ( mutator3.completeScope()); // now any pending elements where default-resolved CHECK (not contains(join(target), "≺γ∣3.1415927≻")); - CHECK (mutator3.assignElm(GAMMA_PI)); // ...we assign a new payload to the current element first // assignElm + CHECK (mutator3.assignElm(GAMMA_PI)); // ...we assign a new payload to the designated element // assignElm CHECK ( contains(join(target), "≺γ∣3.1415927≻")); CHECK ( mutator3.completeScope()); cout << "Content after assignment; " @@ -1067,51 +1067,12 @@ namespace test{ // --- third round: mutate data and sub-scopes --- - // This time we build the Mutator bindings in a way to allow mutation - // For one, "mutation" means to assign a changed value to a simple node / attribute. - // And beyond that, mutation entails to open a nested scope and delve into that recursively. - // Here, as this is really just a test and demonstration, we implement those nested scopes aside - // managed within a map and keyed by the sub node's ID. -#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #992 + // since our target data here is comprised of GenNode elements, + // we're both able to assign data and to enter a nested Record + // The default configuration is outfitted for this use as-is right away. auto mutator3 = TreeMutator::build() - .attach (collection(target) - .constructFrom ([&](GenNode const& spec) -> Data - { - cout << "constructor invoked on "< bool - { - cout << "match? "< bool - { - cout << "assign "< bool - { - // use our "inside knowledge" to get at the nested scope implementation - VecD& subScope = subScopes[subID]; - buff.create ( - TreeMutator::build() - .attach (collection(subScope) - .constructFrom ([&](GenNode const& spec) -> Data - { - cout << "SubScope| constructor invoked on "< represents attributes as a list of named sub GenNode elements, and the + // access to attributes uses the first match found + attrs = root.attribs(); // visit all attributes sequentially... + CHECK ( *attrs == ATTRIB1); // first attribute "α" was left as it was + CHECK (*++attrs == GAMMA_PI); // this is where the value assignment happened... + CHECK ( attrs->data.get() == GAMMA_PI.data.get()); + CHECK (*++attrs == ATTRIB3); // ...while the duplicate "γ"... + CHECK ( attrs->data.get() == 3.45); // ...still holds the original value + CHECK (*++attrs == ATTRIB2); + CHECK (isnil (++attrs)); +#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #992 // prepare for recursion into sub scope.. // Since this is a demonstration, we do not actually recurse into anything, // rather we invoke the operations on a nested mutator right from here.