vrtc / chorus (public) (License: CC0) (since 2023-08-12) (hash sha1)
World of Warcraft add-on stub. The overall goal is to create a specialized raid frame.

/src/ChorusTest.lua (b3107a50589f57faea7690e1f3012af20aa726c7) (6222 bytes) (mode 100644) (type blob)

local Chorus = Chorus

--[[ NOTE SavedVariables do not work for this since they are loaded after all
of the scripts and after all of the API was shadowed. Testing module must be
loaded __before__ shadowing. See each individual script for details. ]]--

--[[ To enable testing mode uncomment the following line and `/run ReloadUI()`. ]]--

--[[ Chorus.debugFlag = true ]]--

if not Chorus.debugFlag then
	Chorus.test = {}
	return
end

if DEFAULT_CHAT_FRAME then
	DEFAULT_CHAT_FRAME:AddMessage(date('%X') .. ' ChorusTest.lua: mock testing mode enabled')
end

local t = {
	focus = {},
	party1 = {
		UnitIsPlayer = true,
		UnitClass = {'Warrior', 'WARRIOR'},
		UnitPowerType = {1, 'RAGE'},
		UnitPower = 13,
		UnitPowerMax = 100,
	},
	party1target = {},
	party2 = {
		UnitIsPlayer = true,
		UnitClass = {'Priest', 'PRIEST'},
		UnitPowerType = {0, 'MANA'},
	},
	party2target = {},
	party3 = {
		UnitIsPlayer = true,
		UnitClass = {'Warlock', 'WARLOCK'},
		UnitPowerType = {0, 'MANA'},
	},
	party3target = {},
	party4 = {
		UnitIsPlayer = true,
		UnitClass = {'Mage', 'MAGE'},
		UnitPowerType = {0, 'MANA'},
		UnitIsDead = true,
		UnitHealth = 0
	},
	party4target = {},
	partypet1 = {},
	partypet2 = {},
	partypet3 = {},
	partypet4 = {},
	pet = {},
	player = {
		UnitIsPlayer = true,
		UnitClass = {'Paladin', 'PALADIN'},
		UnitPowerType = {0, 'MANA'},
	},
	target = {},
}

local function recordGet(u, key)
	local r = t[u]
	if r then
		local e = r[key]
		if e and 'table' == type(e) then
			return unpack(e)
		else
			return e
		end
	end
	return
end

local function GetNumPartyMembers_Mock()
	return 4
end

local function UnitAura_Mock(u, i, filter)
	if u and i > 36 then
		return nil
	end

	if 'HARMFUL' == string.match(filter, 'HARMFUL') then
		return 'Poison',
			'',
			'Interface\\Icons\\Spell_Nature_CorrosiveBreath',
			0,
			'Poison',
			30,
			GetTime(),
			nil,
			nil,
			nil,
			744
	else
		return 'Blessing of Wisdom',
			'Rank 1',
			'Interface\\Icons\\Spell_Holy_SealOfWisdom',
			0,
			'Magic',
			600,
			GetTime(),
			'player',
			nil,
			1,
			19742
	end
end

local function UnitCastingInfo_Mock()
	--[[-- @todo Add UnitCastingInfo mock.
	]]
	return
end

local function UnitChannelInfo_Mock()
	--[[-- @todo Add UnitChannelInfo mock.
	]]
	return
end

local function UnitClass_Mock(u)
	return recordGet(u, 'UnitClass')
end

local function UnitExists_Mock(u)
	if 'none' == u then
		return false
	end
	return true
end

local function UnitHealth_Mock(u)
	local r = recordGet(u, 'UnitHealth')
	if r then
		return r
	end
	return math.random(1, 1000 * 1000)
end

local function UnitHealthMax_Mock(u)
	local r = recordGet(u, 'UnitHealthMax')
	if r then
		return r
	end
	return 1000 * 1000
end

local function UnitInParty_Mock(u)
	return tContains({'player', 'party1', 'party2', 'party3', 'party4',}, u)
end

local function UnitInRaid_Mock(u)
	return 'raid' == string.match(u, 'raid')
end

local function UnitInRange_Mock()
	return true
end

local function UnitIsConnected_Mock(u)
	if 'none' == u then
		return false
	end
	return true
end

local function UnitIsCorpse_Mock(u)
	return recordGet(u, 'UnitIsCorpse') or false
end

local function UnitIsDead_Mock(u)
	return recordGet(u, 'UnitIsDead') or false
end

local function UnitIsFriend_Mock(u)
	if 'target' == u or 'focus' == u then
		return false
	elseif string.len(u) > string.len('target') and 'target' == string.match(u, 'target') then
		return false
	else
		return true
	end
end

local function UnitIsGhost_Mock()
	return false
end

local function UnitIsPlayer_Mock(u)
	if 'target' == u or 'focus' == u or  'pet' == u then
		return false
	elseif string.len(u) > string.len('pet') and 'pet' == string.match(u, 'pet') then
		return false
	elseif string.len(u) > string.len('target') and 'target' == string.match(u, 'target') then
		return false
	else
		return true
	end
end

local function UnitIsUnit_Mock(u0, u1)
	return u0 == u1
end

local function UnitLevel_Mock(u)
	local r = recordGet(u, 'UnitLevel')
	if r then
		return r
	end

	return 81
end

local function UnitName_Mock(u)
	return string.upper(string.sub(u, 1, 1)) .. string.lower(string.sub(u, 2, string.len(u)))
end

local function UnitPower_Mock(u)
	local r = recordGet(u, 'UnitPower')
	if r then
		return recordGet(u, 'UnitPower')
	end
	return math.random(1, 1000 * 1000)
end

local function UnitPowerMax_Mock(u)
	local r = recordGet(u, 'UnitPowerMax')
	if r then
		return recordGet(u, 'UnitPowerMax')
	end
	return 1000 * 1000
end

local function UnitPowerType_Mock(u)
	local r = recordGet(u, 'UnitPowerType')
	if r then
		return recordGet(u, 'UnitPowerType')
	end
	return 0, 'MANA'
end

local function RegisterUnitWatch_Mock(self)
	self:Show()
end

local function SecureButton_GetUnit_Mock(self)
	local i = 0
	local f = self
	local u = nil
	while (i < 8192) do
		u = f:GetAttribute('unit')
		if u ~= nil and 'string' == type(u) then
			break
		elseif f:GetAttribute('useparent-unit') or f:GetAttribute('useparent*') then
			local p = f:GetParent()
			if p then
				f = p
			else
				break
			end
		else
			break
		end
		i = i + 1
	end

	return u
end

local function UnregisterUnitWatch_Mock()
	--[[ call DoNothing() ]]--
	return
end

local function UnitGroupRolesAssigned_Mock()
	return 'DAMAGER'
end

Chorus.test = {
	GetNumPartyMembers = GetNumPartyMembers_Mock,
	UnitAura = UnitAura_Mock,
	UnitCastingInfo = UnitCastingInfo_Mock,
	UnitChannelInfo = UnitChannelInfo_Mock,
	UnitClass = UnitClass_Mock,
	UnitExists = UnitExists_Mock,
	UnitGroupRolesAssigned = UnitGroupRolesAssigned_Mock,
	UnitHealth = UnitHealth_Mock,
	UnitHealthMax = UnitHealthMax_Mock,
	UnitInParty = UnitInParty_Mock,
	UnitInRaid = UnitInRaid_Mock,
	UnitInRange = UnitInRange_Mock,
	UnitIsConnected = UnitIsConnected_Mock,
	UnitIsCorpse = UnitIsCorpse_Mock,
	UnitIsDead = UnitIsDead_Mock,
	UnitIsFriend = UnitIsFriend_Mock,
	UnitIsGhost = UnitIsGhost_Mock,
	UnitIsPlayer = UnitIsPlayer_Mock,
	UnitIsUnit = UnitIsUnit_Mock,
	UnitLevel = UnitLevel_Mock,
	UnitName = UnitName_Mock,
	UnitPower = UnitPower_Mock,
	UnitPowerMax = UnitPowerMax_Mock,
	UnitPowerType = UnitPowerType_Mock,

	RegisterUnitWatch = RegisterUnitWatch_Mock,
	SecureButton_GetUnit = SecureButton_GetUnit_Mock,
	UnregisterUnitWatch = UnregisterUnitWatch_Mock,
}


Mode Type Size Ref File
100644 blob 35 5c40e6e2862d70b5c51c326a13073a4012ac05c7 .gitignore
100644 blob 3606 f73da473168d1897963fd2e32d89841ca0461ec0 README.adoc
040000 tree - 271296b4bafcaa151458a0192fd313641ca9b409 bin
100644 blob 228 c7dd24afa7d5c2375ff60a91c73623a304b808f9 chorus.toc
040000 tree - 99c99c3cbc641f8954a5be291e61681cb5e74629 conf
040000 tree - efa7258757edf7b888ea13c215e14b497fef8a16 doc
100644 blob 2391 1b0ca1bc25f74a34476360e5a8f14e28767b204e makefile
040000 tree - b9d3ea9d61b99ee71b5fcdbc6b18843df20c8c3c src
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/vrtc/chorus

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/vrtc/chorus

Clone this repository using git:
git clone git://git.rocketgit.com/user/vrtc/chorus

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main