return function()local k=game:GetService("\067\111\108\108\101\099\116\105\111\110\083\101\114\118\105\099\101")local J=require(script.Parent)describe("\099\114\101\097\116\105\111\110",function()it("\115\104\111\117\108\100 \099\114\101\097\116\101 \097 \110\101\119 \105\110\115\116\097\110\099\101",function()(expect(J.new(Instance.new("\080\097\114\116")))).to.be.a("\116\097\098\108\101")end)it("\115\104\111\117\108\100 \102\097\105\108 \119\105\116\104\111\117\116 \097 \116\101\109\112\108\097\116\101",function()(expect(function()J.new()end)).to.throw()end)it("\115\104\111\117\108\100 \102\097\105\108 \119\105\116\104 \097\110 \105\110\118\097\108\105\100 \099\111\110\102\105\103\117\114\097\116\105\111\110",function()(expect(function()J.new(Instance.new("\083\111\117\110\100"),{returnMethod="\099\102\114\097\109\101"})end)).to.throw("\099\097\110\110\111\116 \099\114\101\097\116\101 \080\111\111\108\101\114 \119\105\116\104 \099\102\114\097\109\101 \114\101\116\117\114\110 \109\101\116\104\111\100 \105\102 \105\110\115\116\097\110\099\101 \116\101\109\112\108\097\116\101 \105\115 \110\111\116 \097 \066\097\115\101\080\097\114\116 \111\114 \077\111\100\101\108")end)it("\115\104\111\117\108\100 \099\114\101\097\116\101 \097 \114\097\110\100\111\109 \105\110\115\116\097\110\099\101 \119\105\116\104 \114\097\110\100\111\109 \103\101\116\077\101\116\104\111\100",function()local k=J.new(Instance.new("\080\097\114\116"),{getMethod="\114\097\110\100\111\109"});(expect(k._random)).to.be.a("\117\115\101\114\100\097\116\097")end)end)describe("\112\111\111\108\105\110\103",function()local i=Instance.new("\080\097\114\116")local c=J.new(i,{size=50})it("\115\104\111\117\108\100 \104\097\118\101 \097 \099\101\114\116\097\105\110 \097\109\111\117\110\116 \111\102 \105\110\115\116\097\110\099\101\115 \105\110 \116\104\101 \112\111\111\108 \097\108\114\101\097\100\121",function()(expect(c:Size())).to.equal(50)end)it("\115\104\111\117\108\100 \116\097\103 \097\108\108 \105\110\115\116\097\110\099\101\115 \119\105\116\104 \097 \099\101\114\116\097\105\110 \112\111\111\108 \116\097\103",function()for J,i in pairs(c._pool)do(expect(function()if not k:HasTag(i,"\112\111\111\108\101\114\095"..c._id)then error("\078\111 \116\097\103\033")end end)).never.to.throw()end end)it("\115\104\111\117\108\100 \103\101\116 \097\110 \105\110\115\116\097\110\099\101",function()(expect(c:Get())).to.be.ok()end)it("\115\104\111\117\108\100 \098\101 \097\098\108\101 \116\111 \114\101\116\117\114\110 \097\110 \105\110\115\116\097\110\099\101",function()(expect(function()local J=c:Get()c:Return(J)if k:HasTag(J,"\112\111\111\108\101\114\095\105\110\085\115\101")then error("\083\116\105\108\108 \105\110 \117\115\101\033")end end)).never.to.throw()end)it("\115\104\111\117\108\100 \098\101 \097\098\108\101 \116\111 \114\101\115\105\122\101 \116\104\101 \112\111\111\108",function()c:Resize(100);(expect(c:Size())).to.equal(100)c:Resize(50);(expect(c:Size())).to.equal(50)end)it("\115\104\111\117\108\100 \110\111\116 \098\101 \117\115\097\098\108\101 \097\102\116\101\114 \098\101\105\110\103 \100\101\115\116\114\111\121\101\100",function()c:Destroy();(expect(function()c:Get()end)).to.throw("\097\116\116\101\109\112\116 \116\111 \117\115\101 \100\101\115\116\114\111\121\101\100 \080\111\111\108\101\114 \105\110\115\116\097\110\099\101")end)end)describe("\101\120\104\097\117\115\116\105\111\110",function()local k=Instance.new("\080\097\114\116")local i=J.new(k,{size=50,exhaustion=true})it("\115\104\111\117\108\100 \115\116\097\114\116 \119\105\116\104 \053\048 \105\110\115\116\097\110\099\101\115",function()(expect(i:Size())).to.equal(50)end)it("\115\104\111\117\108\100 \114\101\109\111\118\101 \097\110\100 \097\100\100 \105\110\115\116\097\110\099\101 \097\102\116\101\114 \103\101\116\116\105\110\103 \097\110\100 \114\101\116\117\114\110\105\110\103",function()local k=i:Get();(expect(i:Size())).to.equal(49)i:Return(k);(expect(i:Size())).to.equal(50)end)it("\115\104\111\117\108\100 \100\101\115\116\114\111\121 \097\110\100 \114\101\109\111\118\101 \097\108\108 \105\110\115\116\097\110\099\101\115 \102\114\111\109 \116\104\101 \112\111\111\108",function()i:Destroy();(expect(i:Size())).to.equal(0)end)end)end
--!nocheck
--^ see line 16

return function()
	local CollectionService = game:GetService("CollectionService")

	local Pooler = require(script.Parent)

	describe("creation", function()
		it("should create a new instance", function()
			expect(Pooler.new(Instance.new("Part"))).to.be.a("table")
		end)

		it("should fail without a template", function()
			expect(function()
				Pooler.new()
			end).to.throw()
		end)

		it("should fail with an invalid configuration", function()
			expect(function()
				Pooler.new(Instance.new("Sound"), { returnMethod = "cframe" })
			end).to.throw("cannot create Pooler with cframe return method if instance template is not a BasePart or Model")
		end)

		it("should create a random instance with random getMethod", function()
			local instance = Pooler.new(Instance.new("Part"), { getMethod = "random" })
			expect(instance._random).to.be.a("userdata")
		end)
	end)

	describe("pooling", function()
		local template = Instance.new("Part")
		local pool = Pooler.new(template, { size = 50 })

		it("should have a certain amount of instances in the pool already", function()
			expect(pool:Size()).to.equal(50)
		end)

		it("should tag all instances with a certain pool tag", function()
			for _, v in pairs(pool._pool) do
				expect(function()
					if not CollectionService:HasTag(v, "pooler_" .. pool._id) then
						error("No tag!")
					end
				end).never.to.throw()
			end
		end)

		it("should get an instance", function()
			expect(pool:Get()).to.be.ok()
		end)

		it("should be able to return an instance", function()
			expect(function()
				local instance = pool:Get()
				pool:Return(instance)

				if CollectionService:HasTag(instance, "pooler_inUse") then
					error("Still in use!")
				end
			end).never.to.throw()
		end)

		it("should be able to resize the pool", function()
			pool:Resize(100)
			expect(pool:Size()).to.equal(100)

			pool:Resize(50)
			expect(pool:Size()).to.equal(50)
		end)

		it("should not be usable after being destroyed", function()
			pool:Destroy()

			expect(function()
				pool:Get()
			end).to.throw("attempt to use destroyed Pooler instance")
		end)
	end)

	describe("exhaustion", function()
		local template = Instance.new("Part")
		local exhaustionPool = Pooler.new(template, { size = 50, exhaustion = true })

		it("should start with 50 instances", function()
			expect(exhaustionPool:Size()).to.equal(50)
		end)

		it("should remove and add instance after getting and returning", function()
			local instance = exhaustionPool:Get()
			expect(exhaustionPool:Size()).to.equal(49)

			exhaustionPool:Return(instance)
			expect(exhaustionPool:Size()).to.equal(50)
		end)

		it("should destroy and remove all instances from the pool", function()
			exhaustionPool:Destroy()
			expect(exhaustionPool:Size()).to.equal(0)
		end)
	end)
end
