local s=require(script.Parent.topoRuntime)return function()describe("\084\111\112\111\082\117\110\116\105\109\101",function()it("\115\104\111\117\108\100 \114\101\115\116\111\114\101 \115\116\097\116\101",function()local function Q()local Q=s.useHookState()Q.counter=(Q.counter or 0)+1 return Q.counter end local a={system={}}local i=0 local function q()i+=1;(expect(Q())).to.equal(i)end s.start(a,q)s.start(a,q);(expect(i)).to.equal(2)end)it("\115\104\111\117\108\100 \099\108\101\097\110\117\112",function()local Q=false local a=0 local function i()local i=s.useHookState(nil,function()if Q then a+=1 else return true end end)i.counter=(i.counter or 0)+1 return i.counter end local q={system={}}local U=true local function z()if U then(expect(i())).to.equal(1)end end s.start(q,z);(expect(a)).to.equal(0)U=false s.start(q,z);(expect(a)).to.equal(0)Q=true s.start(q,z);(expect(a)).to.equal(1)U=true s.start(q,z);(expect(a)).to.equal(1)end)it("\115\104\111\117\108\100 \097\108\108\111\119 \107\101\121\105\110\103 \098\121 \117\110\105\113\117\101 \118\097\108\117\101\115",function()local function Q(Q)local a=s.useHookState(Q)a.counter=(a.counter or 0)+1 return a.counter end local a={system={}}local i=0 local function q()i+=1;(expect(Q("\097 \118\097\108\117\101"))).to.equal(i)end s.start(a,q)s.start(a,q);(expect(i)).to.equal(2)s.start(a,function()q()q()end);(expect(i)).to.equal(4)end)end)end
local topoRuntime = require(script.Parent.topoRuntime)

return function()
	describe("TopoRuntime", function()
		it("should restore state", function()
			local function useHook()
				local storage = topoRuntime.useHookState()

				storage.counter = (storage.counter or 0) + 1

				return storage.counter
			end

			local node = {
				system = {},
			}

			local ranCount = 0
			local function fn()
				ranCount += 1
				expect(useHook()).to.equal(ranCount)
			end

			topoRuntime.start(node, fn)

			topoRuntime.start(node, fn)

			expect(ranCount).to.equal(2)
		end)

		it("should cleanup", function()
			local shouldCleanup = false
			local cleanedUpCount = 0
			local function useHook()
				local storage = topoRuntime.useHookState(nil, function()
					if shouldCleanup then
						cleanedUpCount += 1
					else
						return true
					end
				end)

				storage.counter = (storage.counter or 0) + 1

				return storage.counter
			end

			local node = {
				system = {},
			}

			local shouldRunHook = true
			local function fn()
				if shouldRunHook then
					expect(useHook()).to.equal(1)
				end
			end

			topoRuntime.start(node, fn)

			expect(cleanedUpCount).to.equal(0)

			shouldRunHook = false

			topoRuntime.start(node, fn)

			expect(cleanedUpCount).to.equal(0)

			shouldCleanup = true

			topoRuntime.start(node, fn)

			expect(cleanedUpCount).to.equal(1)

			shouldRunHook = true

			topoRuntime.start(node, fn)

			expect(cleanedUpCount).to.equal(1)
		end)

		it("should allow keying by unique values", function()
			local function useHook(unique)
				local storage = topoRuntime.useHookState(unique)

				storage.counter = (storage.counter or 0) + 1

				return storage.counter
			end

			local node = {
				system = {},
			}

			local ranCount = 0
			local function fn()
				ranCount += 1
				expect(useHook("a value")).to.equal(ranCount)
			end

			topoRuntime.start(node, fn)

			topoRuntime.start(node, fn)

			expect(ranCount).to.equal(2)

			topoRuntime.start(node, function()
				fn()
				fn()
			end)

			expect(ranCount).to.equal(4)
		end)
	end)
end
