Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
the events-test_filter_attack_type test verify what [filter_attack]type= can check type of damage same if modified by [damage]replacement/alternative_type.

The second verify [filter_weapon]type= called by a special(or leadership/resistance abilities) can ckeck type without modofication by [damage] for don't risk infinite recursion.
  • Loading branch information
newfrenchy83 committed Nov 2, 2023
1 parent 11750c2 commit 6fd29f0
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# wmllint: no translatables

#####
# API(s) being tested: [event][filter_attack]type=
##
# Actions:
# Give Alice an ability that adds a damage special with addition of arcnae type to all of his weapons.
# Define events that use filter_attack matching Alice's arcane type.
# Have Alice attack Bob.
##
# Expected end state:
# An event triggers when Alice attacks during side 1's turn because type=arcane detected.
#####
{GENERIC_UNIT_TEST event_test_filter_attack_type (
[event]
name=start
[object]
silent=yes
[effect]
apply_to=new_ability
[abilities]
[damage]
id=test_arcane_damage
alternative_type=arcane
[/damage]
[/abilities]
[/effect]
[filter]
id=alice
[/filter]
[/object]
[modify_unit]
[filter]
[/filter]
# Make sure they don't die during the attacks
[status]
invulnerable=yes
[/status]
[/modify_unit]
{VARIABLE triggers 0}
[/event]
[event]
name=side 1 turn 1
[do_command]
[move]
x=7,13
y=3,4
[/move]
[attack]
[source]
x,y=13,4
[/source]
[destination]
x,y=13,3
[/destination]
[/attack]
[/do_command]
[end_turn][/end_turn]
[/event]

[event]
name=side 2 turn
[do_command]
[attack]
[source]
x,y=13,3
[/source]
[destination]
x,y=13,4
[/destination]
[/attack]
[/do_command]
[end_turn][/end_turn]
[/event]

# Event when Alice attacks
[event]
name=attack
first_time_only=no
[filter_attack]
type=arcane
[/filter_attack]
{ASSERT ({VARIABLE_CONDITIONAL side_number equals 1})}
{ASSERT ({VARIABLE_CONDITIONAL triggers equals 0})}
{VARIABLE_OP triggers add 1}
[/event]
[event]
name=turn 2
{RETURN ({VARIABLE_CONDITIONAL triggers equals 1})}
[/event]
)}
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
#textdomain wesnoth-test

#####
# API(s) being tested: [damage]replacement_type=
##
# Actions:
# Give both Alice and Bob 100% chance to hit.
# Give Bob one [damage] with replacement_type=fire and two [damage] with replacement_type=cold
# change resistance of Bob to arcane to 50% and fire to -100%.
# Give Alice one [damage] with replacement_type=cold, two [damage] with replacement_type=arcane and three with replacement_type=fire
# and change Alice resistance to cold to -100% and fire to 50%.
# Move Alice next to Bob, and have Alice attack Bob.
##
# Expected end state:
# Alice attack with fire and Bob use cold.
#####
{GENERIC_UNIT_TEST "damage_type_test" (
# macro used for two tests below
#define FILTER_TYPE_BLADE
[filter_self]
[filter_weapon]
type=blade
[/filter_weapon]
[/filter_self]
#enddef

#define DAMAGE_TYPE_TEST FILTER_WEAPON
[event]
name=start
[modify_unit]
Expand Down Expand Up @@ -46,12 +41,15 @@
[/damage]
[damage]
replacement_type=fire
{FILTER_WEAPON}
[/damage]
[damage]
replacement_type=cold
{FILTER_WEAPON}
[/damage]
[damage]
replacement_type=cold
{FILTER_WEAPON}
[/damage]
[chance_to_hit]
value=100
Expand Down Expand Up @@ -166,6 +164,42 @@
{ASSERT ({VARIABLE_CONDITIONAL b.hitpoints equals 76})}
{SUCCEED}
[/event]
#enddef

#####
# API(s) being tested: [damage]replacement_type=
##
# Actions:
# Give both Alice and Bob 100% chance to hit.
# Give Bob one [damage] with replacement_type=fire and two [damage] with replacement_type=cold
# change resistance of Bob to arcane to 50% and fire to -100%.
# Give Alice one [damage] with replacement_type=cold, two [damage] with replacement_type=arcane and three with replacement_type=fire
# and change Alice resistance to cold to -100% and fire to 50%.
# Move Alice next to Bob, and have Alice attack Bob.
##
# Expected end state:
# Alice attack with fire and Bob use cold.
#####
{GENERIC_UNIT_TEST "damage_type_test" (
{DAMAGE_TYPE_TEST ()}
)}

#####
# API(s) being tested: [damage]replacement_type=[filter_self][filter_weapon]type=blade
##
# Actions:
# Give both Alice and Bob 100% chance to hit.
# Give Bob one [damage] with replacement_type=fire and two [damage] with replacement_type=cold and filter by type=blade
# change resistance of Bob to arcane to 50% and fire to -100%.
# Give Alice one [damage] with replacement_type=cold, two [damage] with replacement_type=arcane and three with replacement_type=fire
# and change Alice resistance to cold to -100% and fire to 50%.
# Move Alice next to Bob, and have Alice attack Bob.
##
# Expected end state:
# Alice attack with fire; and Bob use cold because Bob [damage] filter must check type=blade and not the replacement type, that who cause infinite recursion.
#####
{GENERIC_UNIT_TEST "damage_type_with_filter_test" (
{DAMAGE_TYPE_TEST {FILTER_TYPE_BLADE}}
)}

#####
Expand Down
2 changes: 2 additions & 0 deletions wml_test_schedule
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
0 test_ability_id_not_active
0 event_test_filter_attack
0 event_test_filter_attack_no_defense
0 event_test_filter_attack_type
0 event_test_filter_attack_specials
0 event_test_filter_attack_on_moveto
0 event_test_filter_attack_opponent_weapon_condition
Expand Down Expand Up @@ -335,6 +336,7 @@
0 test_remove_ability_by_filter
0 test_overwrite_specials_filter
0 damage_type_test
0 damage_type_with_filter_test
0 damage_secondary_type_test
0 swarms_filter_student_by_type
0 swarms_effects_not_checkable
Expand Down

0 comments on commit 6fd29f0

Please sign in to comment.