alma
alma copied to clipboard
A macro for operator tests
Never mind that we don't have a testing library in 007. We can stub one if we want.
This tweet felt inspiring. Not least because the author goes through a few iterations of his idea in order to arrive at the best possible macro.
(Edit: reproducing the Tweet below for completeness.)
This took a bit of macro voodoo, but I now have a pretty cool DSL for writing unit tests for my type checker. 😅 #rustlang
#[test] fn add_operator() { operator_tests! { op: add, pass: [ (int, int) -> int, (string, string) -> string ], fail: [ (int, string), (string, int), (boolean, boolean) ] }; }
The final version is here. The implementation of that macro is just above.
I think it'd be interesting to think about what would be the 007 analogue of this, and how it'd be implemented as a macro.