Add tests for validation assets

This commit is contained in:
juliancoffee 2021-05-23 22:27:33 +03:00
parent 8c1643cad9
commit 457e5b14d8
14 changed files with 153 additions and 96 deletions

View File

@ -1,8 +1,8 @@
({ ({
"head": Item("common.items.npc_armor.biped_small.gnarling.head.gnarling"), Armor(Head): Item("common.items.npc_armor.biped_small.gnarling.head.gnarling"),
"feet": Item("common.items.npc_armor.biped_small.gnarling.foot.gnarling"), Armor(Feet): Item("common.items.npc_armor.biped_small.gnarling.foot.gnarling"),
"hands": Item("common.items.npc_armor.biped_small.gnarling.hand.gnarling"), Armor(Hands): Item("common.items.npc_armor.biped_small.gnarling.hand.gnarling"),
"chest": Item("common.items.npc_armor.biped_small.gnarling.chest.gnarling"), Armor(Chest): Item("common.items.npc_armor.biped_small.gnarling.chest.gnarling"),
"pants": Item("common.items.npc_armor.biped_small.gnarling.pants.gnarling"), Armor(Legs): Item("common.items.npc_armor.biped_small.gnarling.pants.gnarling"),
"belt": Item("common.items.npc_armor.biped_small.gnarling.tail.gnarling"), Armor(Belt): Item("common.items.npc_armor.biped_small.gnarling.tail.gnarling"),
}) })

View File

@ -1,8 +1,8 @@
({ ({
"head": Item("common.items.npc_armor.biped_small.adlet.head.adlet_bow"), Armor(Head): Item("common.items.npc_armor.biped_small.adlet.head.adlet_bow"),
"hands": Item("common.items.npc_armor.biped_small.adlet.hand.adlet_bow"), Armor(Hands): Item("common.items.npc_armor.biped_small.adlet.hand.adlet_bow"),
"feet": Item("common.items.npc_armor.biped_small.adlet.foot.adlet"), Armor(Feet): Item("common.items.npc_armor.biped_small.adlet.foot.adlet"),
"chest": Item("common.items.npc_armor.biped_small.adlet.chest.adlet_bow"), Armor(Chest): Item("common.items.npc_armor.biped_small.adlet.chest.adlet_bow"),
"pants": Item("common.items.npc_armor.biped_small.adlet.pants.adlet_bow"), Armor(Legs): Item("common.items.npc_armor.biped_small.adlet.pants.adlet_bow"),
"belt": Item("common.items.npc_armor.biped_small.adlet.tail.adlet"), Armor(Belt): Item("common.items.npc_armor.biped_small.adlet.tail.adlet"),
}) })

View File

@ -1,8 +1,8 @@
({ ({
"head": Item("common.items.npc_armor.biped_small.adlet.head.adlet_spear"), Armor(Head): Item("common.items.npc_armor.biped_small.adlet.head.adlet_spear"),
"hands": Item("common.items.npc_armor.biped_small.adlet.hand.adlet_spear"), Armor(Hands): Item("common.items.npc_armor.biped_small.adlet.hand.adlet_spear"),
"feet": Item("common.items.npc_armor.biped_small.adlet.foot.adlet"), Armor(Feet): Item("common.items.npc_armor.biped_small.adlet.foot.adlet"),
"chest": Item("common.items.npc_armor.biped_small.adlet.chest.adlet_spear"), Armor(Chest): Item("common.items.npc_armor.biped_small.adlet.chest.adlet_spear"),
"pants": Item("common.items.npc_armor.biped_small.adlet.pants.adlet_spear"), Armor(Legs): Item("common.items.npc_armor.biped_small.adlet.pants.adlet_spear"),
"belt": Item("common.items.npc_armor.biped_small.adlet.tail.adlet"), Armor(Belt): Item("common.items.npc_armor.biped_small.adlet.tail.adlet"),
}) })

View File

@ -1,8 +1,8 @@
({ ({
"head": Item("common.items.npc_armor.biped_small.sahagin.head.sahagin"), Armor(Head): Item("common.items.npc_armor.biped_small.sahagin.head.sahagin"),
"feet": Item("common.items.npc_armor.biped_small.sahagin.foot.sahagin"), Armor(Feet): Item("common.items.npc_armor.biped_small.sahagin.foot.sahagin"),
"hands": Item("common.items.npc_armor.biped_small.sahagin.hand.sahagin"), Armor(Hands): Item("common.items.npc_armor.biped_small.sahagin.hand.sahagin"),
"chest": Item("common.items.npc_armor.biped_small.sahagin.chest.sahagin"), Armor(Chest): Item("common.items.npc_armor.biped_small.sahagin.chest.sahagin"),
"pants": Item("common.items.npc_armor.biped_small.sahagin.pants.sahagin"), Armor(Legs): Item("common.items.npc_armor.biped_small.sahagin.pants.sahagin"),
"belt": Item("common.items.npc_armor.biped_small.sahagin.tail.sahagin"), Armor(Belt): Item("common.items.npc_armor.biped_small.sahagin.tail.sahagin"),
}) })

View File

@ -1,7 +1,7 @@
({ ({
"head": Item("common.items.npc_armor.biped_small.haniwa.head.haniwa"), Armor(Head): Item("common.items.npc_armor.biped_small.haniwa.head.haniwa"),
"feet": Item("common.items.npc_armor.biped_small.haniwa.foot.haniwa"), Armor(Feet): Item("common.items.npc_armor.biped_small.haniwa.foot.haniwa"),
"hands": Item("common.items.npc_armor.biped_small.haniwa.hand.haniwa"), Armor(Hands): Item("common.items.npc_armor.biped_small.haniwa.hand.haniwa"),
"chest": Item("common.items.npc_armor.biped_small.haniwa.chest.haniwa"), Armor(Chest): Item("common.items.npc_armor.biped_small.haniwa.chest.haniwa"),
"pants": Item("common.items.npc_armor.biped_small.haniwa.pants.haniwa"), Armor(Legs): Item("common.items.npc_armor.biped_small.haniwa.pants.haniwa"),
}) })

View File

@ -1,8 +1,8 @@
({ ({
"head": Item("common.items.npc_armor.biped_small.myrmidon.head.myrmidon"), Armor(Head): Item("common.items.npc_armor.biped_small.myrmidon.head.myrmidon"),
"feet": Item("common.items.npc_armor.biped_small.myrmidon.foot.myrmidon"), Armor(Feet): Item("common.items.npc_armor.biped_small.myrmidon.foot.myrmidon"),
"hands": Item("common.items.npc_armor.biped_small.myrmidon.hand.myrmidon"), Armor(Hands): Item("common.items.npc_armor.biped_small.myrmidon.hand.myrmidon"),
"chest": Item("common.items.npc_armor.biped_small.myrmidon.chest.myrmidon"), Armor(Chest): Item("common.items.npc_armor.biped_small.myrmidon.chest.myrmidon"),
"pants": Item("common.items.npc_armor.biped_small.myrmidon.pants.myrmidon"), Armor(Legs): Item("common.items.npc_armor.biped_small.myrmidon.pants.myrmidon"),
"belt": Item("common.items.npc_armor.biped_small.myrmidon.tail.myrmidon"), Armor(Belt): Item("common.items.npc_armor.biped_small.myrmidon.tail.myrmidon"),
}) })

View File

@ -1,17 +1,17 @@
({ ({
"shoulder": Item("common.items.armor.ferocious.shoulder"), Armor(Shoulders): Item("common.items.armor.ferocious.shoulder"),
"chest": Item("common.items.armor.ferocious.chest"), Armor(Chest): Item("common.items.armor.ferocious.chest"),
"belt": Item("common.items.armor.ferocious.belt"), Armor(Belt): Item("common.items.armor.ferocious.belt"),
"hands": Item("common.items.armor.ferocious.hand"), Armor(Hands): Item("common.items.armor.ferocious.hand"),
"pants": Item("common.items.armor.ferocious.pants"), Armor(Legs): Item("common.items.armor.ferocious.pants"),
"feet": Item("common.items.armor.ferocious.foot"), Armor(Feet): Item("common.items.armor.ferocious.foot"),
"back": Item("common.items.armor.ferocious.back"), Armor(Back): Item("common.items.armor.ferocious.back"),
"lantern": Choice([ Lantern: Choice([
(1.0, Some(Item("common.items.lantern.black_0"))), (1.0, Some(Item("common.items.lantern.black_0"))),
(2.0, None), (2.0, None),
]), ]),
"glider": Item("common.items.glider.glider_blue"), Glider: Item("common.items.glider.glider_blue"),
}) })

View File

@ -1,7 +1,7 @@
({ ({
"head": Item("common.items.npc_armor.biped_small.husk.head.husk"), Armor(Head): Item("common.items.npc_armor.biped_small.husk.head.husk"),
"feet": Item("common.items.npc_armor.biped_small.husk.foot.husk"), Armor(Feet): Item("common.items.npc_armor.biped_small.husk.foot.husk"),
"hands": Item("common.items.npc_armor.biped_small.husk.hand.husk"), Armor(Hands): Item("common.items.npc_armor.biped_small.husk.hand.husk"),
"chest": Item("common.items.npc_armor.biped_small.husk.chest.husk"), Armor(Chest): Item("common.items.npc_armor.biped_small.husk.chest.husk"),
"pants": Item("common.items.npc_armor.biped_small.husk.pants.husk"), Armor(Legs): Item("common.items.npc_armor.biped_small.husk.pants.husk"),
}) })

View File

@ -1,17 +1,17 @@
({ ({
"shoulder": Item("common.items.armor.warlock.shoulder"), Armor(Shoulders): Item("common.items.armor.warlock.shoulder"),
"chest": Item("common.items.armor.warlock.chest"), Armor(Chest): Item("common.items.armor.warlock.chest"),
"belt": Item("common.items.armor.warlock.belt"), Armor(Belt): Item("common.items.armor.warlock.belt"),
"hands": Item("common.items.armor.warlock.hand"), Armor(Hands): Item("common.items.armor.warlock.hand"),
"pants": Item("common.items.armor.warlock.pants"), Armor(Legs): Item("common.items.armor.warlock.pants"),
"feet": Item("common.items.armor.warlock.foot"), Armor(Feet): Item("common.items.armor.warlock.foot"),
"back": Item("common.items.armor.warlock.back"), Armor(Back): Item("common.items.armor.warlock.back"),
"lantern": Choice([ Lantern: Choice([
(1.0, Some(Item("common.items.lantern.black_0"))), (1.0, Some(Item("common.items.lantern.black_0"))),
(2.0, None), (2.0, None),
]), ]),
"glider": Item("common.items.glider.glider_purp"), Glider: Item("common.items.glider.glider_purp"),
}) })

View File

@ -1,17 +1,17 @@
({ ({
"shoulder": Item("common.items.armor.warlord.shoulder"), Armor(Shoulders): Item("common.items.armor.warlord.shoulder"),
"chest": Item("common.items.armor.warlord.chest"), Armor(Chest): Item("common.items.armor.warlord.chest"),
"belt": Item("common.items.armor.warlord.belt"), Armor(Belt): Item("common.items.armor.warlord.belt"),
"hands": Item("common.items.armor.warlord.hand"), Armor(Hands): Item("common.items.armor.warlord.hand"),
"pants": Item("common.items.armor.warlord.pants"), Armor(Legs): Item("common.items.armor.warlord.pants"),
"feet": Item("common.items.armor.warlord.foot"), Armor(Feet): Item("common.items.armor.warlord.foot"),
"back": Item("common.items.armor.warlord.back"), Armor(Back): Item("common.items.armor.warlord.back"),
"lantern": Choice([ Lantern: Choice([
(1.0, Some(Item("common.items.lantern.black_0"))), (1.0, Some(Item("common.items.lantern.black_0"))),
(2.0, None), (2.0, None),
]), ]),
"glider": Item("common.items.glider.glider_purp"), Glider: Item("common.items.glider.glider_purp"),
}) })

View File

@ -1,12 +1,12 @@
({ ({
"shoulder": Item("common.items.armor.leather_plate.shoulder"), Armor(Shoulders): Item("common.items.armor.leather_plate.shoulder"),
"chest": Item("common.items.armor.leather_plate.chest"), Armor(Chest): Item("common.items.armor.leather_plate.chest"),
"belt": Item("common.items.armor.leather_plate.belt"), Armor(Belt): Item("common.items.armor.leather_plate.belt"),
"hands": Item("common.items.armor.leather_plate.hand"), Armor(Hands): Item("common.items.armor.leather_plate.hand"),
"pants": Item("common.items.armor.leather_plate.pants"), Armor(Legs): Item("common.items.armor.leather_plate.pants"),
"feet": Item("common.items.armor.leather_plate.foot"), Armor(Feet): Item("common.items.armor.leather_plate.foot"),
"lantern": Choice([ Lantern: Choice([
(1.0, Some(Item("common.items.lantern.black_0"))), (1.0, Some(Item("common.items.lantern.black_0"))),
(2.0, None), (2.0, None),
]), ]),

View File

@ -1,13 +1,13 @@
({ ({
"shoulder": Item("common.items.armor.twigsflowers.shoulder"), Armor(Shoulders): Item("common.items.armor.twigsflowers.shoulder"),
"chest": Item("common.items.armor.twigsflowers.chest"), Armor(Chest): Item("common.items.armor.twigsflowers.chest"),
"hands": Item("common.items.armor.twigsflowers.hand"), Armor(Hands): Item("common.items.armor.twigsflowers.hand"),
"pants": Item("common.items.armor.twigsflowers.pants"), Armor(Legs): Item("common.items.armor.twigsflowers.pants"),
"feet": Item("common.items.armor.twigsflowers.foot"), Armor(Feet): Item("common.items.armor.twigsflowers.foot"),
"belt": Item("common.items.armor.twigsflowers.belt"), Armor(Belt): Item("common.items.armor.twigsflowers.belt"),
"lantern": Item("common.items.lantern.black_0"), Lantern: Item("common.items.lantern.black_0"),
"neck": Item("common.items.armor.misc.neck.plain_1"), Armor(Neck): Item("common.items.armor.misc.neck.plain_1"),
"ring1": Item("common.items.armor.misc.ring.gold"), Armor(Ring1): Item("common.items.armor.misc.ring.gold"),
"ring2": Item("common.items.armor.misc.ring.gold"), Armor(Ring2): Item("common.items.armor.misc.ring.gold"),
}) })

View File

@ -1,5 +1,5 @@
({ ({
"chest": Choice([ Armor(Chest): Choice([
(1.0, Some(Item("common.items.armor.misc.chest.worker_green_0"))), (1.0, Some(Item("common.items.armor.misc.chest.worker_green_0"))),
(1.0, Some(Item("common.items.armor.misc.chest.worker_green_1"))), (1.0, Some(Item("common.items.armor.misc.chest.worker_green_1"))),
(1.0, Some(Item("common.items.armor.misc.chest.worker_red_0"))), (1.0, Some(Item("common.items.armor.misc.chest.worker_red_0"))),
@ -12,10 +12,10 @@
(1.0, Some(Item("common.items.armor.misc.chest.worker_orange_1"))), (1.0, Some(Item("common.items.armor.misc.chest.worker_orange_1"))),
]), ]),
"belt": Item("common.items.armor.swift.belt"), Armor(Belt): Item("common.items.armor.swift.belt"),
"pants": Item("common.items.armor.misc.pants.worker_blue"), Armor(Legs): Item("common.items.armor.misc.pants.worker_blue"),
"feet": Choice([ Armor(Feet): Choice([
(1.0, Some(Item("common.items.armor.swift.foot"))), (1.0, Some(Item("common.items.armor.swift.foot"))),
(1.0, Some(Item("common.items.armor.misc.foot.sandals"))), (1.0, Some(Item("common.items.armor.misc.foot.sandals"))),
]), ]),

View File

@ -401,9 +401,9 @@ impl LoadoutBuilder {
loadout = loadout.glider(Some(item)); loadout = loadout.glider(Some(item));
}, },
EquipSlot::Armor(slot @ ArmorSlot::Bag1) EquipSlot::Armor(slot @ ArmorSlot::Bag1)
| EquipSlot::Armor(slot @ ArmorSlot::Bag2) | EquipSlot::Armor(slot @ ArmorSlot::Bag2)
| EquipSlot::Armor(slot @ ArmorSlot::Bag3) | EquipSlot::Armor(slot @ ArmorSlot::Bag3)
| EquipSlot::Armor(slot @ ArmorSlot::Bag4) => { | EquipSlot::Armor(slot @ ArmorSlot::Bag4) => {
loadout = loadout.bag(slot, Some(item)); loadout = loadout.bag(slot, Some(item));
}, },
}; };
@ -760,16 +760,16 @@ impl LoadoutBuilder {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::comp::{self, Body}; use crate::{
assets::{AssetExt, Error},
comp::{self, Body},
};
use rand::thread_rng; use rand::thread_rng;
use strum::IntoEnumIterator; use strum::IntoEnumIterator;
// Testing all configs in loadout with weapons of different toolkinds // Testing all configs in loadout with weapons of different toolkinds
// //
// Things that will be catched - invalid assets paths // Things that will be catched - invalid assets paths
// FIXME: if item is used in some branch of rng test may miss it
// TODO: as of now there is no rng generation of items.
// Validate assets for all possible branches
#[test] #[test]
fn test_loadout_configs() { fn test_loadout_configs() {
let test_weapons = vec![ let test_weapons = vec![
@ -852,5 +852,62 @@ mod tests {
} }
#[test] #[test]
fn test_loadout_assets() { LoadoutBuilder::from_asset_expect("common.loadouts.test"); } fn test_loadout_asset() { LoadoutBuilder::from_asset_expect("common.loadouts.test"); }
#[test]
fn test_all_loadout_assets() {
#[derive(Clone)]
struct LoadoutsList(Vec<LoadoutSpec>);
impl assets::Compound for LoadoutsList {
fn load<S: assets::source::Source>(
cache: &assets::AssetCache<S>,
specifier: &str,
) -> Result<Self, Error> {
let list = cache
.load::<assets::Directory>(specifier)?
.read()
.iter()
.map(|spec| LoadoutSpec::load_cloned(spec))
.collect::<Result<_, Error>>()?;
Ok(LoadoutsList(list))
}
}
// It just load everything that could
// TODO: add some checks, e.g. that Armor(Head) key correspond
// to Item with ItemKind Head(_)
fn validate_asset(loadout: LoadoutSpec) {
let spec = loadout.0.clone();
for (key, specifier) in spec {
match specifier {
ItemSpec::Item(specifier) => {
Item::new_from_asset_expect(&specifier);
},
ItemSpec::Choice(ref items) => {
for item in items {
match item {
(_, Some(ItemSpec::Item(specifier))) => {
Item::new_from_asset_expect(&specifier);
},
(_, None) => {},
(_, _) => {
panic!(
"\n\nChoice of Choice is unimplemented. (Search for \n{:?}: \
{:#?})\n\n",
key, specifier,
);
},
};
}
},
};
}
}
let loadouts = LoadoutsList::load_expect_cloned("common.loadouts.*").0;
for loadout in loadouts {
validate_asset(loadout);
}
}
} }