Module:Format ISBN/data/testcases

-- Unit tests for Module:Format ISBN/data. Click talk page to run tests. -- Example usage: --  -- Console example: --  mw.log(p.run_tests(mw.getCurrentFrame))

local p = require('Module:UnitTests') local _data = require('Module:Format ISBN/data')

function p:test_basic_sanity self:equals("type(_data)", type(_data), "table") local count = 0; for _ in pairs(_data) do count = count + 1 end self:equals("#_data > 0", count > 0, true) end

function p:test_main_registration_groups_exist self:equals("type(_data[\"978-0\"])", type(_data["978-0"]), "table") self:equals("type(_data[\"978-1\"])", type(_data["978-1"]), "table") self:equals("type(_data[\"979-8\"])", type(_data["979-8"]), "table") end

function p:test_978_0_table_shape self:equals("type(_data[\"978-0\"])", type(_data["978-0"]), "table") self:equals("#_data[\"978-0\"] > 0", #_data["978-0"] > 0, true)

for i = 1, #_data["978-0"] do self:equals("type(_data[\"978-0\"][" .. i .. "])", type(_data["978-0"][i]), "table") self:equals("#_data[\"978-0\"][" .. i .. "] > 0", #_data["978-0"][i] > 0, true)

self:equals("type(_data[\"978-0\"][" .. i .. "][1])", type(_data["978-0"][i][1]), "number") for j = 2, #_data["978-0"][i] do self:equals("type(_data[\"978-0\"][" .. i .. "][" .. j .. "])", type(_data["978-0"][i][j]), "table") self:equals("#_data[\"978-0\"][" .. i .. "][" .. j .."]", #_data["978-0"][i][j], 2)

self:equals("type(_data[\"978-0\"][" .. i .. "][" .. j .."][1])", type(_data["978-0"][i][j][1]), "number") self:equals("type(_data[\"978-0\"][" .. i .. "][" .. j .."][2])", type(_data["978-0"][i][j][2]), "number") end end end

return p