Add __tostring to Stack

squeeze-backports
Victor Seva 13 years ago
parent 76e2c024a5
commit 8bdb517d84

@ -134,9 +134,14 @@ end
-- GLOBAL -- GLOBAL
Stack = { Stack = {
__class__ = 'Stack' __class__ = 'Stack',
}
Stack_MT = {
__index = Stack,
__tostring = function(t)
return table.tostring(Stack.list(t))
end
} }
Stack_MT = { __index = Stack }
-- Create a Table with stack functions -- Create a Table with stack functions
function Stack:new() function Stack:new()

@ -88,6 +88,14 @@ TestStack = {}
assertItemsEquals(l[1],{1,2,3}) assertItemsEquals(l[1],{1,2,3})
assertEquals(l[2],1) assertEquals(l[2],1)
end end
function TestStack:test_tostring()
s = Stack:new()
s:push(1)
assertEquals(tostring(s), "{1}")
s:push(2)
assertEquals(tostring(s), "{2,1}")
end
-- class TestStack -- class TestStack
---- Control test output: ---- Control test output:
lu = LuaUnit lu = LuaUnit

Loading…
Cancel
Save