local G=(require("\115\117\112\112\111\114\116\046\102\097\099\116\111\114\121")).create local z=require("\105\110\118\111\107\097\116\105\111\110\046\100\111\116\097\050\046\085\110\105\116")local f=require("\105\110\118\111\107\097\116\105\111\110\046\100\111\116\097\050\046\065\098\105\108\105\116\121")local u=require("\105\110\118\111\107\097\116\105\111\110\046\100\111\116\097\050\046\068\097\109\097\103\101\073\110\115\116\097\110\099\101")local p=require("\105\110\118\111\107\097\116\105\111\110\046\099\111\110\115\116\046\105\110\118\111\107\101\114")describe("\100\111\116\097\050\046\068\097\109\097\103\101\073\110\115\116\097\110\099\101",function()describe("\099\111\110\115\116\114\117\099\116\111\114",function()it("\105\110\105\116\105\097\108\105\122\101\115 \097\116\116\114\105\098\117\116\101\115",function()local p=G("\100\111\116\097\095\104\101\114\111\095\105\110\118\111\107\101\114")local q=z(p)local c=G("\100\111\116\097\095\104\101\114\111",{name="\110\112\099\095\100\111\116\097\095\104\101\114\111\095\097\120\101"})local w=z(c)local g=G("\100\111\116\097\095\097\098\105\108\105\116\121",{name="\097\120\101\095\099\117\108\108\105\110\103\095\098\108\097\100\101"})local Q=f(g)local T=u(q,666,w,Q)assert.equal(q,T.victim)assert.equal(666,T.amount)assert.equal(w,T.attacker)assert.equal(Q,T.inflictor)assert.equal(DOTA_DAMAGE_CATEGORY_SPELL,T.category)end)end)describe("\035\086\105\099\116\105\109\078\097\109\101",function()it("\114\101\116\117\114\110\115 \116\104\101 \118\105\099\116\105\109\'\115 \101\110\116\105\116\121 \110\097\109\101",function()local q=G("\100\111\116\097\095\104\101\114\111\095\105\110\118\111\107\101\114")local c=z(q)local w=G("\100\111\116\097\095\104\101\114\111",{name="\110\112\099\095\100\111\116\097\095\104\101\114\111\095\097\120\101"})local g=z(w)local Q=G("\100\111\116\097\095\097\098\105\108\105\116\121",{name="\097\120\101\095\099\117\108\108\105\110\103\095\098\108\097\100\101"})local T=f(Q)local j=u(c,666,g,T)assert.equal(p.UNIT_NAME,j:VictimName())end)end)describe("\035\065\116\116\097\099\107\101\114\078\097\109\101",function()it("\114\101\116\117\114\110\115 \116\104\101 \097\116\116\097\099\107\101\114\'\115 \101\110\116\105\116\121 \110\097\109\101",function()local p=G("\100\111\116\097\095\104\101\114\111\095\105\110\118\111\107\101\114")local q=z(p)local c=u(q,666,nil,nil)assert.is_nil(c:AttackerName())local w=G("\100\111\116\097\095\104\101\114\111",{name="\110\112\099\095\100\111\116\097\095\104\101\114\111\095\097\120\101"})local g=z(w)local Q=G("\100\111\116\097\095\097\098\105\108\105\116\121",{name="\097\120\101\095\099\117\108\108\105\110\103\095\098\108\097\100\101"})local T=f(Q)c=u(q,666,g,T)assert.equal("\110\112\099\095\100\111\116\097\095\104\101\114\111\095\097\120\101",c:AttackerName())end)end)describe("\035\065\116\116\097\099\107\101\114\080\108\097\121\101\114\079\119\110\101\114",function()it("\114\101\116\117\114\110\115 \116\104\101 \097\116\116\097\099\107\101\114\'\115 \112\108\097\121\101\114 \101\110\116\105\116\121",function()local p=G("\100\111\116\097\095\104\101\114\111\095\105\110\118\111\107\101\114")local q=z(p)local c=u(q,666,nil,nil)assert.is_nil(c:AttackerPlayerOwner())local w=G("\100\111\116\097\095\112\108\097\121\101\114")local g=G("\100\111\116\097\095\104\101\114\111",{name="\110\112\099\095\100\111\116\097\095\104\101\114\111\095\097\120\101";playerOwner=w})local Q=z(g)local T=G("\100\111\116\097\095\097\098\105\108\105\116\121",{name="\097\120\101\095\099\117\108\108\105\110\103\095\098\108\097\100\101"})local j=f(T)c=u(q,666,Q,j)assert.equal(w,c:AttackerPlayerOwner())end)end)describe("\035\073\110\102\108\105\099\116\111\114\078\097\109\101",function()it("\114\101\116\117\114\110\115 \116\104\101 \105\110\102\108\105\099\116\111\114\'\115 \097\098\105\108\105\116\121 \110\097\109\101",function()local p=G("\100\111\116\097\095\104\101\114\111\095\105\110\118\111\107\101\114")local q=z(p)local c=u(q,666,nil,nil)assert.is_nil(c:InflictorName())local w=G("\100\111\116\097\095\104\101\114\111",{name="\110\112\099\095\100\111\116\097\095\104\101\114\111\095\097\120\101"})local g=z(w)local Q=G("\100\111\116\097\095\097\098\105\108\105\116\121",{name="\097\120\101\095\099\117\108\108\105\110\103\095\098\108\097\100\101"})local T=f(Q)c=u(q,666,g,T)assert.equal("\097\120\101\095\099\117\108\108\105\110\103\095\098\108\097\100\101",c:InflictorName())end)end)end)
local create = require("support.factory").create

local Unit = require("invokation.dota2.Unit")
local Ability = require("invokation.dota2.Ability")
local DamageInstance = require("invokation.dota2.DamageInstance")

local INVOKER = require("invokation.const.invoker")

describe("dota2.DamageInstance", function()
  describe("constructor", function()
    it("initializes attributes", function()
      local victimHero = create("dota_hero_invoker")
      local victim = Unit(victimHero)
      local attackerHero = create("dota_hero", { name = "npc_dota_hero_axe" })
      local attacker = Unit(attackerHero)
      local inflictorAbility = create("dota_ability", { name = "axe_culling_blade" })
      local inflictor = Ability(inflictorAbility)
      local dmg = DamageInstance(victim, 666, attacker, inflictor)

      assert.equal(victim, dmg.victim)
      assert.equal(666, dmg.amount)
      assert.equal(attacker, dmg.attacker)
      assert.equal(inflictor, dmg.inflictor)
      assert.equal(DOTA_DAMAGE_CATEGORY_SPELL, dmg.category)
    end)
  end)

  describe("#VictimName", function()
    it("returns the victim's entity name", function()
      local victimHero = create("dota_hero_invoker")
      local victim = Unit(victimHero)
      local attackerHero = create("dota_hero", { name = "npc_dota_hero_axe" })
      local attacker = Unit(attackerHero)
      local inflictorAbility = create("dota_ability", { name = "axe_culling_blade" })
      local inflictor = Ability(inflictorAbility)
      local dmg = DamageInstance(victim, 666, attacker, inflictor)

      assert.equal(INVOKER.UNIT_NAME, dmg:VictimName())
    end)
  end)

  describe("#AttackerName", function()
    it("returns the attacker's entity name", function()
      local victimHero = create("dota_hero_invoker")
      local victim = Unit(victimHero)
      local dmg = DamageInstance(victim, 666, nil, nil)

      assert.is_nil(dmg:AttackerName())

      local attackerHero = create("dota_hero", { name = "npc_dota_hero_axe" })
      local attacker = Unit(attackerHero)
      local inflictorAbility = create("dota_ability", { name = "axe_culling_blade" })
      local inflictor = Ability(inflictorAbility)

      dmg = DamageInstance(victim, 666, attacker, inflictor)

      assert.equal("npc_dota_hero_axe", dmg:AttackerName())
    end)
  end)

  describe("#AttackerPlayerOwner", function()
    it("returns the attacker's player entity", function()
      local victimHero = create("dota_hero_invoker")
      local victim = Unit(victimHero)
      local dmg = DamageInstance(victim, 666, nil, nil)

      assert.is_nil(dmg:AttackerPlayerOwner())

      local player = create("dota_player")
      local attackerHero = create("dota_hero", { name = "npc_dota_hero_axe", playerOwner = player })
      local attacker = Unit(attackerHero)
      local inflictorAbility = create("dota_ability", { name = "axe_culling_blade" })
      local inflictor = Ability(inflictorAbility)

      dmg = DamageInstance(victim, 666, attacker, inflictor)

      assert.equal(player, dmg:AttackerPlayerOwner())
    end)
  end)

  describe("#InflictorName", function()
    it("returns the inflictor's ability name", function()
      local victimHero = create("dota_hero_invoker")
      local victim = Unit(victimHero)
      local dmg = DamageInstance(victim, 666, nil, nil)

      assert.is_nil(dmg:InflictorName())

      local attackerHero = create("dota_hero", { name = "npc_dota_hero_axe" })
      local attacker = Unit(attackerHero)
      local inflictorAbility = create("dota_ability", { name = "axe_culling_blade" })
      local inflictor = Ability(inflictorAbility)

      dmg = DamageInstance(victim, 666, attacker, inflictor)

      assert.equal("axe_culling_blade", dmg:InflictorName())
    end)
  end)
end)
