sunder/tests/test_flag.gd
2026-02-18 18:33:17 -05:00

61 lines
2.1 KiB
GDScript

# This file is part of sunder.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
extends GutTest
const FLAG:PackedScene = preload("res://scenes/entities/flag/flag.tscn")
const FLAG_HOLDER:PackedScene = preload("res://scenes/entities/components/flag_holder.tscn")
var _subject:Flag
var _carry:FlagHolder
func before_each() -> void:
_subject = FLAG.instantiate()
_carry = FLAG_HOLDER.instantiate()
watch_signals(_subject)
add_child_autofree(_subject)
add_child_autofree(_carry)
func test_flag_default_state() -> void:
assert_eq(_subject.state, Flag.FlagState.ON_STAND)
func test_flag_default_visibility() -> void:
assert_true(_subject.is_visible())
func test_grab_flag() -> void:
_carry.grab(_subject)
assert_signal_emitted_with_parameters(_subject, 'grabbed', [_carry])
assert_eq(_subject.state, Flag.FlagState.TAKEN)
assert_eq(_subject.last_carrier, null)
assert_false(_subject.is_visible())
func test_drop_flag() -> void:
test_grab_flag()
_carry.drop()
assert_signal_emitted_with_parameters(_subject, 'dropped', [_carry])
assert_eq(_subject.state, Flag.FlagState.DROPPED)
assert_eq(_subject.last_carrier, _carry)
assert_true(_subject.is_visible())
#
func test_that_flag_grab_hides_flag() -> void:
test_grab_flag()
assert_false(_subject.is_visible())
func test_grab_already_taken_flag() -> void:
test_grab_flag()
var _new_carry:FlagHolder = FLAG_HOLDER.instantiate()
add_child_autofree(_new_carry)
_new_carry.grab(_subject)
assert_null(_new_carry.flag)
assert_eq(_carry.flag, _subject)