hhspecify/hhassert

Simple assertion library for Hack

0.2.0 2015-06-25 08:31 UTC

This package is not auto-updated.

Last update: 2024-10-26 18:17:30 UTC


README

hhassert is simple assertion library for Hack.
You can use easily as assert module of nodejs.

Build Status HHVM Status Dependency Status

Basic Usage

It will specify the hhassert\Assert in the use keyword.

use hhassert\Assert;

Assert::ok(1 === 1);      //Passed
Assert::ok("a" === "b");  //Failed

Assert::equal("a", "a");  //Passed
Assert::equal(1, 1);      //Passed
Assert::equal(1.0, 2.0);  //Failed

Assert::notEqual("a", "b"); //Passed
Assert::notEqual("a", "a"); //Failed

Assert::throws(() ==> {
    throw new InvalidArgumentException("exception!!");
}, InvalidArgumentException::class);

Custom matcher

You can be the registration of the matcher in the configure method. Matcher specified in the lambda expression.

Assert::configure((ContextBuilder $builder) ==> {

    $builder->registerMatcher('custom_matcher', (...) ==> {
        list($a, $b) = func_get_args();

        if ($a !== $b) {
            throw new AssertionFailedException("custom matcher");
        }
    });

});

Assert::custom_matcher("a", "b");

Run the test

composer install
composer test