Open NodeGuy opened 4 years ago
I've written a few assert law functions for various type classes here. They are not complete, but I'll likely expand on them as I build that library. If you want to steal them for your own devices feel free!
Be aware that I ran into some issues when comparing the results of the tests for ADTs like Reader and Task, since their type signatures (in my implementation) are:
export type Reader<R, A> = (r: R) => A;
export type Task<A> = () => Promise<A>;
Deno's assertEquals is not quite smart enough to compare functions (as far as I know this is a pretty hard problem). In these cases I had to settle for testing the output of executing the types, as seen here for reader and here for task.
Hope this helps you in some way.
I spent today expanding my test suite to be more flexible. You can find those tests with fully compliant types in the latest release of hkts here. Not that I've also "shimmed" an assertFunction so I don't have to treat task, reader, io, etc any differently from other monads/adts. It's a little hacky though.
Is there a way to programmatically test types for compliance with the various laws, similar to using fantasy-laws for Fantasy Land?