Add code comments stating what each unit test is testing.

This commit is contained in:
Pentarctagon 2021-11-16 16:46:00 -06:00 committed by Steve Cotton
parent 14865d0afd
commit 11631775a4
6 changed files with 265 additions and 80 deletions

View file

@ -56,6 +56,11 @@
[/if]
#enddef
##
# Starting state:
# Side 1 leader Alice (Elvish Archer)
# Side 2 leader Bob (Orcish Grunt)
##
#define GENERIC_UNIT_TEST NAME CONTENT
#arg SIDE1_CONTROLLER
human#endarg

View file

@ -1,5 +1,17 @@
# wmllint: no translatables
#####
# API(s) being tested: [have_unit]ability_id_active
##
# Actions:
# Give Alice an unconditionally active [hides] ability.
# Recruit a Peasant and check that a unit exists with an active [hides] ability.
# Recruit a Woodsman and check that a unit exists with an active [hides] ability.
##
# Expected end state:
# [have_unit]ability_id_active triggers on each recruit
#####
{GENERIC_UNIT_TEST test_ability_id_active (
[event]
name=start
@ -63,76 +75,3 @@
{VARIABLE_OP triggers add 1}
[/event]
) (SIDE1_RECRUIT=Peasant,Woodsman)}
{GENERIC_UNIT_TEST test_ability_id_not_active (
[event]
name=start
{VARIABLE triggers 0}
[object]
silent=yes
[filter]
id=alice
[/filter]
[effect]
apply_to=new_ability
[abilities]
[hides]
id=hides_test
[filter]
[filter_location]
terrain=*^F*
[/filter_location]
[/filter]
[/hides]
[/abilities]
[/effect]
[/object]
[do_command]
[recruit]
type=Peasant
x,y=3,6
[from]
x,y=7,3
[/from]
[/recruit]
[/do_command]
[do_command]
[recruit]
type=Woodsman
x,y=15,8
[from]
x,y=7,3
[/from]
[/recruit]
[/do_command]
{RETURN ({VARIABLE_CONDITIONAL triggers equals 2})}
[/event]
[event]
name=recruit
[filter]
type=Peasant
[/filter]
{ASSERT (
[not]
[have_unit]
ability_id_active=hides_test
[/have_unit]
[/not]
)}
{VARIABLE_OP triggers add 1}
[/event]
[event]
name=recruit
[filter]
type=Woodsman
[/filter]
{ASSERT (
[not]
[have_unit]
ability_id_active=hides_test
[/have_unit]
[/not]
)}
{VARIABLE_OP triggers add 1}
[/event]
) (SIDE1_RECRUIT=Peasant,Woodsman)}

View file

@ -0,0 +1,86 @@
# wmllint: no translatables
#####
# API(s) being tested: [have_unit]ability_id_active
##
# Actions:
# Give Alice a [hides] ability active only on forests.
# Recruit a Peasant and check that no unit exists with an active [hides] ability.
# Recruit a Woodsman and check that no unit exists with an active [hides] ability.
##
# Expected end state:
# [not][have_unit]ability_id_active does not trigger on either recruit
#####
{GENERIC_UNIT_TEST test_ability_id_not_active (
[event]
name=start
{VARIABLE triggers 0}
[object]
silent=yes
[filter]
id=alice
[/filter]
[effect]
apply_to=new_ability
[abilities]
[hides]
id=hides_test
[filter]
[filter_location]
terrain=*^F*
[/filter_location]
[/filter]
[/hides]
[/abilities]
[/effect]
[/object]
[do_command]
[recruit]
type=Peasant
x,y=3,6
[from]
x,y=7,3
[/from]
[/recruit]
[/do_command]
[do_command]
[recruit]
type=Woodsman
x,y=15,8
[from]
x,y=7,3
[/from]
[/recruit]
[/do_command]
{RETURN ({VARIABLE_CONDITIONAL triggers equals 2})}
[/event]
[event]
name=recruit
[filter]
type=Peasant
[/filter]
{ASSERT (
[not]
[have_unit]
ability_id_active=hides_test
[/have_unit]
[/not]
)}
{VARIABLE_OP triggers add 1}
[/event]
[event]
name=recruit
[filter]
type=Woodsman
[/filter]
{ASSERT (
[not]
[have_unit]
ability_id_active=hides_test
[/have_unit]
[/not]
)}
{VARIABLE_OP triggers add 1}
[/event]
) (SIDE1_RECRUIT=Peasant,Woodsman)}

View file

@ -1,4 +1,6 @@
# Unit tests for wesnoth.as_text(...)
#####
# API(s) being tested: wesnoth.as_text
#####
{GENERIC_UNIT_TEST "as_text" (
[event]
@ -26,17 +28,20 @@
[lua]
code = <<
-- testing data type handling
unit_test.assert_equal(wesnoth.as_text("a"), '"a"', 'convert string to string')
unit_test.assert_equal(wesnoth.as_text(1), "1", 'convert number to string')
unit_test.assert_equal(wesnoth.as_text(true), "true", 'convert boolean to string')
unit_test.assert_equal(wesnoth.as_text({ "a", "b", "c" }), '{"1":"a","2":"b","3":"c"}', 'convert array to string')
-- associative table iteration order not defined and can vary between runs even when the data remains identical
-- testing conversion of lua table
-- associative table iteration order not defined and can vary between runs even when the data remains identical so can't test full string contents
local tab_txt = wesnoth.as_text({ a = 1, b = false, c = "d" })
unit_test.assert_contains(tab_txt, '"a":1', 'convert table to string: first key')
unit_test.assert_contains(tab_txt, '"b":false', 'convert table to string: second key')
unit_test.assert_contains(tab_txt, '"c":"d"', 'convert table to string: third key')
-- testing WML array conversion
local wml_tab_txt = wesnoth.as_text(wml.variables["var"])
unit_test.assert_contains(wml_tab_txt, '{"1":{"1":"one","2":{"1":{"1":"first","2":{', 'convert wml table to string: first tag opener')
unit_test.assert_contains(wml_tab_txt, '"a":1', 'convert wml table to string: first tag first key')

View file

@ -1,5 +1,6 @@
# This test checks conditional tags
#####
# API(s) being tested: [if][true],[and][true],[or][true],[not][false]
#####
{GENERIC_UNIT_TEST "check_conditionals_1" (
[event]
name = start
@ -22,6 +23,9 @@
[/event]
)}
#####
# API(s) being tested: [if][true],[and][true],[or][false]
#####
{GENERIC_UNIT_TEST "check_conditionals_2" (
[event]
name = start

View file

@ -1,3 +1,13 @@
#####
# API(s) being tested: [event][fire_event]
##
# Actions:
# Define a custom event
# Fire the custom event from within another event with [fire_event] using its name
##
# Expected end state:
# The custom event has executed
#####
{GENERIC_UNIT_TEST "event_handlers_in_events_1" (
[event]
name=test
@ -13,6 +23,16 @@
[/event]
)}
#####
# API(s) being tested: [event][fire_event],[event][event]
##
# Actions:
# Define a custom event nested within another event
# Fire the custom event from within the same event than the custom event was defined in with [fire_event] using its name
##
# Expected end state:
# The custom event has executed
#####
{GENERIC_UNIT_TEST "event_handlers_in_events_2" (
[event]
name=start
@ -29,6 +49,17 @@
[/event]
)}
#####
# API(s) being tested: [event][fire_event],[event][event]
##
# Actions:
# Define a custom event nested within another event
# The nested event is defined first in the WML
# Fire the custom event from within a different event than the custom event was defined in with [fire_event] using its name
##
# Expected end state:
# The custom event has executed
#####
{GENERIC_UNIT_TEST "event_handlers_in_events_3" (
[event]
name=start
@ -48,6 +79,16 @@
[/event]
)}
#####
# API(s) being tested: [event][fire_event],[event][event]
##
# Actions:
# Attempt to fire a custom event before that custom event has been defined
# Then define the custom event
##
# Expected end state:
# The custom event has not been executed
#####
{GENERIC_UNIT_TEST "event_handlers_in_events_4" (
[event]
name=start
@ -67,6 +108,18 @@
[/event]
)}
#####
# API(s) being tested: [event][event],[unstore_unit]fire_event
##
# Actions:
# Create a unit
# Store the unit
# Define a nested post_advance event
# Make the unit advance by giving it xp and unstoring with fire_event=yes
##
# Expected end state:
# The nested post_advance event is executed
#####
{GENERIC_UNIT_TEST "event_handlers_in_events_5" (
[event]
name=start
@ -97,6 +150,18 @@
[/event]
)}
#####
# API(s) being tested: [event][insert_tag]
##
# Actions:
# Create a unit
# Store the unit
# Define a nested post_advance event using [set_variables] and [insert_tag]
# Make the unit advance by giving it xp and unstoring with fire_event=yes
##
# Expected end state:
# The nested post_advance event is executed
#####
{GENERIC_UNIT_TEST "event_handlers_in_events_6" (
[event]
name=start
@ -121,9 +186,6 @@
name=event
variable=ev0
[/insert_tag]
[fire_event]
name=test
[/fire_event]
{VARIABLE_OP my_unit.experience add 50}
[unstore_unit]
@ -137,6 +199,19 @@
[/event]
)}
#####
# API(s) being tested: [event][event][insert_tag]
##
# Actions:
# Create a unit
# Store the unit
# Define a nested custom event which itself has a nested post_advance event using [set_variables] and [insert_tag]
# Fire the outer, custom event using its name
# Make the unit advance by giving it xp and unstoring with fire_event=yes
##
# Expected end state:
# The nested post_advance event is executed
#####
{GENERIC_UNIT_TEST "event_handlers_in_events_7" (
[event]
name=start
@ -180,6 +255,18 @@
[/event]
)}
#####
# API(s) being tested: [event][insert_tag]
##
# Actions:
# Create a unit
# Store the unit
# Define a nested custom event which itself has a nested post_advance event using the stored unit's [variables] and [insert_tag]
# Make the unit advance by giving it xp and unstoring with fire_event=yes
##
# Expected end state:
# The nested post_advance event is executed
#####
{GENERIC_UNIT_TEST "event_handlers_in_events_8" (
[event]
name=start
@ -217,6 +304,16 @@
[/event]
)}
#####
# API(s) being tested: [event][fire_event]id
##
# Actions:
# Define a custom event
# Fire the custom event from within another event with [fire_event] using its ID
##
# Expected end state:
# The custom event has executed
#####
{GENERIC_UNIT_TEST "event_handlers_in_events_9" (
[event]
name=start
@ -234,6 +331,15 @@
[/event]
)}
#####
# API(s) being tested: [event]delayed_variable_substitution
##
# Actions:
# Define a nested event with delayed_variable_substitution=yes
##
# Expected end state:
# The nested event delays substituting the variable's value until it executes, rather than when the outer event executes
#####
{GENERIC_UNIT_TEST "event_handers_in_events__delayed" (
[event]
name=prestart
@ -250,6 +356,15 @@
[/event]
)}
#####
# API(s) being tested: [event]delayed_variable_substitution
##
# Actions:
# Define a nested event with delayed_variable_substitution=no
##
# Expected end state:
# The nested event immediately substitutes the variable's value when the outer event executes
#####
{GENERIC_UNIT_TEST "event_handers_in_events__immediate" (
[event]
name=prestart
@ -266,6 +381,17 @@
[/event]
)}
#####
# API(s) being tested: [event][insert_tag]
##
# Actions:
# Define a post_advance event which includes a filter created via [insert_tag]
# Two units are created, exactly one of which matches the filter
# Both units are advanced a level
##
# Expected end state:
# The event was triggered exactly once
#####
{GENERIC_UNIT_TEST "event_handlers_in_events__dynamic_filter" (
[event]
name=start
@ -280,6 +406,7 @@
{UNIT 1 "Elvish Archer" 2 2 ()}
[event]
name=post_advance
first_time_only=no
[insert_tag]
name=filter
variable=filter
@ -297,6 +424,16 @@
[/event]
)}
#####
# API(s) being tested: [remove_event]
##
# Actions:
# Define an event with an ID value
# Remove the event
##
# Expected end state:
# The removed event doesn't fire
#####
{GENERIC_UNIT_TEST "event_remove_test" (
[event]
name=start
@ -315,6 +452,15 @@
[/event]
)}
#####
# API(s) being tested: [event]first_time_only
##
# Actions:
# Define a nested event with first_time_only=no
##
# Expected end state:
# The event executes multiple times
#####
{GENERIC_UNIT_TEST "event_repeat_test" (
[event]
name=start