Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
fantasy-laws
Advanced tools
Property-based tests to verify the lawfulness of Fantasy Land -compliant algebraic data types.
Add fantasy-laws
, jsverify
, sanctuary-show
, and
sanctuary-type-classes
to "devDependencies"
in package.json,
then run npm install
.
Usage is best explained by example. The following code defines a Sum type which is intended to satisfy Setoid, Semigroup, Monoid, and Group:
function Sum(value) {
if (!(this instanceof Sum)) return new Sum (value);
this.value = value;
}
// Sum.fantasy-land/empty :: () -> Sum
Sum['fantasy-land/empty'] = function() { return Sum (0); };
// Sum#fantasy-land/equals :: Sum ~> Sum -> Boolean
Sum.prototype['fantasy-land/equals'] = function(other) {
return Z.equals (this.value, other.value);
};
// Sum#fantasy-land/concat :: Sum ~> Sum -> Sum
Sum.prototype['fantasy-land/concat'] = function(other) {
return Sum (this.value + other.value);
};
// Sum#fantasy-land/invert :: Sum ~> () -> Sum
Sum.prototype['fantasy-land/invert'] = function() {
return Sum (-this.value);
};
The following steps demonstrate how to test the Group laws:
Require fantasy-laws
, jsverify
, sanctuary-show
, and
sanctuary-type-classes
:
const laws = require ('fantasy-laws');
const jsc = require ('jsverify');
const show = require ('sanctuary-show');
const Z = require ('sanctuary-type-classes');
Require the type to be tested:
const Sum = require ('../Sum');
Define an "arbitrary" for the type:
// SumArb :: Arbitrary Sum
const SumArb = jsc.number.smap (Sum, sum => sum.value, show);
Provide the fixed parameters to laws.Group
:
const {leftInverse, rightInverse} = laws.Group (Z.equals, Sum);
Provide the appropriate number of arbitraries to the function associated with a particular law to produce a thunk:
// testLeftInverse :: () -> Undefined !
const testLeftInverse = leftInverse (SumArb);
// testRightInverse :: () -> Undefined !
const testRightInverse = rightInverse (SumArb);
To run the tests, invoke the thunk or use a test runner such as Mocha:
suite ('Group laws', () => {
test ('left inverse', testLeftInverse);
test ('right inverse', testRightInverse);
});
FAQs
Property-based tests for Fantasy Land -compliant algebraic data types
We found that fantasy-laws demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 13 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.