43 lines
2.2 KiB
Python
43 lines
2.2 KiB
Python
"""Run native dispatch and the actual OctoAux addon event handler together."""
|
|
import pathlib, subprocess, sys, tempfile
|
|
root = pathlib.Path(__file__).resolve().parents[1]
|
|
subprocess.run([sys.argv[1]], check=True)
|
|
source = (root / 'client_addons/aux-addon/compat.lua').read_text()
|
|
start = source.index("events:SetScript('OnEvent', function")
|
|
end = source.index('\nend)', start) + len('\nend)')
|
|
handler = source[start:end]
|
|
setup = r'''
|
|
local PREFIX = 'OctoAux'
|
|
local notices, messages, updates = {}, {}, 0
|
|
local pages = {bidder={rows={{id=77}},total=1}, owner={rows={{id=88}},total=1}}
|
|
local incoming = {bidder={rows={{id=77}}}}
|
|
local waiting = {bidder={page={rows={{id=77}}}}}
|
|
local current = incoming.bidder
|
|
local function commit(k,p) pages[k]=p updates=updates+1 end
|
|
local function system_message(s) notices[#notices+1]=s end
|
|
local G={DEFAULT_CHAT_FRAME={AddMessage=function(_,s)messages[#messages+1]=s end}}
|
|
local function GII(link) assert(link=='item:2589:0:0:0:0:0:-1:0');return 'Linen Cloth' end
|
|
local events={SetScript=function(self,_,f)self.handler=f end}
|
|
'''
|
|
checks = r'''
|
|
local function deliver(prefix, text)events.handler(nil,nil,prefix,text)end
|
|
for _, text in ipairs({'D;', 'D;0;2589;0','D;77;0;0','D;77;2589;-1', 'D;77;2589;4294967296','D;77;2589;0;extra'})do
|
|
deliver('OctoAux',text)
|
|
assert(updates==0 and #notices==0 and #pages.bidder.rows==1 and current)
|
|
end
|
|
deliver('Foreign','D;77;2589;4294967295');assert(updates==0)
|
|
deliver('OctoAux','D;77;2589;4294967295')
|
|
assert(updates==1 and #pages.bidder.rows==0 and pages.bidder.total==0)
|
|
assert(incoming.bidder==nil and waiting.bidder==nil and current==nil)
|
|
assert(pages.owner.rows[1].id==88)
|
|
local expected='Your auction of Linen Cloth has been cancelled by the seller.'
|
|
assert(notices[1]==expected and messages[1]==expected)
|
|
GII=function()return nil end
|
|
deliver('OctoAux','D;78;2590;0')
|
|
assert(notices[2]=='Your auction of item 2590 has been cancelled by the seller.')
|
|
print('PASS OctoAux cancellation: validation, visible/pending invalidation, owner preservation, source message, uncached name')
|
|
'''
|
|
with tempfile.TemporaryDirectory(prefix='auction-cancel-') as d:
|
|
fixture=pathlib.Path(d)/'fixture.lua';fixture.write_text(setup+handler+checks)
|
|
subprocess.run([sys.argv[2], str(fixture)], check=True)
|