pijamas.assertion
Pijamas, a BDD assertion
library for D.
License
Licensed under the MIT license. See LICENSE for more information.
-
Declaration
Assertion!T
should
(T)(auto ref Tcontext
);The function
should
it's an helper or syntax sugar to create the assertation. Because of D’s lookup shortcut syntax, one is able to use both
andshould
(obj)obj.
to get an object wrapped around an Assertion instanceshould
-
Declaration
alias
expect
= should(T)(auto ref T context);The function
expect
it's an helper or syntax sugar to create the assertation. Because of D’s lookup shortcut syntax, one is able to use both
andexpect
(obj)obj.
to get an object wrapped around an Assertion instanceexpect
-
Declaration
struct
Assertion
(T);Class returned by should, that it's used to generate the fluent API
-
Declaration
pure nothrow @safe this(T
_context
);
pure nothrow @safe this(ref T_context
);Creates a instance of Assertion, wrapping a value or object
-
Declaration
alias
be
= id;
aliasto
= id;
aliasas
= id;
aliasof
= id;
aliasa
= id;
aliasand
= id;
aliashave
= id;
aliaswhich
= id;
pure nothrow @nogc @safe Assertionid
();Identity function. Simply does nothing beyond making assertation more human friendly
-
Declaration
pure nothrow @nogc @safe Assertion
not
();This function negates the wrapper assertion. With it, one can express fluent assertions without much effort.
Examples
10.should.not.equal(2); // OK 10.should.not.equal(10); // Throws an Exception "expected 10 not to be 10"
-
Declaration
@trusted T
equal
(U)(auto ref Uother
, stringfile
= __FILE__, size_tline
= __LINE__);Asserts for equality between two objects. Returns the value wrapped around the assertion.
Examples
[1, 2, 3, 4].should.equal([1, 2, 3, 4]); 255.should.equal(10); // Throws an Exception "expected 255 to equal 10"
-
Declaration
@trusted T
approxEqual
(U = double)(Uother
, UmaxRelDiff
= CommonDefaultFor!(T, U), UmaxAbsDiff
= 0.0, stringfile
= __FILE__, size_tline
= __LINE__) if (is(T : real) && __traits(isFloating, T) && is(U : real) && __traits(isFloating, U));Asserts that a float type is aproximated equal. Returns the valued wrapped around the assertion
Parameters
U
other
Value to compare to compare.
U
maxRelDiff
Maximum allowable relative difference. Setting to 0.0 disables this check. Default depends on the type of
and the original valie: It is approximately half the number of decimal digits of precision of the smaller type.other
U
maxAbsDiff
Maximum absolute difference. This is mainly usefull for comparing values to zero. Setting to 0.0 disables this check. Defaults to
0.0
.string
file
filename
size_t
line
line
number inside offile
Examples
double d = 0.1; double d2 = d + 1e-10; d.should.not.be.equal(d2); d.should.be.approxEqual(d2);
-
Declaration
alias
close
= approxEqual;Alias to approxEqual
Examples
double d = 0.1; double d2 = d + 1e-10; d.should.not.be.close(d2); d.should.be.close(d2);
-
Declaration
@safe T
exist
(stringfile
= __FILE__, size_tline
= __LINE__);Asserts whether a value exists - currently simply compares it with
null
, if it is a pointer, a class or a string. Returns the value wrapped around the assertion.Examples
auto exists = "I exist!"; should(exists).exist; string doesntexist; doesntexist.should.exist; // Throws an Exception "expected null to exist" Object aObject; aClass.should.not.exists;
-
Declaration
@trusted bool
biggerThan
(U)(Uother
, stringfile
= __FILE__, size_tline
= __LINE__);Asserts if a value is bigger than another value. Returns the result.
Examples
"z".should.be.biggerThan("a"); 10.should.be.biggerThan(1);
-
Declaration
@trusted bool
biggerOrEqualThan
(U)(Uother
, stringfile
= __FILE__, size_tline
= __LINE__);Asserts if a value is bigger or equal than another value. Returns the result.
Examples
"z".should.be.biggerOrEqualThan("a"); 10.should.be.biggerOrEqualThan(10); 20.should.be.biggerOrEqualThan(10);
-
Declaration
@trusted bool
smallerThan
(U)(Uother
, stringfile
= __FILE__, size_tline
= __LINE__);Asserts if a value is smaller than another value. Returns the result.
Examples
10.should.be.smallerThan(100); false.should.be.smallerThan(true);
-
Declaration
@trusted bool
smallerOrEqualThan
(U)(Uother
, stringfile
= __FILE__, size_tline
= __LINE__);Asserts if a value is smaller or euqal than another value. Returns the result.
Examples
10.should.be.smallerOrEqualThan(100); 10.should.be.smallerOrEqualThan(10); false.should.be.smallerOrEqualThan(true);
-
Declaration
@trusted bool
sorted
(stringfile
= __FILE__, size_tline
= __LINE__);Asserts whether a forward range is
sorted
.Examples
[1, 2, 3, 4].should.be.sorted; [1, 2, 0, 4].should.not.be.sorted;
-
Declaration
@trusted void
key
(U)(Uother
, stringfile
= __FILE__, size_tline
= __LINE__);Asserts for an associative array to have a
key
equal toother
.Examples
["something": 10].should.have.key("something");
-
Declaration
@nogc @trusted U
include
(U)(Uother
, stringfile
= __FILE__, size_tline
= __LINE__) if (!isAssociativeArray!T);
@trusted Uinclude
(U)(Uother
, stringfile
= __FILE__, size_tline
= __LINE__) if (isAssociativeArray!T);
aliasvalue
= include;
aliascontain
= include;Asserts for an input range wrapped around an Assertion to
contain
/include
avalue
.Examples
[1, 2, 3, 4].should.include(3); "something".should.not.include('o'); "something".should.include("th");
-
Declaration
@trusted U
length
(U)(Ulen
, stringfile
= __FILE__, size_tline
= __LINE__);Asserts for the .
length
property or function value to equal some value.Examples
[1, 2, 3, 4].should.have.length(4); "abcdefg".should.have.length(0); // ^^ - Throws an Exception "expected 'abcdefg' to have length of 0"
-
Declaration
@trusted bool
empty
(stringfile
= __FILE__, size_tline
= __LINE__);Asserts for the .length property or function value to be equal to 0.
Examples
[].should.be.empty; "".should.be.empty;
-
Declaration
@safe auto
match
(RegEx)(RegExre
, stringfile
= __FILE__, size_tline
= __LINE__) if (isSomeString!T && isRegexFor!(RegEx, T));
@safe automatch
(U)(Ure
, stringfile
= __FILE__, size_tline
= __LINE__) if (isSomeString!T && isSomeString!U);Asserts for a string wrapped around the Assertion to
match
a regular expression.Examples
"something weird".should.match(`[a-z]+`); "something weird".should.match(regex(`[a-z]+`)); "something 2 weird".should.not.match(ctRegex!(`^[a-z]+$`)); "1234numbers".should.match(`[0-9]+[a-z]+`); "1234numbers".should.not.match(`^[a-z]+`);
-
Declaration
@safe bool
True
(stringfile
= __FILE__, size_tline
= __LINE__);Asserts for a boolean value to be equal to
true
.Examples
true.should.be.True; (1 == 1).should.be.True;
-
Declaration
@safe bool
False
(stringfile
= __FILE__, size_tline
= __LINE__);Asserts for a boolean value to be equal to
true
.Examples
false.should.be.False; (1 != 1).should.be.False;
-
Declaration
@trusted void
Throw
(T : Throwable = Exception)(stringfile
= __FILE__, size_tline
= __LINE__);Asserts whether a callable object wrapped around the assertion throws an exception of type T.
Examples
void throwing() { throw new Exception("I throw with 0!"); } should(&throwing).Throw!Exception; void notThrowing() { return; } should(¬Throwing).not.Throw;
-