Skip to content

Commit

Permalink
Add unit tests for ability[filter][filter_adjacent_location]adjacent,…
Browse files Browse the repository at this point in the history
…count=

The Wiki docs say that count= takes a number or numerical range, and
is true if the number of matches in adjacent locations matches that
range. However, the implementations that are specific to using it in
ability filters are buggy, and returns false if any location in the
adjacent= set doesn't match.

This behavior should be fixed for 1.20, but fixing it for 1.18 could
cause Out Of Sync errors if any ability used this.
  • Loading branch information
stevecotton authored and newfrenchy83 committed Oct 11, 2024
1 parent 0e21864 commit be284c4
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#textdomain wesnoth-test

#####
# API(s) being tested: ability[filter][filter_adjacent_location]adjacent,count=
##
# Actions:
# Give Alice an ability specialX, which is only active if exactly three of adjacents terrains are Gg.
# Give Charlie and Dave has specialY.
# Test whether the ability is active.
##
# Expected end state:
# specialX should be active.
#####
{COMMON_KEEP_A_B_C_D_UNIT_TEST "filter_filter_adjacent_location_count_three_active" (
[event]
name=start

[object]
silent=yes
[effect]
apply_to=new_ability
[abilities]
[damage]
id=specialX
name=_ "specialX"
description=_ "specialX is active if and only if 3 terrains hexes are Gg"
value=100
apply_to=self
[filter]
[filter_adjacent_location]
adjacent=n,ne,se,s,sw,nw
count=3
terrain=Gg
[/filter_adjacent_location]
[/filter]
[/damage]
[/abilities]
[/effect]
[filter]
id=alice
[/filter]
[/object]

{ASSERT (
[have_unit]
ability_id_active=specialX
[/have_unit]
)}

{SUCCEED}
[/event]
)}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#textdomain wesnoth-test

#####
# API(s) being tested: ability[filter][filter_adjacent_location]adjacent,count=
##
# Actions:
# Give Alice an ability specialX, which is only active if zero of the adjacent terrains are Ww.
# No unit has specialY.
# Test whether the ability is active.
##
# Expected end state:
# specialX should be active.
#####
{COMMON_KEEP_A_B_C_D_UNIT_TEST "filter_filter_adjacent_location_count_zero_active" (
[event]
name=start

[object]
silent=yes
[effect]
apply_to=new_ability
[abilities]
[damage]
id=specialX
name=_ "specialX"
description=_ "specialX is active if and only if 0 terrains hexes are Ww"
value=100
apply_to=self
[filter]
[filter_adjacent_location]
adjacent=n,ne,se,s,sw,nw
count=0
terrain=Ww
[/filter_adjacent_location]
[/filter]
[/damage]
[/abilities]
[/effect]
[filter]
id=alice
[/filter]
[/object]

{ASSERT (
[have_unit]
ability_id_active=specialX
[/have_unit]
)}

{SUCCEED}
[/event]
)}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#####
# API(s) being tested: ability[filter][filter_adjacent_location]adjacent,count=
##
# Actions:
# Give Alice an ability specialX, which is only active if zero of the adjacent terrains are Gg.
# Give Bob the ability specialY.
# Test whether specialX ability is active.
##
# Expected end state:
# specialX isn't active.
#####
{COMMON_KEEP_A_B_C_D_UNIT_TEST "filter_filter_adjacent_location_count_zero_inactive" (
[event]
name=start

[object]
silent=yes
[effect]
apply_to=new_ability
[abilities]
[damage]
id=specialX
name=_ "specialX"
description=_ "specialX is active if and only if 0 terrains hexes are Gg"
value=100
apply_to=self
[filter]
[filter_adjacent_location]
adjacent=n,ne,se,s,sw,nw
count=0
terrain=Gg
[/filter_adjacent_location]
[/filter]
[/damage]
[/abilities]
[/effect]
[filter]
id=alice
[/filter]
[/object]

{ASSERT (
[not]
[have_unit]
ability_id_active=specialX
[/have_unit]
[/not]
)}

{SUCCEED}
[/event]
)}
3 changes: 3 additions & 0 deletions wml_test_schedule
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@
0 taught_resistance_with_three_attack_types
0 swarms_filter_student_by_type
0 swarms_effects_not_checkable
0 filter_filter_adjacent_location_count_three_active
0 filter_filter_adjacent_location_count_zero_active
0 filter_filter_adjacent_location_count_zero_inactive
0 filter_special_id_active
0 filter_ability_special_id_active
0 filter_special_id_not_exists
Expand Down

0 comments on commit be284c4

Please sign in to comment.