pyjamas 0.1.0

A BDD assertion library for D

To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:


Build Status Gitter chat

<img src="/logo-big.png" align="left"/> A BDD assertion library for D.


import pyjamas;

[1, 2, 3, 4].should.include(3);


Pyjamas is an assertion library heavily inspired by visionmedia'ś should.js module for Node.JS.

General Assertions

Pyjamas exports a single function should meant for public use. Because of D's lookup shortcut syntax, one is able to use both should(obj) and obj.should to get an object wrapped around an Assertion instance.

Assertion not()

This function negates the wrapper assertion. With it, one can express fluent assertions without much effort:


T equal(U)(U other, string file = __FILE__, size_t line = __LINE__);

Asserts for equality between two objects. Returns the value wrapped around the assertion.

[1, 2, 3, 4].should.equal([1, 2, 3, 4]);
255.should.equal(10); // Throws an Exception "expected 255 to equal 10"

T exist(string file = __FILE__, size_t line = __LINE__);

Asserts whether a value exists - currently simply compares it with null, if it is convertible to null. Returns the value wrapped around the assertion.

auto exists = "I exist!";
string doesntexist;
str.should.exist; // Throws an Exception "expected null to exist"

bool biggerThan(U)(U other, string file = __FILE__, size_t line = __LINE__);

Asserts if a value is bigger than another value. Returns the result.


bool smallerThan(U)(U other, string file = __FILE__, size_t line = __LINE__)

Asserts if a value is smaller than another value. Returns the result.;;

U include(U)(U other, string file = __FILE__, size_t line = __LINE__);

Asserts for an input range wrapped around an Assertion to contain/include a value.

[1, 2, 3, 4].should.include(3);

U length(U)(U length, string file = __FILE__, size_t line = __LINE__);

Asserts for the .length property or function value to equal some value.

[1, 2, 3, 4].should.have.length(4);
// ^^ - Throws an Exception "expected 'abcdefg' to have length of 0"

auto match(RegEx)(RegEx re, string file = __FILE__, size_t line = __LINE__);

Asserts for a string wrapped around the Assertion to match a regular expression.

"something weird".match(`[a-z]+`);
"something weird".match(regex(`[a-z]+`));
"something 2 weird".should.not.match(ctRegex!`^[a-z]+$`));

bool True(string file = __FILE__, size_t = line = __LINE__); and .False

Both functions have the same signature. Asserts for a boolean value to be equal to true or to `false.`;;

bool sorted(strinf file = __FILE__, size_t line = __LINE__);

Asserts whether a forward range is sorted.

[1, 2, 3, 4];
[1, 2, 0, 4];

void Throw(T : Throwable)(string file = __FILE__, size_t line = __LINE__);

Asserts whether a callable object wrapped around the assertion throws an exception of type T.

void throwing()
  throw new Exception("I throw with 0!");


void notThrowing()


.be .as .of .a .and .have .which

These methods all are aliases for an identity function, returning the assertion instance without modification. This allows one to have a more fluent API, by chaining statements together:;
[1, 2, 3, 4].should.have.length(4);

Need more documentation?

I know the documentation is still somewhat lacking, but it's better than nothing, I guess? :)

Try looking at the test suite in test/pyjamas_test.d to see some "real world" testing of the library. Even though I'm using my testing framework bed, this library is supposed to be framework agnostic (you can use it with unittest if you want).

BTW, I'll be glad to accept help in writting the documentation.


Run tests with:

dub --config=test


This code is licensed under the GPLv3 license. See the LICENSE file for more information.

  • Pedro Tacla Yamada
0.2.1 2014-Dec-10
0.2.0 2014-Sep-02
0.1.0 2014-Aug-21
0.0.11 2014-Aug-20
0.0.10 2014-Aug-20
Show all 15 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 464 downloads total

Short URL: