mirror of
https://github.com/kikito/inspect.lua.git
synced 2024-12-15 14:34:21 +00:00
adds test for rawlen
This commit is contained in:
parent
3d27a547e0
commit
387a2f683a
@ -1,6 +1,7 @@
|
||||
local inspect = require 'inspect'
|
||||
local unindent = require 'spec.unindent'
|
||||
local is_luajit, ffi = pcall(require, 'ffi')
|
||||
local has_rawlen = type(_G.rawlen) == 'function'
|
||||
|
||||
describe( 'inspect', function()
|
||||
|
||||
@ -74,6 +75,13 @@ describe( 'inspect', function()
|
||||
assert.equals('{ "a", "b", "c", { "d", "e" }, "f" }', inspect({'a','b','c', {'d','e'}, 'f'}))
|
||||
end)
|
||||
|
||||
if has_rawlen then
|
||||
it('handles arrays with a __len metatable correctly (ignoring the __len metatable and using rawlen)', function()
|
||||
local arr = setmetatable({1,2,3}, {__len = function() return nil end})
|
||||
assert.equals("{ 1, 2, 3 }", inspect(arr))
|
||||
end)
|
||||
end
|
||||
|
||||
it('works with simple dictionary tables', function()
|
||||
assert.equals("{\n a = 1,\n b = 2\n}", inspect({a = 1, b = 2}))
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user