Module:TableTools/testcases

local tableTools = require("Module:TableTools") local ScribuntoUnit = require("Module:ScribuntoUnit") local suite = ScribuntoUnit:new

-- For `tableTools.pack`

function suite:test_pack -- @TODO end

-- For `tableTools.selectFirst`

do local selectFirst = tableTools.selectFirst local expectedError = "Module:TableTools:33: bad argument #1 to " .. "'Dev:TableTools.selectFirst' (index out of range)"

function suite:test_selectFirst_1 local success, errorMessage = pcall(selectFirst, -3)

self:assertFalse(success) self:assertEquals(errorMessage, expectedError) end

function suite:test_selectFirst_2 local success, errorMessage = pcall(selectFirst, -3, "1")

self:assertFalse(success) self:assertEquals(errorMessage, expectedError) end

function suite:test_selectFirst_3 local success, errorMessage = pcall(selectFirst, -3, "1", "2")

self:assertFalse(success) self:assertEquals(errorMessage, expectedError) end

function suite:test_selectFirst_4 local success, first = pcall(selectFirst, -3, "1", "2", "3")

self:assertTrue(success) self:assertEquals(first, "1") end

function suite:test_selectFirst_5 local success, errorMessage = pcall(selectFirst, -2)

self:assertFalse(success) self:assertEquals(errorMessage, expectedError) end

function suite:test_selectFirst_6 local success, errorMessage = pcall(selectFirst, -2, "1")

self:assertFalse(success) self:assertEquals(errorMessage, expectedError) end

function suite:test_selectFirst_7 local success, first = pcall(selectFirst, -2, "1", "2")

self:assertTrue(success) self:assertEquals(first, "1") end

function suite:test_selectFirst_8 local success, first, second = pcall(selectFirst, -2, "1", "2", "3")

self:assertTrue(success) self:assertEquals(first, "1") self:assertEquals(second, "2") end

function suite:test_selectFirst_9 local success, errorMessage = pcall(selectFirst, -1)

self:assertFalse(success) self:assertEquals(errorMessage, expectedError) end

function suite:test_selectFirst_10 local success, first = pcall(selectFirst, -1, "1")

self:assertTrue(success) self:assertEquals(first, "1") end

function suite:test_selectFirst_11 local success, first, second = pcall(selectFirst, -1, "1", "2")

self:assertTrue(success) self:assertEquals(first, "1") self:assertEquals(second, "2") end

function suite:test_selectFirst_12 local success, first, second, third = pcall(selectFirst, -1, "1", "2", "3")

self:assertTrue(success) self:assertEquals(first, "1") self:assertEquals(second, "2") self:assertEquals(third, "3") end

function suite:test_selectFirst_13 local success, errorMessage = pcall(selectFirst, 0)

self:assertFalse(success) self:assertEquals(errorMessage, expectedError) end

function suite:test_selectFirst_14 local success, errorMessage = pcall(selectFirst, 0, "1")

self:assertFalse(success) self:assertEquals(errorMessage, expectedError) end

function suite:test_selectFirst_15 local success, errorMessage = pcall(selectFirst, 0, "1", "2")

self:assertFalse(success) self:assertEquals(errorMessage, expectedError) end

function suite:test_selectFirst_16 local success, errorMessage = pcall(selectFirst, 0, "1", "2", "3")

self:assertFalse(success) self:assertEquals(errorMessage, expectedError) end

function suite:test_selectFirst_17 local success, first = pcall(selectFirst, 1)

self:assertTrue(success) self:assertEquals(first, nil) end

function suite:test_selectFirst_18 local success, first = pcall(selectFirst, 1, "1")

self:assertTrue(success) self:assertEquals(first, "1") end

function suite:test_selectFirst_19 local success, first, second = pcall(selectFirst, 1, "1", "2")

self:assertTrue(success) self:assertEquals(first, "1") self:assertEquals(second, nil) end

function suite:test_selectFirst_20 local success, first = pcall(selectFirst, 1, "1", "2", "3")

self:assertTrue(success) self:assertEquals(first, "1") self:assertEquals(second, nil) self:assertEquals(third, nil) end

function suite:test_selectFirst_21 local success, first, second = pcall(selectFirst, 2)

self:assertTrue(success) self:assertEquals(first, nil) self:assertEquals(second, nil) end

function suite:test_selectFirst_22 local success, first, second = pcall(selectFirst, 2, "1")

self:assertTrue(success) self:assertEquals(first, "1") self:assertEquals(second, nil) end

function suite:test_selectFirst_23 local success, first, second = pcall(selectFirst, 2, "1", "2")

self:assertTrue(success) self:assertEquals(first, "1") self:assertEquals(second, "2") end

function suite:test_selectFirst_24 local success, first, second, third = pcall(selectFirst, 2, "1", "2", "3")

self:assertTrue(success) self:assertEquals(first, "1") self:assertEquals(second, "2") self:assertEquals(third, nil) end

function suite:test_selectFirst_25 local success, first, second, third = pcall(selectFirst, 3)

self:assertTrue(success) self:assertEquals(first, nil) self:assertEquals(second, nil) self:assertEquals(third, nil) end

function suite:test_selectFirst_26 local success, first, second, third = pcall(selectFirst, 3, "1")

self:assertTrue(success) self:assertEquals(first, "1") self:assertEquals(second, nil) self:assertEquals(third, nil) end

function suite:test_selectFirst_27 local success, first, second, third = pcall(selectFirst, 3, "1", "2")

self:assertTrue(success) self:assertEquals(first, "1") self:assertEquals(second, "2") self:assertEquals(third, nil) end

function suite:test_selectFirst_28 local success, first, second, third = pcall(selectFirst, 3, "1", "2", "3")

self:assertTrue(success) self:assertEquals(first, "1") self:assertEquals(second, "2") self:assertEquals(third, "3") end end

-- For `tableTools.isSequence`

function suite:test_isSequence -- @TODO end

-- For `tableTools.size`

function suite:test_size -- @TODO end

-- For `tableTools.includes`

function suite:test_includes -- @TODO end

-- For `tableTools.merge`

function suite:test_merge -- @TODO end

return suite