local d=require("\064\112\107\103\047\064\106\115\100\111\116\108\117\097\047\106\101\115\116-\103\108\111\098\097\108\115")local i=d.expect local F=d.describe local k=d.beforeEach local b=d.jest local a=d.it local M F("\082\101\097\099\116\070\105\098\101\114\083\116\097\099\107",function()k(function()b.resetModules()M=require("\046\046\047\082\101\097\099\116\070\105\098\101\114\083\116\097\099\107\046\110\101\119\046\108\117\097\117")end)a("\099\114\101\097\116\101\115 \097 \099\117\114\115\111\114 \119\105\116\104 \116\104\101 \103\105\118\101\110 \100\101\102\097\117\108\116 \118\097\108\117\101",function()local d={foo=3};(i(M.createCursor(d))).toEqual({current=d})end)a("\105\110\105\116\105\097\108\105\122\101\115 \116\104\101 \115\116\097\099\107 \101\109\112\116\121",function()(i(M.isEmpty())).toBe(true)end)F("\115\116\097\099\107 \109\097\110\105\112\117\108\097\116\105\111\110\115",function()local d local F k(function()d=M.createCursor(nil)F={}end)a("\112\117\115\104\101\115 \097\110 \101\108\101\109\101\110\116 \097\110\100 \116\104\101 \115\116\097\099\107 \105\115 \110\111\116 \101\109\112\116\121",function()M.push(d,true,F);(i(M.isEmpty())).toBe(false)end)a("\112\117\115\104\101\115 \097\110 \101\108\101\109\101\110\116 \097\110\100 \097\115\115\105\103\110\115 \116\104\101 \118\097\108\117\101 \116\111 \116\104\101 \099\117\114\115\111\114",function()local k={foo=3}M.push(d,k,F);(i(d.current)).toEqual(k)end)a("\112\117\115\104\101\115 \097\110 \101\108\101\109\101\110\116\044 \112\111\112\115 \105\116 \098\097\099\107 \097\110\100 \116\104\101 \115\116\097\099\107 \105\115 \101\109\112\116\121",function()M.push(d,true,F)M.pop(d,F);(i(M.isEmpty())).toBe(true)end)a("\112\117\115\104\101\115 \097\110 \101\108\101\109\101\110\116\044 \112\111\112\115 \105\116 \098\097\099\107 \097\110\100 \116\104\101 \099\117\114\115\111\114 \104\097\115 \105\116\115 \105\110\105\116\105\097\108 \118\097\108\117\101",function()local k="\102\111\111"d.current=k M.push(d,true,F)M.pop(d,F);(i(d.current)).toBe(k)end)end)end)
local JestGlobals = require("@pkg/@jsdotlua/jest-globals")
local jestExpect = JestGlobals.expect
local describe = JestGlobals.describe
local beforeEach = JestGlobals.beforeEach
local jest = JestGlobals.jest
local it = JestGlobals.it

local ReactFiberStack

describe("ReactFiberStack", function()
	beforeEach(function()
		jest.resetModules()
		ReactFiberStack = require("../ReactFiberStack.new.luau")
	end)

	it("creates a cursor with the given default value", function()
		local defaultValue = { foo = 3 }
		jestExpect(ReactFiberStack.createCursor(defaultValue)).toEqual({
			current = defaultValue,
		})
	end)

	it("initializes the stack empty", function()
		jestExpect(ReactFiberStack.isEmpty()).toBe(true)
	end)

	describe("stack manipulations", function()
		local cursor
		local fiber

		beforeEach(function()
			cursor = ReactFiberStack.createCursor(nil)
			fiber = {}
		end)

		it("pushes an element and the stack is not empty", function()
			ReactFiberStack.push(cursor, true, fiber)
			jestExpect(ReactFiberStack.isEmpty()).toBe(false)
		end)

		it("pushes an element and assigns the value to the cursor", function()
			local pushedElement = { foo = 3 }
			ReactFiberStack.push(cursor, pushedElement, fiber)
			jestExpect(cursor.current).toEqual(pushedElement)
		end)

		it("pushes an element, pops it back and the stack is empty", function()
			ReactFiberStack.push(cursor, true, fiber)
			ReactFiberStack.pop(cursor, fiber)
			jestExpect(ReactFiberStack.isEmpty()).toBe(true)
		end)

		it(
			"pushes an element, pops it back and the cursor has its initial value",
			function()
				local initialCursorValue = "foo"
				cursor.current = initialCursorValue

				ReactFiberStack.push(cursor, true, fiber)
				ReactFiberStack.pop(cursor, fiber)
				jestExpect(cursor.current).toBe(initialCursorValue)
			end
		)
	end)
end)
