Skip to content

Commit

Permalink
test: add BLOCK test
Browse files Browse the repository at this point in the history
  • Loading branch information
BigJk committed Dec 25, 2023
1 parent 3eb8882 commit 5c4c91f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
5 changes: 4 additions & 1 deletion assets/scripts/artifacts/deflector_shield.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ register_artifact("DEFLECTOR_SHIELD", {
},
test = function()
add_actor_by_enemy("DUMMY")
return assert_chain({ assert_status_effect_count(1), assert_status_effect("BLOCK", 8) })
return assert_chain({
function () return assert_status_effect_count(1) end,
function () return assert_status_effect("BLOCK", 8) end
})
end
});
13 changes: 8 additions & 5 deletions assets/scripts/cards/shield_bash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,28 @@ register_card("SHIELD_BASH", {
end
},
test = function()
dummy = add_actor_by_enemy("DUMMY")
cards = get_cards(PLAYER_ID)
local dummy = add_actor_by_enemy("DUMMY")
local cards = get_cards(PLAYER_ID)

-- Check if the card is in the player's hand
if not cards[1] then
return "Card not in hand"
end

card = get_card_instance(cards[1])
local card = get_card_instance(cards[1])
if card.type_id ~= "SHIELD_BASH" then
return "Card has wrong type: " .. card.type_id
end

cast_card(cards[1], dummy)

if get_actor(dummy).hp ~= 96 then
return "Expected 96 health, got " .. get_actor_health(dummy)
return "Expected 96 health, got " .. get_actor(dummy).hp
end

return assert_chain({ assert_status_effect_count(1), assert_status_effect("BLOCK", 4) })
return assert_chain({
function () assert_status_effect_count(1) end,
function () assert_status_effect("BLOCK", 4) end
})
end
})
20 changes: 19 additions & 1 deletion assets/scripts/status_effects/block.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,23 @@ register_status_effect("BLOCK", {
end
return ctx.damage
end
}
},
test = function()
return assert_chain({
function() return assert_status_effect_count(1) end,
function() return assert_status_effect("BLOCK", 1) end,
function ()
local dummy = add_actor_by_enemy("DUMMY")
local damage = deal_damage(dummy, PLAYER_ID, 1)
if damage ~= 0 then
return "Expected 0 damage, got " .. damage
end

damage = deal_damage(dummy, PLAYER_ID, 2)
if damage ~= 2 then
return "Expected 2 damage, got " .. damage
end
end
})
end
})
2 changes: 1 addition & 1 deletion cmd/internal/tester/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ func main() {
for _, statusEffect := range resources.StatusEffects {
if statusEffect.Test != nil {
setupClean(session)
session.GiveStatusEffect(statusEffect.ID, game.PlayerActorID, 1)
setupFight(session)
session.GiveStatusEffect(statusEffect.ID, game.PlayerActorID, 1)

res, err := statusEffect.Test.Call()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/tester/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func TestGame(t *testing.T) {
for _, statusEffect := range resources.StatusEffects {
if statusEffect.Test != nil {
setupClean(session)
session.GiveStatusEffect(statusEffect.ID, game.PlayerActorID, 1)
setupFight(session)
session.GiveStatusEffect(statusEffect.ID, game.PlayerActorID, 1)

t.Run(fmt.Sprintf("StatusEffect:%s", statusEffect.ID), func(t *testing.T) {
res, err := statusEffect.Test.Call()
Expand Down

0 comments on commit 5c4c91f

Please sign in to comment.