cspec
cspec copied to clipboard
Assertions for arrays
It would be nice to have array equality assertions, comparing element by element.
Some thoughts about this:
- As seen here, C++ supports literal arrays, but I believe it's mandatory to assign them to a variable:
int expected[] = { 16, 2, 77, 40, 12071 };
. It would be great to avoid the variable and write something likeshould(numbers) be equal({ 16, 2, 77, 40, 12071 })
- The user should be able to decide whether the elements must be in the same order or not
Regarding literal arrays, you can avoid the variable by casting (starting C99). Something like this should work:
should(numbers) be equal (int[5] { 16, 2, 77, 40, 12071 })
And equal
signature shoud be something like:
equal(int a[static 1]);
Ref: http://stackoverflow.com/a/1269651/1335438