Diff-Listener: add a similar simplistic demo for opaque binding
based on a TreeMutator binding to a STL vector ...because this is probably the most frequently used case
This commit is contained in:
parent
3321e5bc6b
commit
8a5f1bc8d7
2 changed files with 40 additions and 3 deletions
|
|
@ -316,7 +316,7 @@ sometimes get into conflict with the essentially open and permissive nature of s
|
|||
a mapping rule, which translates into additional conventions about how to spell out matters in the diff language.
|
||||
|
||||
We choose to leave this largely on the level of stylistic rules, thus stressing the language nature of the diff.
|
||||
Even when this bears the danger to produce an exception very late, when it comes to applying the diff to a target
|
||||
Even when this bears the danger to raise failures rather late, when it comes to applying the diff to a target
|
||||
data structure. The intention behind this whole diff approach is to transform tight coupling with strict rules
|
||||
into a loose collaboration based on a common understanding. So generally we'll assume the diff is just right,
|
||||
and if not, we'll get what we deserve.footnote:[This gives rise to a tricky discussion about loss of strictness
|
||||
|
|
|
|||
|
|
@ -63,6 +63,12 @@ namespace test{
|
|||
,[](GenNode const& n) { return n.data.get<string>(); }
|
||||
));
|
||||
}
|
||||
|
||||
string
|
||||
contents (vector<string> const& strings)
|
||||
{
|
||||
return util::join (strings);
|
||||
}
|
||||
}//(End)Test fixture
|
||||
|
||||
|
||||
|
|
@ -104,7 +110,7 @@ namespace test{
|
|||
run (Arg)
|
||||
{
|
||||
demo_one();
|
||||
// demo_two();
|
||||
demo_two();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -132,7 +138,7 @@ namespace test{
|
|||
demo_one()
|
||||
{
|
||||
Rec::Mutator subject;
|
||||
subject.scope(VAL_A, VAL_B, VAL_C);
|
||||
subject.scope (VAL_A, VAL_B, VAL_C);
|
||||
|
||||
CHECK ("a, b, c" == contents(subject));
|
||||
|
||||
|
|
@ -140,6 +146,37 @@ namespace test{
|
|||
|
||||
CHECK ("a, d, c" == contents(subject));
|
||||
}
|
||||
|
||||
|
||||
/** @test mutate a STL collection opaquely by applying the sample diff */
|
||||
void
|
||||
demo_two()
|
||||
{
|
||||
struct Opaque
|
||||
: DiffMutable
|
||||
, std::vector<string>
|
||||
{
|
||||
using std::vector<string>::vector;
|
||||
|
||||
void
|
||||
buildMutator (TreeMutator::Handle buff) override
|
||||
{
|
||||
buff.create (
|
||||
TreeMutator::build()
|
||||
.attach (collection (static_cast<vector<string>&> (*this))
|
||||
));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
Opaque subject{"a","b","c"};
|
||||
CHECK ("a, b, c" == contents(subject));
|
||||
|
||||
DiffApplicator<Opaque>{subject}.consume (someDiff());
|
||||
|
||||
CHECK ("a, d, c" == contents(subject));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue