FEATURE: Assert equal for tables
An assertion for tables the does a deep comparison.
Also, if the error messages could serialize tables that would be nice too.
Right now it just shows table: 0x7fac41603780 ~= table: 0x7fac41700130.
The inspect library is good for this.
I think it's better to integrate the assert lib: https://github.com/Olivine-Labs/luassert
it would solve more problems with asserts in u-test
I like this feature and actually implemented something similar in my own version of u-test, but on the other hand I like the simplicity of this library.
How about allowing library users to override how assertion parameters are displayed? Then it would be easy to use inspect or any other custom display code while keeping u-test simple and sane.
You can use recently added "Custom assertions" and craft something like.
local function tables_equal(tbl1, tbl2)
if not (inspect(tbl1) == inspect(tbl2)) then
local failure_msg = inspect(tbl1) .. " ~= " .. inspect(tbl2)
return false, msg
end
end
test.register_assert("tables_equal", tables_equal)
P.S.
I have found curious bug.
Implementations of equal is a little bit broken.
api.equal = function (l, r)
if l ~= r then
fail(tostring(l) .. " ~= " .. tostring(r))
end
end
Implementation assumes l ~= r same as not (l == r).
In case of meta methods this assumption is wrong. Same with not_equal. I will fix it ASAP.
As far as I remeber lua does not have metamethod for 'not equal' operation. So '~=' becomes 'not __eq' as you expected.