pijamas.assertion
Pijamas, a BDD assertion library for D.
License
Licensed under the MIT license. See LICENSE for more information.
-
Declaration
Assertion!Tshould(T)(auto ref Tcontext);The function
shouldit's an helper or syntax sugar to create the assertation. Because of D’s lookup shortcut syntax, one is able to use bothandshould(obj)obj.to get an object wrapped around an Assertion instanceshould -
Declaration
aliasexpect= should(T)(auto ref T context);The function
expectit's an helper or syntax sugar to create the assertation. Because of D’s lookup shortcut syntax, one is able to use bothandexpect(obj)obj.to get an object wrapped around an Assertion instanceexpect -
Declaration
structAssertion(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
aliasbe= 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 Assertionnot();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 Tequal(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 TapproxEqual(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
UotherValue to compare to compare.
UmaxRelDiffMaximum 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.otherUmaxAbsDiffMaximum absolute difference. This is mainly usefull for comparing values to zero. Setting to 0.0 disables this check. Defaults to
0.0.stringfilefilename
size_tlinelinenumber inside offileExamples
double d = 0.1; double d2 = d + 1e-10; d.should.not.be.equal(d2); d.should.be.approxEqual(d2);
-
Declaration
aliasclose= 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 Texist(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 boolbiggerThan(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 boolbiggerOrEqualThan(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 boolsmallerThan(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 boolsmallerOrEqualThan(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 boolsorted(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 voidkey(U)(Uother, stringfile= __FILE__, size_tline= __LINE__);Asserts for an associative array to have a
keyequal toother.Examples
["something": 10].should.have.key("something");
-
Declaration
@nogc @trusted Uinclude(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/includeavalue.Examples
[1, 2, 3, 4].should.include(3); "something".should.not.include('o'); "something".should.include("th");
-
Declaration
@trusted Ulength(U)(Ulen, stringfile= __FILE__, size_tline= __LINE__);Asserts for the .
lengthproperty 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 boolempty(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 automatch(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
matcha 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 boolTrue(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 boolFalse(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 voidThrow(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;
-