local p=require("\078\101\120\117\115\085\110\105\116\084\101\115\116\105\110\103")local u=require((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\078\101\120\117\115\080\108\117\103\105\110\070\114\097\109\101\119\111\114\107"))local L=u:GetResource("\066\097\115\101\046\079\118\101\114\114\105\100\097\098\108\101\073\110\100\101\120\073\110\115\116\097\110\099\101")p:RegisterUnitTest("\067\111\110\115\116\114\117\099\116\111\114",function(p)local u=L.new()p:AssertEquals(u.ClassName,"\079\118\101\114\114\105\100\097\098\108\101\073\110\100\101\120\073\110\115\116\097\110\099\101","\067\108\097\115\115 \110\097\109\101 \105\115 \105\110\099\111\114\114\101\099\116\046")end)p:RegisterUnitTest("\095\095\103\101\116\105\110\100\101\120",function(p)local u,i,o={},{},{}local F=L:Extend()F.Table5=true F.Table6=true function F.__getindex(F,p,L)if p=="\084\097\098\108\101\049"then return u elseif p=="\084\097\098\108\101\050"then return i elseif p=="\084\097\098\108\101\051"then return o elseif p=="\084\097\098\108\101\052"then return nil,true elseif p=="\084\097\098\108\101\053"then return nil elseif p=="\084\097\098\108\101\054"then return tostring(L)end end local t=F.new()p:AssertEquals(t.ClassName,"\079\118\101\114\114\105\100\097\098\108\101\073\110\100\101\120\073\110\115\116\097\110\099\101","\067\108\097\115\115 \110\097\109\101 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(t.Table1,u,"\079\118\101\114\114\105\100\101 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(t.Table2,i,"\079\118\101\114\114\105\100\101 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(t.Table3,o,"\079\118\101\114\114\105\100\101 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(t.Table4,nil,"\079\118\101\114\114\105\100\101 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(t.Table5,true,"\079\118\101\114\114\105\100\101 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(t.Table6,"\116\114\117\101","\079\118\101\114\114\105\100\101 \105\115 \105\110\099\111\114\114\101\099\116\046")end)p:RegisterUnitTest("\095\095\115\101\116\105\110\100\101\120",function(p)local u=L:Extend()u.ClassName="\084\101\115\116"function u.__setindex(L,p,u)return"\083\116\114\105\110\103\095"..(tostring(p)..("\095"..tostring(u)))end local i=u.new()i.Index1=1 i.Index2=2 i.Index3=3 p:AssertEquals(i.Index1,"\083\116\114\105\110\103\095\073\110\100\101\120\049\095\049","\079\118\101\114\114\105\100\101 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(i.Index2,"\083\116\114\105\110\103\095\073\110\100\101\120\050\095\050","\079\118\101\114\114\105\100\101 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(i.Index3,"\083\116\114\105\110\103\095\073\110\100\101\120\051\095\051","\079\118\101\114\114\105\100\101 \105\115 \105\110\099\111\114\114\101\099\116\046")i.Index1=4 i.Index2=5 i.Index3=6 p:AssertEquals(i.Index1,"\083\116\114\105\110\103\095\073\110\100\101\120\049\095\052","\079\118\101\114\114\105\100\101 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(i.Index2,"\083\116\114\105\110\103\095\073\110\100\101\120\050\095\053","\079\118\101\114\114\105\100\101 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(i.Index3,"\083\116\114\105\110\103\095\073\110\100\101\120\051\095\054","\079\118\101\114\114\105\100\101 \105\115 \105\110\099\111\114\114\101\099\116\046")end)p:RegisterUnitTest("\095\095\114\097\119\103\101\116",function(p)local u=L:Extend()u.Index1=1 u.Index2=2 function u.__getindex(L,p,u)if p=="\073\110\100\101\120\049"then return 4 elseif p=="\073\110\100\101\120\050"then return nil,true elseif p=="\073\110\100\101\120\051"then return 6 end end local i=u.new()p:AssertEquals(i.Index1,4,"\079\118\101\114\114\105\100\101 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(i.Index2,nil,"\079\118\101\114\114\105\100\101 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(i.Index3,6,"\079\118\101\114\114\105\100\101 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(i:__rawget("\073\110\100\101\120\049"),1,"\082\097\119 \103\101\116 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(i:__rawget("\073\110\100\101\120\050"),2,"\082\097\119 \103\101\116 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(i:__rawget("\073\110\100\101\120\051"),nil,"\082\097\119 \103\101\116 \105\115 \105\110\099\111\114\114\101\099\116\046")end)p:RegisterUnitTest("\069\120\116\101\110\100\105\110\103",function(p)local u=L:Extend()u.TestProperty1="\084\101\115\116 \049"function u.__getindex(i,u,L)if u=="\084\101\115\116\080\114\111\112\101\114\116\121\049"then p:AssertEquals(L,"\084\101\115\116 \049","\067\108\097\115\115 \116\101\115\116 \112\114\111\112\101\114\116\121 \105\115 \105\110\099\111\114\114\101\099\116\046")end end local i=u.new()i.TestProperty2="\084\101\115\116 \050"p:AssertEquals(i.TestProperty1,"\084\101\115\116 \049","\067\108\097\115\115 \112\114\111\112\101\114\116\121 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(i.TestProperty2,"\084\101\115\116 \050","\079\098\106\101\099\116 \112\114\111\112\101\114\116\121 \105\115 \105\110\099\111\114\114\101\099\116\046")end)p:RegisterUnitTest("\082\101\102\101\114\101\110\099\101\087\105\116\104\105\110\071\101\116\105\110\100\101\120",function(p)local u=L:Extend()function u.__getindex(L,p,u)if p=="\084\101\115\116\080\114\111\112\101\114\116\121\049"then return"\084\101\115\116 \049"elseif p=="\084\101\115\116\080\114\111\112\101\114\116\121\050"then return"\084\101\115\116 \050"end end local i=u.new()p:AssertEquals(i.TestProperty1,"\084\101\115\116 \049","\084\101\115\116 \112\114\111\112\101\114\116\121 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(i.TestProperty2,"\084\101\115\116 \050","\084\101\115\116 \112\114\111\112\101\114\116\121 \105\115 \105\110\099\111\114\114\101\099\116\046")end)p:RegisterUnitTest("\083\117\112\101\114\067\108\097\115\115\073\110\105\116\105\097\108\105\122\097\116\105\111\110",function(p)local u=L:Extend()local i=u:Extend()function u.__getindex(L,p,u)if p=="\084\101\115\116\080\114\111\112\101\114\116\121\049"then return"\084\101\115\116 \049"elseif p=="\084\101\115\116\080\114\111\112\101\114\116\121\050"then return"\084\101\115\116 \050"end end function u.__new(u)u:InitializeSuper()p:AssertEquals(u.TestProperty1,"\084\101\115\116 \049","\083\117\112\101\114 \099\108\097\115\115 \112\114\111\112\101\114\116\121 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(u.TestProperty2,"\084\101\115\116 \050","\083\117\112\101\114 \099\108\097\115\115 \112\114\111\112\101\114\116\121 \105\115 \105\110\099\111\114\114\101\099\116\046")end function i.__new(u)u:InitializeSuper()p:AssertEquals(u.TestProperty1,"\084\101\115\116 \049","\067\108\097\115\115 \112\114\111\112\101\114\116\121 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(u.TestProperty2,"\084\101\115\116 \050","\067\108\097\115\115 \112\114\111\112\101\114\116\121 \105\115 \105\110\099\111\114\114\101\099\116\046")end local o=i.new()p:AssertEquals(o.TestProperty1,"\084\101\115\116 \049","\079\098\106\101\099\116 \112\114\111\112\101\114\116\121 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(o.TestProperty2,"\084\101\115\116 \050","\079\098\106\101\099\116 \112\114\111\112\101\114\116\121 \105\115 \105\110\099\111\114\114\101\099\116\046")end)return true
--[[
TheNexusAvenger

Tests the OverridableIndexInstance class.
--]]

local NexusUnitTesting = require("NexusUnitTesting")

local NexusPluginFramework = require(game:GetService("ReplicatedStorage"):WaitForChild("NexusPluginFramework"))
local OverridableIndexInstance = NexusPluginFramework:GetResource("Base.OverridableIndexInstance")



--[[
Test that the constructor works without failing.
--]]
NexusUnitTesting:RegisterUnitTest("Constructor",function(UnitTest)
	local CuT = OverridableIndexInstance.new()
	UnitTest:AssertEquals(CuT.ClassName,"OverridableIndexInstance","Class name is incorrect.")
end)

--[[
Test overriding the __getindex method.
--]]
NexusUnitTesting:RegisterUnitTest("__getindex",function(UnitTest)
	local Table1,Table2,Table3 = {},{},{}
	
	--Create the test class.
	local TestClass = OverridableIndexInstance:Extend()
	TestClass.Table5 = true
	TestClass.Table6 = true
	function TestClass:__getindex(Index,BaseIndex)
		if Index == "Table1" then
			return Table1
		elseif Index == "Table2" then
			return Table2
		elseif Index == "Table3" then
			return Table3
		elseif Index == "Table4" then
			return nil,true
		elseif Index == "Table5" then
			return nil
		elseif Index == "Table6" then
			return tostring(BaseIndex)
		end
	end
	
	--Assert the indexes are correct.
	local CuT = TestClass.new()
	UnitTest:AssertEquals(CuT.ClassName,"OverridableIndexInstance","Class name is incorrect.")
	UnitTest:AssertEquals(CuT.Table1,Table1,"Override is incorrect.")
	UnitTest:AssertEquals(CuT.Table2,Table2,"Override is incorrect.")
	UnitTest:AssertEquals(CuT.Table3,Table3,"Override is incorrect.")
	UnitTest:AssertEquals(CuT.Table4,nil,"Override is incorrect.")
	UnitTest:AssertEquals(CuT.Table5,true,"Override is incorrect.")
	UnitTest:AssertEquals(CuT.Table6,"true","Override is incorrect.")
end)

--[[
Tests the __setindex method.
--]]
NexusUnitTesting:RegisterUnitTest("__setindex",function(UnitTest)
	--Create the test class.
	local TestClass = OverridableIndexInstance:Extend()
	TestClass.ClassName = "Test"
	function TestClass:__setindex(IndexName,NewValue)
		return "String_"..tostring(IndexName).."_"..tostring(NewValue)
	end
	
	--Assert setting indexs are correct.
	local CuT = TestClass.new()
	CuT.Index1 = 1
	CuT.Index2 = 2
	CuT.Index3 = 3
	UnitTest:AssertEquals(CuT.Index1,"String_Index1_1","Override is incorrect.")
	UnitTest:AssertEquals(CuT.Index2,"String_Index2_2","Override is incorrect.")
	UnitTest:AssertEquals(CuT.Index3,"String_Index3_3","Override is incorrect.")
	CuT.Index1 = 4
	CuT.Index2 = 5
	CuT.Index3 = 6
	UnitTest:AssertEquals(CuT.Index1,"String_Index1_4","Override is incorrect.")
	UnitTest:AssertEquals(CuT.Index2,"String_Index2_5","Override is incorrect.")
	UnitTest:AssertEquals(CuT.Index3,"String_Index3_6","Override is incorrect.")
end)

--[[
Tests the __rawget method.
--]]
NexusUnitTesting:RegisterUnitTest("__rawget",function(UnitTest)
	--Create the test class.
	local TestClass = OverridableIndexInstance:Extend()
	TestClass.Index1 = 1
	TestClass.Index2 = 2
	function TestClass:__getindex(Index,BaseIndex)
		if Index == "Index1" then
			return 4
		elseif Index == "Index2" then
			return nil,true
		elseif Index == "Index3" then
			return 6
		end
	end
	
	--Assert the indexes are correct.
	local CuT = TestClass.new()
	UnitTest:AssertEquals(CuT.Index1,4,"Override is incorrect.")
	UnitTest:AssertEquals(CuT.Index2,nil,"Override is incorrect.")
	UnitTest:AssertEquals(CuT.Index3,6,"Override is incorrect.")
	UnitTest:AssertEquals(CuT:__rawget("Index1"),1,"Raw get is incorrect.")
	UnitTest:AssertEquals(CuT:__rawget("Index2"),2,"Raw get is incorrect.")
	UnitTest:AssertEquals(CuT:__rawget("Index3"),nil,"Raw get is incorrect.")
end)

--[[
Tests extending the OverridableIndexInstance.
--]]
NexusUnitTesting:RegisterUnitTest("Extending",function(UnitTest)
	--Extend the class.
	local TestClass = OverridableIndexInstance:Extend()
	TestClass.TestProperty1 = "Test 1"
	
	function TestClass:__getindex(Index,BaseIndex)
		if Index == "TestProperty1" then
			UnitTest:AssertEquals(BaseIndex,"Test 1","Class test property is incorrect.")
		end
	end
	
	--Create the component under testing.
	local CuT = TestClass.new()
	CuT.TestProperty2 = "Test 2"
	UnitTest:AssertEquals(CuT.TestProperty1,"Test 1","Class property is incorrect.")
	UnitTest:AssertEquals(CuT.TestProperty2,"Test 2","Object property is incorrect.")
end)

--[[
Tests referencing self in __getindex.
--]]
NexusUnitTesting:RegisterUnitTest("ReferenceWithinGetindex",function(UnitTest)
	--Extend the class.
	local TextClass = OverridableIndexInstance:Extend()
	
	function TextClass:__getindex(IndexName,OriginalReturn)
		if IndexName == "TestProperty1" then
			return "Test 1"
		elseif IndexName == "TestProperty2" then
			return "Test 2"
		end
	end
	
	--Create the component under testing.
	local CuT = TextClass.new()
	UnitTest:AssertEquals(CuT.TestProperty1,"Test 1","Test property is incorrect.")
	UnitTest:AssertEquals(CuT.TestProperty2,"Test 2","Test property is incorrect.")
end)

--[[
Tests extending with super class initializing.
--]]
NexusUnitTesting:RegisterUnitTest("SuperClassInitialization",function(UnitTest)
	--Extend the class.
	local TestClass1 = OverridableIndexInstance:Extend()
	local TestClass2 = TestClass1:Extend()
	
	function TestClass1:__getindex(Index,BaseIndex)
		if Index == "TestProperty1" then
			return "Test 1"
		elseif Index == "TestProperty2" then
			return "Test 2"
		end
	end
	
	function TestClass1:__new()
		self:InitializeSuper()
		UnitTest:AssertEquals(self.TestProperty1,"Test 1","Super class property is incorrect.")
		UnitTest:AssertEquals(self.TestProperty2,"Test 2","Super class property is incorrect.")
	end
	
	function TestClass2:__new()
		self:InitializeSuper()
		UnitTest:AssertEquals(self.TestProperty1,"Test 1","Class property is incorrect.")
		UnitTest:AssertEquals(self.TestProperty2,"Test 2","Class property is incorrect.")
	end
	
	--Create the component under testing.
	local CuT = TestClass2.new()
	UnitTest:AssertEquals(CuT.TestProperty1,"Test 1","Object property is incorrect.")
	UnitTest:AssertEquals(CuT.TestProperty2,"Test 2","Object property is incorrect.")
end)



return true