61 lines
2.1 KiB
GDScript
61 lines
2.1 KiB
GDScript
extends "res://addons/gut/test.gd"
|
|
|
|
const CanonLog = preload("res://scripts/canon_log/canon_log.gd")
|
|
const PartyMember = preload("res://scripts/canon_log/party_member.gd")
|
|
const Quest = preload("res://scripts/canon_log/quest.gd")
|
|
|
|
|
|
func test_push_event_caps_at_five():
|
|
var log = CanonLog.new()
|
|
for i in 7:
|
|
log.push_event("event %d" % i)
|
|
assert_eq(log.recent_events.size(), 5)
|
|
assert_eq(log.recent_events[0], "event 2")
|
|
assert_eq(log.recent_events[4], "event 6")
|
|
|
|
|
|
func test_add_fact_dedups():
|
|
var log = CanonLog.new()
|
|
log.add_fact("the bridge is out")
|
|
log.add_fact("the bridge is out")
|
|
assert_eq(log.established_facts.size(), 1)
|
|
|
|
|
|
func test_humiliations_stack():
|
|
var log = CanonLog.new()
|
|
log.add_humiliation("h_1", "vomited on a shrine", 7, 3)
|
|
log.add_humiliation("h_2", "vomited on a shrine", 7, 5)
|
|
assert_eq(log.humiliations.size(), 2)
|
|
|
|
|
|
func test_adjust_disposition_clamps_and_reports_missing():
|
|
var log = CanonLog.new()
|
|
log.party.append(PartyMember.new("brannoc_thane", "Brannoc Thane", 98))
|
|
assert_true(log.adjust_disposition("brannoc_thane", 50))
|
|
assert_eq(log.party_member("brannoc_thane").disposition, 100)
|
|
assert_false(log.adjust_disposition("nobody", 5))
|
|
|
|
|
|
func test_set_quest_status_rejects_bad_enum():
|
|
var log = CanonLog.new()
|
|
log.active_quests.append(Quest.new("find_the_ledger", "The Missing Ledger", "active", "Find it"))
|
|
assert_false(log.set_quest_status("find_the_ledger", "abandoned"))
|
|
assert_true(log.set_quest_status("find_the_ledger", "complete"))
|
|
assert_false(log.set_quest_status("no_quest", "active"))
|
|
|
|
|
|
func test_unsupported_schema_version_returns_null():
|
|
assert_null(CanonLog.from_dict({"schema_version": 2}))
|
|
|
|
|
|
func test_add_quest_appends_active_and_is_idempotent():
|
|
var log = CanonLog.new()
|
|
assert_false(log.has_quest("find_the_ledger"))
|
|
assert_true(log.add_quest("find_the_ledger", "The Missing Ledger", "Find who took it"))
|
|
assert_true(log.has_quest("find_the_ledger"))
|
|
assert_eq(log.active_quests.size(), 1)
|
|
assert_eq(log.active_quests[0].status, "active")
|
|
# second add is a no-op
|
|
assert_false(log.add_quest("find_the_ledger", "x", "y"))
|
|
assert_eq(log.active_quests.size(), 1)
|