@ -7,8 +7,32 @@
-- public function
local bufferMethods = {
add = function(self, ...)
local args = {...}
for i=1, #args do
table.insert(self.data, tostring(args[i]))
end
return self
}
local function newBuffer()
return setmetatable( { data = {} }, {
__index = bufferMethods,
__tostring = function(self) return table.concat(self.data) end
} )
local function inspect(t)
return ""
local buffer = newBuffer()
buffer:add('{')
for i=1, #t do
if i > 1 then buffer:add(', ') end
buffer:add(tostring(t[i]))
buffer:add('}')
return tostring(buffer)
return inspect
@ -2,8 +2,8 @@ local inspect = require 'inspect'
context( 'inspect', function()
test('Should work with simple arrays', function()
assert_equal(inspect( {1,2,3}
test('Should work with simple array-like tables', function()
assert_equal(inspect({1,2,3}), "{1, 2, 3}" )
end)