local U=import("\046\047\099\114\101\097\116\101\069\110\117\109")local N=import("\046\047\102\117\110\099\116\105\111\110\115\047\116\121\112\101\111\102")describe("\099\114\101\097\116\101\069\110\117\109",function()it("\115\104\111\117\108\100 \115\116\114\105\110\103\105\102\121 \097\115 \116\104\101 \105\110\112\117\116 \110\097\109\101",function()local N=U("\070\111\111",{})assert.equal(tostring(N),"\070\111\111")end)it("\115\104\111\117\108\100 \104\097\118\101 \116\121\112\101\111\102 \'\069\110\117\109\'",function()local P=U("\066\097\114",{})assert.equal(N(P),"\069\110\117\109")end)it("\115\104\111\117\108\100 \104\097\118\101 \109\101\109\098\101\114\115 \102\111\114 \101\097\099\104 \105\110\112\117\116",function()local P={a=1,b=2}local F=U("\066\097\114",P)for U,P in pairs(P)do local s=F[U]assert.equal(N(s),"\069\110\117\109\073\116\101\109")assert.equal(tostring(s),string.format("\069\110\117\109\046\066\097\114\046\037\115",U))assert.equal(s.Value,P)assert.equal(s.Name,U)assert.equal(s.EnumType,F)end end)it("\115\104\111\117\108\100 \116\104\114\111\119 \119\104\101\110 \097\099\099\101\115\115\105\110\103 \105\110\118\097\108\105\100 \109\101\109\098\101\114\115",function()local N=U("\070\114\111\098\117\108\111\110",{})assert.has.errors(function()tostring(N.whatever)end)end)it("\115\104\111\117\108\100 \116\104\114\111\119 \119\104\101\110 \097\099\099\101\115\115\105\110\103 \105\110\118\097\108\105\100 \109\101\109\098\101\114\115 \111\102 \097\110 \101\110\117\109 \118\097\114\105\097\110\116",function()local N=U("\077\117\110\103\117\108\097\116\105\111\110",{foo=5})local P=N.foo assert.has.errors(function()tostring(P.something)end)end)end)
local createEnum = import("./createEnum")
local typeof = import("./functions/typeof")

describe("createEnum", function()
	it("should stringify as the input name", function()
		local enum = createEnum("Foo", {})

		assert.equal(tostring(enum), "Foo")
	end)

	it("should have typeof 'Enum'", function()
		local enum = createEnum("Bar", {})

		assert.equal(typeof(enum), "Enum")
	end)

	it("should have members for each input", function()
		local values = {
			a = 1,
			b = 2,
		}

		local enum = createEnum("Bar", values)

		for name, value in pairs(values) do
			local enumValue = enum[name]

			assert.equal(typeof(enumValue), "EnumItem")
			assert.equal(tostring(enumValue), string.format("Enum.Bar.%s", name))
			assert.equal(enumValue.Value, value)
			assert.equal(enumValue.Name, name)
			assert.equal(enumValue.EnumType, enum)
		end
	end)

	it("should throw when accessing invalid members", function()
		local enum = createEnum("Frobulon", {})

		assert.has.errors(function()
			tostring(enum.whatever)
		end)
	end)

	it("should throw when accessing invalid members of an enum variant", function()
		local enum = createEnum("Mungulation", {
			foo = 5,
		})

		local variant = enum.foo

		assert.has.errors(function()
			tostring(variant.something)
		end)
	end)
end)