feat(client): id helper + leaf canon-log entities with owned invariants
Also configure GUT to not treat push_error() as a test failure (client/.gutconfig.json: failure_error_types = [engine, gut]). The brief's LogPlayer/Quest setters intentionally push_error() on rejected input; GUT's default failure_error_types includes push_error, which would fail test_player_rejects_unknown_class and test_quest_status_enum despite their assertions passing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
55
client/tests/unit/test_entities.gd
Normal file
55
client/tests/unit/test_entities.gd
Normal file
@@ -0,0 +1,55 @@
|
||||
extends "res://addons/gut/test.gd"
|
||||
|
||||
const Ids = preload("res://scripts/ids.gd")
|
||||
const LogPlayer = preload("res://scripts/canon_log/log_player.gd")
|
||||
const LogLocation = preload("res://scripts/canon_log/log_location.gd")
|
||||
const PartyMember = preload("res://scripts/canon_log/party_member.gd")
|
||||
const Quest = preload("res://scripts/canon_log/quest.gd")
|
||||
const Humiliation = preload("res://scripts/canon_log/humiliation.gd")
|
||||
|
||||
|
||||
func test_ids_regex():
|
||||
assert_true(Ids.is_valid("greywater_docks"))
|
||||
assert_false(Ids.is_valid("Bad Id"))
|
||||
assert_false(Ids.is_valid("has-hyphen"))
|
||||
|
||||
|
||||
func test_player_dict_has_only_three_keys():
|
||||
var p = LogPlayer.new("Aldric", "sellsword", "Fortune spits on you")
|
||||
var d = p.to_dict()
|
||||
assert_eq(d.keys().size(), 3)
|
||||
assert_false("luck" in d)
|
||||
assert_eq(d["class_id"], "sellsword")
|
||||
|
||||
|
||||
func test_player_rejects_unknown_class():
|
||||
var p = LogPlayer.new("Aldric", "sellsword", "x")
|
||||
assert_false(p.set_class_id("bard"))
|
||||
assert_eq(p.class_id, "sellsword")
|
||||
|
||||
|
||||
func test_party_member_clamps_disposition():
|
||||
var m = PartyMember.new("brannoc_thane", "Brannoc Thane", 200)
|
||||
assert_eq(m.disposition, 100)
|
||||
m.set_disposition(-200)
|
||||
assert_eq(m.disposition, -100)
|
||||
|
||||
|
||||
func test_quest_status_enum():
|
||||
var q = Quest.new("find_the_ledger", "The Missing Ledger", "active", "Find it")
|
||||
assert_false(q.set_status("abandoned"))
|
||||
assert_eq(q.status, "active")
|
||||
assert_true(q.set_status("complete"))
|
||||
|
||||
|
||||
func test_humiliation_clamps_weight_and_turn():
|
||||
var h = Humiliation.new("h_1", "vomited on a shrine", 11, -3)
|
||||
assert_eq(h.weight, 10)
|
||||
assert_eq(h.turn, 0)
|
||||
|
||||
|
||||
func test_round_trip_each_entity():
|
||||
var loc = LogLocation.new("greywater_docks", "the Greywater docks")
|
||||
assert_eq(LogLocation.from_dict(loc.to_dict()).to_dict(), loc.to_dict())
|
||||
var m = PartyMember.new("cadwyn_vell", "Cadwyn Vell", 15)
|
||||
assert_eq(PartyMember.from_dict(m.to_dict()).to_dict(), m.to_dict())
|
||||
1
client/tests/unit/test_entities.gd.uid
Normal file
1
client/tests/unit/test_entities.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b4ggfq607h4bj
|
||||
Reference in New Issue
Block a user