extends GutTest const ContentCatalog = preload("res://scripts/domain/content/content_catalog.gd") const ASCII_DATA_PATH := "res://data/ascii" const ITEM_CATEGORIES := [&"weapon", &"armor", &"consumable", &"misc", &"quest"] const ITEM_RARITIES := [&"commun", &"inhabituel", &"rare", &"epique", &"legendaire", &"unique"] const EQUIPMENT_SLOTS := [&"main_hand", &"off_hand", &"head", &"torso", &"arms", &"legs", &"accessory1", &"accessory2"] const SPELL_SCHOOLS := [&"attaque", &"controle", &"soin", &"utilitaire"] const ACHIEVEMENT_CATEGORIES := [&"combat", &"exploration", &"progression", &"social_meta", &"absurde"] const MAX_COLD_LOAD_MSEC := 5000 func test_all_generated_items_spells_and_achievements_load_with_valid_taxonomy_within_budget() -> void: var start_msec := Time.get_ticks_msec() var catalog := ContentCatalog.load_from_directory(ASCII_DATA_PATH) var elapsed_msec := Time.get_ticks_msec() - start_msec assert_eq(Array(catalog.get_diagnostics()), []) assert_lte(elapsed_msec, MAX_COLD_LOAD_MSEC, "cold catalog load must fit the documented release-like budget") _assert_exact_source_ids(catalog, "items.json", &"item") _assert_exact_source_ids(catalog, "spells.json", &"spell") _assert_exact_source_ids(catalog, "achievements.json", &"achievement") for item_id in catalog.get_ids(&"item"): var item := catalog.get_item(item_id) assert_true(StringName(item.category) in ITEM_CATEGORIES, "%s has a supported item category" % item_id) assert_true(StringName(item.rarity) in ITEM_RARITIES, "%s has a supported item rarity" % item_id) if item.has("equip_slot"): assert_true(StringName(item.equip_slot) in EQUIPMENT_SLOTS, "%s has a supported equipment slot" % item_id) for spell_id in catalog.get_ids(&"spell"): assert_true(StringName(catalog.get_spell(spell_id).school) in SPELL_SCHOOLS, "%s has a supported spell school" % spell_id) for achievement_id in catalog.get_ids(&"achievement"): assert_true(StringName(catalog.get_achievement(achievement_id).category) in ACHIEVEMENT_CATEGORIES, "%s has a supported achievement category" % achievement_id) func _assert_exact_source_ids(catalog: ContentCatalog, filename: String, kind: StringName) -> void: var expected_ids: Array[StringName] = [] for entry in _read_json(filename): expected_ids.append(StringName(entry.id)) expected_ids.sort() var actual_ids := catalog.get_ids(kind) assert_eq(actual_ids.size(), expected_ids.size(), "%s catalog cardinality" % filename) assert_eq(actual_ids, expected_ids, "%s preserves every generated source id exactly once" % filename) func _read_json(filename: String) -> Array: var file := FileAccess.open(ASCII_DATA_PATH.path_join(filename), FileAccess.READ) return JSON.parse_string(file.get_as_text())