local e=require("\064\102\114\107\116\101\115\116\047\102\114\107\116\101\115\116")local W=e.test local w=e.assert.check return function()W.suite("\084\097\098\108\101\115",function()W.case("\118\097\108\117\101 \101\113\117\097\108",function()local e={foo=1}local W={foo=1}local m=e w.equal(e,W)w.not_equal(e,m)end)W.case("\099\111\110\116\097\105\110\115",function()local e={a=1,b=2,c=3}w.table.contains(e,"\100")w.table.contains(e,{"\098","\099";"\100";"\101"})end)W.case("\116\097\098\108\101 \101\113\117\097\108 \109\111\100\105\102\105\101\100",function()local e={a=1,b=2}local W={a=1,b=20}w.table.equal(e,W)end)W.case("\116\097\098\108\101 \101\113\117\097\108 \097\100\100\101\100",function()local e={a=1;b=2}local W={a=1}w.table.equal(e,W)end)W.case("\116\097\098\108\101 \101\113\117\097\108 \109\105\115\115\105\110\103",function()local e={a=1}local W={a=1,b=2}w.table.equal(e,W)end)W.case("\097\114\114\097\121\115 \111\102 \116\097\098\108\101\115 \102\105\116 \104\101\114\101",function()local e={{a=1},{a=3}}local W={{a=1},{a=22},{a=3}}w.table.equal(e,W)end)W.case("\116\097\098\108\101-\110\101\115\115 \105\115 \099\104\101\099\107\101\100 \097\116 \114\117\110\116\105\109\101",function()local e="\115\116\114"local W={a=1,b=2}w.table.contains(e,"\097")w.table.equal(W,e)w.table.equal(e,W)end)W.case("\109\101\116\097\116\097\098\108\101\115 \097\114\101\110\'\116 \099\111\110\115\105\100\101\114\101\100",function()local e=setmetatable({a=10},{foo=function() end;b=10})local W=setmetatable({a=10},{bar=function() end;b=20})w.table.equal(e,W)end)end)end
local frktest = require("@frktest/frktest")
local test = frktest.test
local check = frktest.assert.check

return function()
    test.suite("Tables", function()
        test.case("value equal", function()
            local a = { foo = 1 }
            local b = { foo = 1 }
            local c = a
            check.equal(a, b) -- fails, equal checks the address of tables
            check.not_equal(a, c) -- fails, variables pointing to the same table equal eachother
        end)

        test.case("contains", function()
            local a = { a = 1, b = 2, c = 3 }
            check.table.contains(a, "d") -- check for one key
            check.table.contains(a, { "b", "c", "d", "e" }) -- check for multiple keys
        end)

        test.case("table equal modified", function()
            local a = { a = 1, b = 2 }
            local b = { a = 1, b = 20 }
            check.table.equal(a, b)
        end)

        test.case("table equal added", function()
            local a = { a = 1, b = 2 }
            local b = { a = 1 }
            check.table.equal(a, b)
        end)

        test.case("table equal missing", function()
            local a = { a = 1 }
            local b = { a = 1, b = 2 }
            check.table.equal(a, b)
        end)

        test.case("arrays of tables fit here", function()
            local a = { { a = 1 }, { a = 3 } }
            local b = { { a = 1 }, { a = 22 }, { a = 3 } }
            check.table.equal(a, b)
        end)

        test.case("table-ness is checked at runtime", function()
            local not_table = "str"
            local a = { a = 1, b = 2 }

            -- passing non-tables will fail the assertion with helpful message
            check.table.contains(not_table, "a")
            check.table.equal(a, not_table)
            check.table.equal(not_table, a)
        end)

        test.case("metatables aren't considered", function()
            -- these 2 tables are equal, even though their MTs are different
            local a = setmetatable({ a = 10 }, { foo = function() end, b = 10 })
            local b = setmetatable({ a = 10 }, { bar = function() end, b = 20 })
            check.table.equal(a, b)
        end)
    end)
end
