local O=require(script.Parent.table)local function z(O)local z=newproxy(true)local b=("\083\121\109\098\111\108\040\037\115\041"):format(O);(getmetatable(z)).__tostring=function()return b end return z end return function()it("\115\104\111\117\108\100 \104\097\110\100\108\101 \109\097\112\112\105\110\103",function()local z=O.map({"\097","\098";"\099","\100"},function(O)return O:upper()end);(expect(z[1])).to.equal("\065");(expect(z[2])).to.equal("\066");(expect(z[3])).to.equal("\067");(expect(z[4])).to.equal("\068")end)it("\115\104\111\117\108\100 \104\097\110\100\108\101 \102\105\110\100\105\110\103",function()local z=O.find({"\104\101\108\108\111","\119\111\114\108\100"},function(O)return O=="\104\101\108\108\111"end);(expect(z)).to.equal("\104\101\108\108\111")end)it("\115\104\111\117\108\100 \104\097\110\100\108\101 \102\105\108\116\101\114",function()local z=O.filter({1;2;3,4,5;6},function(O)return O%2==0 end)for O=1,#z,1 do(expect(z[O]%2)).to.equal(0)end end)it("\115\104\111\117\108\100 \104\097\110\100\108\101 \118\097\114\105\097\116\105\111\110\115 \111\102 \116\097\098\108\101\046\114\101\109\111\118\101",function()local z={1,2;3,4,"\074\111\104\110 \068\111\101"}O.remove(z,"\074\111\104\110 \068\111\101");(expect(O.find(z,function(O)return O=="\074\111\104\110 \068\111\101"end))).never.to.be.ok()O.remove(z,function(O)return O%2==0 end)O.remove(z,1);(expect(z[1])).to.equal(3)end)it("\115\104\111\117\108\100 \104\097\110\100\108\101 \116\097\098\108\101\046\116\111\115\116\114\105\110\103",function()(expect(O.tostring({1,2,3;4}))).to.equal("\123\091\049\093 \061 \049\044 \091\050\093 \061 \050\044 \091\051\093 \061 \051\044 \091\052\093 \061 \052\125");(expect(O.tostring({a=1;b=2}))).to.equal("\123\097 \061 \049\044 \098 \061 \050\125");(expect(O.tostring({1,2,{3;4}}))).to.equal("\123\091\049\093 \061 \049\044 \091\050\093 \061 \050\044 \091\051\093 \061 \123\091\049\093 \061 \051\044 \091\050\093 \061 \052\125\125");(expect(O.tostring({a=1,b={c=2}},{}))).to.equal("\123\097 \061 \049\044 \098 \061 \123\099 \061 \050\125\125");(expect(O.tostring({z("\084\101\115\116")}))).to.equal("\123\091\049\093 \061 \060\083\121\109\098\111\108\040\084\101\115\116\041\062\125");(expect(O.tostring({function() end}))).to.equal("\123\091\049\093 \061 \060\102\117\110\099\116\105\111\110\062\125");(expect(O.tostring({Instance.new("\070\114\097\109\101")}))).to.equal("\123\091\049\093 \061 \060\070\114\097\109\101\062\125");(expect(O.tostring({"\084\101\115\116"}))).to.equal("\123\091\049\093 \061 \"\084\101\115\116\"\125")end)it("\115\104\111\117\108\100 \104\097\110\100\108\101 \116\097\098\108\101\046\106\111\105\110",function()local z=O.join({a=1,b=2;10},{c=3},{d=4},{5});(expect(z.a)).to.be.ok();(expect(z.b)).to.be.ok();(expect(z.c)).to.be.ok();(expect(z.d)).to.be.ok();(expect(z[1])).to.equal(10);(expect(z[2])).to.equal(5)end)it("\115\104\111\117\108\100 \104\097\110\100\108\101 \116\097\098\108\101\046\099\111\112\121",function()local z={1,2,{3}}local b=O.copy(z);(expect(z)).never.to.equal(b);(expect(z[1])).to.equal(b[1]);(expect(z[2])).to.equal(b[2]);(expect(z[3])).never.to.equal(b[3]);(expect(z[3][1])).to.equal(b[3][1])end)it("\115\104\111\117\108\100 \104\097\110\100\108\101 \116\104\101 \097\100\118\097\110\099\101\100 \116\097\098\108\101\046\099\111\110\099\097\116",function()(expect(O.concat({1;2,3,{4;5}},"\044 "))).to.equal("\049\044 \050\044 \051\044 \091 \052\044 \053 \093")end)it("\115\104\111\117\108\100 \104\097\110\100\108\101 \116\097\098\108\101\046\115\117\098",function()local z=O.sub({1;2,3;4},2);(expect(O.tostring(z))).to.equal("\123\091\049\093 \061 \050\044 \091\050\093 \061 \051\044 \091\051\093 \061 \052\125")local b=O.sub({"\097";"\098","\099","\100","\101","\102"},2,4);(expect(O.tostring(b))).to.equal("\123\091\049\093 \061 \"\098\"\044 \091\050\093 \061 \"\099\"\044 \091\051\093 \061 \"\100\"\125")end)it("\115\104\111\117\108\100 \104\097\110\100\108\101 \116\097\098\108\101\046\116\114\117\110\099\097\116\101",function()local z={1,2,nil;3;4,nil,5};(expect(z[3])).never.to.be.ok()O.truncate(z);(expect(z[3])).to.be.ok();(expect(z[3])).to.equal(3)end)end
local table = require(script.Parent.table)

local function symbol(name)
	local self = newproxy(true)
	local wrappedName = ("Symbol(%s)"):format(name)
	getmetatable(self).__tostring = function()
		return wrappedName
	end

	return self
end

return function()
	it(
		"should handle mapping",
		function()
			local mapped =
				table.map(
				{"a", "b", "c", "d"},
				function(value)
					return value:upper()
				end
			)
			expect(mapped[1]).to.equal("A")
			expect(mapped[2]).to.equal("B")
			expect(mapped[3]).to.equal("C")
			expect(mapped[4]).to.equal("D")
		end
	)

	it(
		"should handle finding",
		function()
			local found =
				table.find(
				{"hello", "world"},
				function(value)
					return value == "hello"
				end
			)
			expect(found).to.equal("hello")
		end
	)

	it(
		"should handle filter",
		function()
			local filter =
				table.filter(
				{1, 2, 3, 4, 5, 6},
				function(value)
					return value % 2 == 0
				end
			)
			for i = 1, #filter do
				expect(filter[i] % 2).to.equal(0)
			end
		end
	)

	it(
		"should handle variations of table.remove",
		function()
			local testTable = {1, 2, 3, 4, "John Doe"}
			table.remove(testTable, "John Doe")

			expect(
				table.find(
					testTable,
					function(value)
						return value == "John Doe"
					end
				)
			).never.to.be.ok()

			table.remove(
				testTable,
				function(value)
					return value % 2 == 0
				end
			)

			table.remove(testTable, 1)

			expect(testTable[1]).to.equal(3)
		end
	)

	it(
		"should handle table.tostring",
		function()
			expect(table.tostring({1, 2, 3, 4})).to.equal("{[1] = 1, [2] = 2, [3] = 3, [4] = 4}")
			expect(table.tostring({a = 1, b = 2})).to.equal("{a = 1, b = 2}")
			expect(table.tostring({1, 2, {3, 4}})).to.equal("{[1] = 1, [2] = 2, [3] = {[1] = 3, [2] = 4}}")
			expect(table.tostring({a = 1, b = {c = 2}}, {})).to.equal("{a = 1, b = {c = 2}}")

			expect(table.tostring({symbol("Test")})).to.equal("{[1] = <Symbol(Test)>}")
			expect(
				table.tostring(
					{
						function()
						end
					}
				)
			).to.equal("{[1] = <function>}")

			expect(table.tostring({Instance.new("Frame")})).to.equal("{[1] = <Frame>}")
			expect(table.tostring({"Test"})).to.equal('{[1] = "Test"}')
		end
	)

	it(
		"should handle table.join",
		function()
			local join = table.join({a = 1, b = 2, 10}, {c = 3}, {d = 4}, {5})
			expect(join.a).to.be.ok()
			expect(join.b).to.be.ok()
			expect(join.c).to.be.ok()
			expect(join.d).to.be.ok()
			expect(join[1]).to.equal(10)
			expect(join[2]).to.equal(5)
		end
	)

	it(
		"should handle table.copy",
		function()
			local oldTable = {1, 2, {3}}
			local newTable = table.copy(oldTable)

			expect(oldTable).never.to.equal(newTable)
			expect(oldTable[1]).to.equal(newTable[1])
			expect(oldTable[2]).to.equal(newTable[2])
			expect(oldTable[3]).never.to.equal(newTable[3])
			expect(oldTable[3][1]).to.equal(newTable[3][1])
		end
	)

	it(
		"should handle the advanced table.concat",
		function()
			expect(table.concat({1, 2, 3, {4, 5}}, ", ")).to.equal("1, 2, 3, [ 4, 5 ]")
		end
	)

	it(
		"should handle table.sub",
		function()
			local subTable = table.sub({1, 2, 3, 4}, 2)
			expect(table.tostring(subTable)).to.equal("{[1] = 2, [2] = 3, [3] = 4}")

			local subTable2 = table.sub({"a", "b", "c", "d", "e", "f"}, 2, 4)
			expect(table.tostring(subTable2)).to.equal('{[1] = "b", [2] = "c", [3] = "d"}')
		end
	)

	it(
		"should handle table.truncate",
		function()
			local testTable = {1, 2, nil, 3, 4, nil, 5}
			expect(testTable[3]).never.to.be.ok()

			table.truncate(testTable)
			expect(testTable[3]).to.be.ok()
			expect(testTable[3]).to.equal(3)
		end
	)
end
