added __tostring comment at the beginning, if possible

This commit is contained in:
Enrique García Cota
2011-04-24 02:09:24 +02:00
parent 395b02ecbe
commit f46ce9b86b
2 changed files with 39 additions and 12 deletions

View File

@@ -147,16 +147,33 @@ context( 'inspect', function()
end)
test('Should include the metatable as an extra hash attribute', function()
local foo = { foo = 1, __tostring = function(k) return 'foo' end }
local bar = setmetatable({a = 1}, foo)
assert_equal(inspect(bar), [[{
context('metatables', function()
test('Should include the metatable as an extra hash attribute', function()
local foo = { foo = 1, __mode = 'v' }
local bar = setmetatable({a = 1}, foo)
assert_equal(inspect(bar), [[{
a = 1,
<metatable> = {
__tostring = <function>
foo = 1,
__mode = "v",
foo = 1
}
}]])
end)
test('Should include the __tostring metamethod if it exists', function()
local foo = { foo = 1, __tostring = function() return 'hello\nworld' end }
local bar = setmetatable({a = 1}, foo)
assert_equal(inspect(bar), [[{ -- hello\nworld
a = 1,
<metatable> = {
__tostring = <function>,
foo = 1
}
}]])
end)
end)