local l=script.Parent.Parent local r=require(l)local i=require(l["\082\101\103\105\115\116\114\121\046\103\108\111\098\097\108"])local y=l.Parent local P=require(y.Dev.JestGlobals)local g=P.expect local B=P.describe local C=P.it local U=P.beforeEach B("\078\101\119 \115\121\109\098\111\108\115",function()C("\115\104\111\117\108\100 \103\105\118\101 \097\110 \111\112\097\113\117\101 \111\098\106\101\099\116",function()local l=r("\102\111\111");(g(typeof(l))).toEqual("\117\115\101\114\100\097\116\097")end)C("\115\104\111\117\108\100 \099\111\101\114\099\101 \116\111 \097 \100\101\102\097\117\108\116 \110\097\109\101 \105\102 \110\111\110\101 \105\115 \103\105\118\101\110",function()local l=r();(g(tostring(l))).toEqual("\083\121\109\098\111\108\040\041")end)C("\115\104\111\117\108\100 \099\111\101\114\099\101 \116\111 \116\104\101 \103\105\118\101\110 \110\097\109\101",function()local l=r("\102\111\111");(g(tostring(l))).toEqual("\083\121\109\098\111\108\040\102\111\111\041")end)C("\115\104\111\117\108\100 \098\101 \117\110\105\113\117\101 \119\104\101\110 \099\111\110\115\116\114\117\099\116\101\100",function()local l=r("\097\098\099")local i=r("\097\098\099");(g(l)).never.toEqual(i)end)end)B("\071\108\111\098\097\108 \114\101\103\105\115\116\114\121",function()U(function()i.__clear()end)C("\115\104\111\117\108\100 \114\101\116\117\114\110 \097 \115\121\109\098\111\108 \102\111\114 \105\116\101\109\115 \114\101\102\101\114\101\110\099\101\100 \102\111\114 \116\104\101 \102\105\114\115\116 \116\105\109\101",function()local l=r.for_("\102\111\111")local i=r.for_("\098\097\114");(g(typeof(l))).toEqual(typeof(r()));(g(tostring(l))).toEqual("\083\121\109\098\111\108\040\102\111\111\041");(g(typeof(i))).toEqual(typeof(r()));(g(tostring(i))).toEqual("\083\121\109\098\111\108\040\098\097\114\041")end)C("\115\104\111\117\108\100 \114\101\116\117\114\110 \116\104\101 \115\097\109\101 \115\121\109\098\111\108 \111\098\106\101\099\116 \102\111\114 \116\104\101 \115\097\109\101 \115\116\114\105\110\103",function()local l=r.for_("\102\111\111")local i=r.for_("\102\111\111");(g(l)).toEqual(i)end)end)
--!strict
--[[
	Tests in this file are from the Symbol code in Roact:
	https://github.com/Roblox/roact/blob/v1.3.1/src/Symbol.spec.lua

	and from interpretation of this spec:
	https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol
]]
local SymbolModule = script.Parent.Parent
local Symbol = require(SymbolModule)
local GlobalRegistry = require(SymbolModule["Registry.global"])

local Packages = SymbolModule.Parent
local JestGlobals = require(Packages.Dev.JestGlobals)
local expect = JestGlobals.expect
local describe = JestGlobals.describe
local it = JestGlobals.it
local beforeEach = JestGlobals.beforeEach

describe("New symbols", function()
	it("should give an opaque object", function()
		local symbol = Symbol("foo")

		expect(typeof(symbol)).toEqual("userdata")
	end)

	it("should coerce to a default name if none is given", function()
		local symbol = Symbol()

		expect(tostring(symbol)).toEqual("Symbol()")
	end)

	it("should coerce to the given name", function()
		local symbol = Symbol("foo")

		expect(tostring(symbol)).toEqual("Symbol(foo)")
	end)

	it("should be unique when constructed", function()
		local symbolA = Symbol("abc")
		local symbolB = Symbol("abc")

		expect(symbolA).never.toEqual(symbolB)
	end)
end)

describe("Global registry", function()
	beforeEach(function()
		GlobalRegistry.__clear()
	end)

	it("should return a symbol for items referenced for the first time", function()
		local fooSymbol = Symbol.for_("foo")
		local barSymbol = Symbol.for_("bar")

		expect(typeof(fooSymbol)).toEqual(typeof(Symbol()))
		expect(tostring(fooSymbol)).toEqual("Symbol(foo)")
		expect(typeof(barSymbol)).toEqual(typeof(Symbol()))
		expect(tostring(barSymbol)).toEqual("Symbol(bar)")
	end)

	it("should return the same symbol object for the same string", function()
		local fooSymbol1 = Symbol.for_("foo")
		local fooSymbol2 = Symbol.for_("foo")

		expect(fooSymbol1).toEqual(fooSymbol2)
	end)
end)
