exceeds-expectations 0.1.1
A simple, IDE-friendly assertion library
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:
exceeds-expectations
exceeds-expectations is an assertion library for the D programming language. It uses the expect(___).to___()
style used by Jest and Chai.
Usage
To get started, add exceeds-expectations as a unittest dependency to your project:
configuration "unittest" {
dependency "exceeds-expectations" version="<current version>"
stringImportPaths "."
}
ℹ️ The stringImportPaths "."
is used by exceeds-expectations to point at the lines of code where an expectation failed.
⚠️ If you run into problems with stringImportPaths "."
, try using dflags "-J."
instead.
Now you can write your unittests in an easily legible format using convenient assertions.
Examples
Equality & Identity
unittest
{
Pencil pencil = new Pencil();
Pencil anotherPencil = cloneObject(pencil);
expect(anotherPencil).toEqual(pencil);
expect(anotherPencil).not.toBe(pencil);
}
Floating Point Comparison
unittest
{
real tempCelsius = 23.0;
real tempFahrenheit = celsiusToFahrenheit(tempCelsius);
expect(tempFahrenheit).toApproximatelyEqual(73.4);
}
Arbitrary Predicates
When the method you need isn't in the library... yet 😉
unittest
{
static bool someConvolutedRequirement(int n)
{
return (n < 233 && n >= -48 && n % 2 == 0) || (n > 692 && n < 10_002 && n % 3 == 1);
}
int myNumber = 8;
expect(myNumber).toSatisfy(&someConvolutedRequirement);
// Or:
expect(8).toSatisfyAny(
(n) => n < 233 && n >= -48 && n % 2 == 0,
(n) => n > 692 && n < 10_002 && n % 3 == 1
)
// .toSatisfyAll() is also available
}
Why?
Existing assertion libraries (such as dshould and fluent-asserts) rely on unified function call syntax to achieve their natural, sentence-like syntax. Unfortunately, DCD does not support auto-completions using the UFCS syntax. This means that IDEs cannot automatically suggest assertions for you.
In exceeds-expectations, assertions begin with a call to expect()
, which returns an "Expectation" object whose member functions are visible to DCD.
- Registered by Andrej Petrović
- 0.1.1 released 4 years ago
- andrej88/exceeds-expectations
- MIT
- Copyright © 2020, Andrej Petrović
- Authors:
- Dependencies:
- colorize
- Versions:
-
0.9.6 2022-Nov-20 0.9.5 2022-Jul-09 0.9.4 2022-Jun-05 0.9.3 2022-Jun-01 0.9.2 2022-Apr-19 - Download Stats:
-
-
0 downloads today
-
1 downloads this week
-
3 downloads this month
-
199 downloads total
-
- Score:
- 0.1
- Short URL:
- exceeds-expectations.dub.pm