Add a basic test for df.image_set.find()

develop
lethosor 2020-04-05 23:30:24 -04:00
parent cc2a5acdd3
commit d664681ea8
2 changed files with 37 additions and 2 deletions

@ -17,10 +17,13 @@ local VALID_MODES = utils.invert{'none', 'title', 'fortress'}
expect = {} expect = {}
function expect.true_(value, comment) function expect.true_(value, comment)
return not not value, comment, 'expected true' return not not value, comment, 'expected true, got ' .. tostring(value)
end end
function expect.false_(value, comment) function expect.false_(value, comment)
return not value, comment, 'expected false' return not value, comment, 'expected false, got ' .. tostring(value)
end
function expect.nil_(value, comment)
return value == nil, comment, 'expected nil, got ' .. tostring(value)
end end
function expect.eq(a, b, comment) function expect.eq(a, b, comment)
return a == b, comment, ('%s ~= %s'):format(a, b) return a == b, comment, ('%s ~= %s'):format(a, b)

@ -0,0 +1,32 @@
config = {
mode = 'title',
}
local function clean_vec(vec)
while #vec > 0 do
if vec[0] then
expect.true_(vec[0]:delete())
end
vec:erase(0)
end
end
local function with_clean_vec(cls, callback)
local vec = cls.get_vector()
dfhack.call_with_finalizer(1, true, clean_vec, vec, callback, vec)
end
function test.image_set()
-- todo: expand to other types?
with_clean_vec(df.image_set, function(vec)
vec:insert('#', {new = df.image_set, id = 1})
vec:insert('#', {new = df.image_set, id = 2})
vec:insert('#', {new = df.image_set, id = 4})
expect.eq(df.image_set.find(1).id, 1)
expect.eq(df.image_set.find(2).id, 2)
expect.eq(df.image_set.find(4).id, 4)
expect.nil_(df.image_set.find(3))
expect.nil_(df.image_set.find(5))
expect.nil_(df.image_set.find(-1))
end)
end