lunarmodules / luassert

Assertion library for Lua
MIT License
202 stars 77 forks source link

Array asssertion #145

Closed Tieske closed 7 years ago

Tieske commented 7 years ago

closes #131 and #139

Add a holes assertion. But also serves as an example on how to create custom assertions to operate on specific objects. Hence I kept the code in a single example file, and didn't combine it with other files.

example usage;

local arr = { "one", "two", "three" }

assert.array(arr).has.no.holes()   -- checks the array to not contain holes --> passes
assert.array(arr).has.no.holes(4)  -- sets explicit length to 4 --> fails

local first_hole = assert.array(arr).has.holes(4)     -- check array of size 4 to contain holes --> passes
assert.equal(4, first_hole)        -- passes, as the index of the first hole is returned
DorianGray commented 7 years ago

:+1: