Files
Bubberstation/code/modules/unit_tests/dismemberment.dm
SkyratBot 015be230f3 [MIRROR] Adds a unit test to check items are dropped when the arm holding them is dismembered. [MDB IGNORE] (#23201)
* Adds a unit test to check items are dropped when the arm holding them is dismembered. (#77646)

## About The Pull Request

What it says on the tin. First time ever making a unit test, so
critiques and feedback are very much appreciated.
If anyone thinks of other relevant edge cases, please do bring them up.
## Why It's Good For The Game

Requested in #77613 (71fe46511a), as the
fact it broke again is a regression. Will fail until that PR is merged,
as you might expect.

* Adds a unit test to check items are dropped when the arm holding them is dismembered.

---------

Co-authored-by: A miscellaneous Fern <80640114+FernandoJ8@users.noreply.github.com>
2023-08-19 11:45:58 -04:00

39 lines
1.5 KiB
Plaintext

/**
* Unit test to check that held items are dropped correctly when we are dismembered.
*
* Also tests for edge cases such as undroppable items.
*/
/datum/unit_test/dismemberment/Run()
var/mob/living/carbon/human/dummy = allocate(/mob/living/carbon/human/consistent)
var/obj/item/testing_item = allocate(/obj/item/analyzer)
testing_item.name = "testing item"
// Standard situation: We're holding a normal item and get dismembered.
test_item(dummy, testing_item)
// Abnormal situation: We're holding an undroppable item and get dismembered.
ADD_TRAIT(testing_item, TRAIT_NODROP, TRAIT_GENERIC)
test_item(dummy, testing_item, status_text = "after applying TRAIT_NODROP to the testing item")
/datum/unit_test/dismemberment/proc/test_item(mob/living/carbon/human/dummy, obj/item/testing_item, status_text = "")
//Check both to make sure being the active hand doesn't make a difference.
dummy.put_in_l_hand(testing_item)
check_dismember(dummy, BODY_ZONE_L_ARM, status_text)
dummy.put_in_r_hand(testing_item)
check_dismember(dummy, BODY_ZONE_R_ARM, status_text)
/datum/unit_test/dismemberment/proc/check_dismember(mob/living/carbon/human/dummy, which_arm, status_text)
var/obj/item/bodypart/dismembered_limb = dummy.get_bodypart(which_arm)
var/obj/item/held_item = dummy.get_item_for_held_index(dismembered_limb.held_index)
dismembered_limb.dismember()
TEST_ASSERT(held_item in dummy.loc, "Dummy did not drop [held_item] when [dismembered_limb] was dismembered [status_text].")
// Clean up after ourselves
qdel(dismembered_limb)
dummy.fully_heal(HEAL_ALL)