[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: unit testing in a functional language
- From: Michal Kolodziejczyk <miko@...>
- Date: Fri, 21 Sep 2012 10:11:12 +0200
On 21.09.2012 04:09, mitch abaza wrote:
> I come from a heavy TDD/OOP background and I'm finding it challenging to
> apply the same testing discipline to Lua.
Have you read any of those? http://lua-users.org/wiki/UnitTesting
> I'm told you can't do reference equality on functions. If true, how
> would I test that the returned table contains a "reference" to the
> filterRuleProvider.filterEmptyMessages function?
Not sure if I understand you correctly, but of course you can check if
two variables reference the same function, so that should work also in
your case:
a=function()
print('Hello world!')
end
b=a
c=function()
print('Hello world!')
end
print(a, b, c)
print(a==b, a==c)
T={a, b, c}
for k,v in ipairs(T) do
print('Equals? ', a==v)
end
Tested on Lua 5.1, but it should work for Lua 5.2..
Regards,
miko