horizon-items: tests load prepared items without the client's Assets

#2038's bundle tooltip tests and #2037's loot tests share one helper that
reads the block registry and facts directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-26 15:59:37 +01:00
parent f56bf1ba38
commit 775e5b19cb
2 changed files with 19 additions and 26 deletions
+1 -8
View File
@@ -322,14 +322,7 @@ mod tooltip_tests {
/// The prepared resources, when they are on this machine: the tooltip
/// asks the item registry whether a stack is a bundle.
fn items() -> Option<Items> {
let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../.local/horizon-client/26.3");
if !root.join("items.json").exists() {
return None;
}
let assets = crate::assets::Assets::load(&root).ok()?;
let facts = crate::blocks::BlockFacts::load(&root, assets.registry).ok()?;
Items::load(&root, assets.registry, &facts).ok()
crate::items::prepared_items()
}
fn bundle_with(counts: &[(&str, u32)]) -> ItemStack {
+18 -18
View File
@@ -1619,6 +1619,22 @@ mod bucket_use_tests {
}
}
/// The items of the prepared resources, when they are on this machine, for
/// tests: the block registry and facts as the client's `Assets::load` reads them.
#[cfg(test)]
pub(crate) fn prepared_items() -> Option<Items> {
let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../.local/horizon-client/26.3");
if !root.join("items.json").exists() {
return None;
}
let (registry, _) =
BlockRegistry::from_facts_json_with_flags(fs::File::open(root.join("facts.json")).ok()?)
.ok()?;
let facts = BlockFacts::load(&root, &registry).ok()?;
Items::load(&root, &registry, &facts).ok()
}
#[cfg(test)]
mod tests {
use super::*;
@@ -1641,22 +1657,6 @@ mod tests {
}
}
/// The items of the prepared resources, when they are on this machine
/// (the block registry and facts as the client's `Assets::load` reads them).
fn prepared_items() -> Option<Items> {
let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../.local/horizon-client/26.3");
if !root.join("items.json").exists() {
return None;
}
let (registry, _) = BlockRegistry::from_facts_json_with_flags(
std::fs::File::open(root.join("facts.json")).ok()?,
)
.ok()?;
let facts = BlockFacts::load(&root, &registry).ok()?;
Items::load(&root, &registry, &facts).ok()
}
#[test]
fn fortune_silk_touch_and_looting() {
let items = Items::for_tests(HashMap::new());
@@ -1746,7 +1746,7 @@ mod tests {
/// `EnchantRandomlyFunction`) put their enchantments on the stack.
#[test]
fn loot_enchant_functions_enchant_the_rolled_item() {
let Some(items) = prepared_items() else {
let Some(items) = super::prepared_items() else {
return;
};
let props = BTreeMap::new();
@@ -1807,7 +1807,7 @@ mod tests {
/// Mending book, then `set_count` uniform 1..64, is 46.
#[test]
fn a_single_level_enchantment_draws_no_level() {
let Some(items) = prepared_items() else {
let Some(items) = super::prepared_items() else {
return;
};
let props = BTreeMap::new();