std.experimental.testing PR review

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Fri Jun 26 08:32:17 PDT 2015


On 26/06/15 17:20, David Gileadi wrote:

> Let's paint this bikeshed!
>
> I tend to like "must" instead of "should"; it's a bit shorter and stronger.

I prefer "should".

> I tend to like dot-separated English for testing, e.g.
>
> throwRangeError.must.throw!RangeError;
>
> One advantage is that the dot after "must" (or "should") can trigger
> code completion on IDEs.

It will also be more composeable. Currently there are a couple of 
assertions that have no negative form, i.e. "shouldBeTrue". If 
should/shouldNot would be separate from the actual comparison it would 
be possible to write "shouldNot.beTrue". It could also support custom 
assertions in the future: "should.beA!(Foo)".

> Finally, I wonder if it's possible to hijack operator overloading to
> support this:
>
> 2.timesTwo.must == 4;

Yes and no :). For plain "==" it's possible, but not for ">=" and the 
other greater/less/negative comparisons. All these operators are 
implemented using the same method. Although there's an enhancement 
request (somewhere) to support overloading these operators separately.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list