lu.deltastrings

Functions used to generate strings of statements describing the differences (or delta) between two instances of a struct or class of the same type. They can be either assignment statements or assert statements.

Members

Enums

Hidden (from lu.uda)
enum Hidden via public import lu.uda : Hidden;

UDA conveying that this member contains sensitive information and should not be printed in clear text; e.g. passwords.

Functions

formatDeltaInto
void formatDeltaInto(Sink sink, QualThing before, QualThing after, uint indents, string submember)

Constructs statement lines for each changed field (or the delta) between two instances of a struct and stores them into a passed output sink.

Examples

struct Foo
{
    string s;
    int i;
    bool b;
}

Foo altered;

altered.s = "some string";
altered.i = 42;
altered.b = true;

Appender!(char[]) sink;

// Fill with delta between `Foo.init` and modified `altered`
sink.formatDeltaInto!(No.asserts)(Foo.init, altered);

assert(sink.data ==
`s = "some string";
i = 42;
b = true;
`);
sink.clear();

// Do the same but prepend the name "altered" to the member names
sink.formatDeltaInto!(No.asserts)(Foo.init, altered, 0, "altered");

assert(sink.data ==
`altered.s = "some string";
altered.i = 42;
altered.b = true;
`);
sink.clear();

// Generate assert statements instead, for easy copy/pasting into unittest blocks
sink.formatDeltaInto!(Yes.asserts)(Foo.init, altered, 0, "altered");

assert(sink.data ==
`assert((altered.s == "some string"), altered.s);
assert((altered.i == 42), altered.i.to!string);
assert(altered.b, altered.b.to!string);
`);

Meta