Saturday, February 16, 2008

felt assertions

I'm working on an assertions library right now. Library? Well, just a couple files, two structs, an exception class, and a half dozen functions.

It's in the D programming language. It depends on Tango Variant, which can actually handle structs of nontrivial sizes. Phobos Variant can't. And it should work with D1 and D2.

I need to get my hands on Tango for D2. Even if Phobos were decent, I can't afford to write so many version statements. It just isn't worth my time. But the reflection capabilities introduced in D2 are great.

The final product will look something like this:
expect(4).equals(4);
expect([1, 2, 3, 4]).has(2).where((int x) { return x % 2 == 0; });

// should be 2 where the constraint is false
expect([1, 2, 3, 4]).has(2).not.where((int x) { return x % 2 == 0; });

// should be other than two where the constraint is false
expect([1, 2, 3, 4]).not.has(2).where((int x) { return x % 3 == 0; });
expect([1, 2, 3, 4]).hasOne.sameAs(2);
expect(true);
expect(null).isNull;
o = new Object;
auto p = o;
expect(o).sameAs(p);
p = new Object;
expect(p).not.sameAs(o);

It'll be ready some time today. And then I should stop slacking and get Felt.Sleeper working. Or fix interfaces with dmocks.

No comments: