From b93d4bf85ce9f221706a6a06d941c86946dbe47a Mon Sep 17 00:00:00 2001 From: David Fisher Date: Sun, 15 Nov 2020 18:53:20 -0500 Subject: [PATCH] Add simple tests to utils description functions I initially ended up in this file looking to take on issue #707 which I realized had been already done. Having touched the file though I thought it good to add some basic tests to get used to the workflow on the project and how things are setup here. This commit adds some basic requests and cleans up some comments which appear to have been left as placeholders for work which appears to have been completed already. I attempted to test the tool_desc and armor_desc functions, but realized I wasn't sure how to best create an instance of Armor or Tool without modifying other files to make more things public. This is my first commit on the project, and was intentionally kept simple accordingly. --- voxygen/src/hud/util.rs | 78 ++++++++++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 16 deletions(-) diff --git a/voxygen/src/hud/util.rs b/voxygen/src/hud/util.rs index 268a628c48..2464663704 100644 --- a/voxygen/src/hud/util.rs +++ b/voxygen/src/hud/util.rs @@ -34,6 +34,7 @@ pub fn item_text<'a>(item: &'a impl ItemDesc) -> (&'_ str, Cow<'a, str>) { (item.name(), desc) } +// TODO: localization fn glider_desc(desc: &str) -> String { format!("Glider\n\n{}\n\n", desc) } fn consumable_desc(desc: &str) -> String { @@ -50,7 +51,6 @@ fn ingredient_desc(desc: &str) -> String { format!("Crafting Ingredient\n\n{}", fn lantern_desc(desc: &str) -> String { format!("Lantern\n\n{}\n\n", desc) } -// Armor Description fn armor_desc(armor: &Armor, desc: &str) -> String { // TODO: localization let kind = match armor.kind { @@ -80,9 +80,8 @@ fn armor_desc(armor: &Armor, desc: &str) -> String { format!("{}\n\nArmor: {}\n\n", kind, armor) } } -// Weapon/Tool Description + fn tool_desc(tool: &Tool, desc: &str) -> String { - // TODO: localization let kind = match tool.kind { ToolKind::Sword => "Sword", ToolKind::Axe => "Axe", @@ -117,21 +116,68 @@ fn tool_desc(tool: &Tool, desc: &str) -> String { ) } } -// Consumable Description -/*fn consumable_desc(consumable: Consumable, desc: &str) -> String { - // TODO: localization - let kind = "Consumable"; - if !desc.is_empty() { - format!("{}\n\n{}\n\n", kind, desc) - } else { - format!("{}\n\n", kind) + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_glider_desc() { + let item_description = "mushrooms"; + + assert_eq!( + "Glider\n\nmushrooms\n\n", + glider_desc(item_description) + ); } -}*/ -// Throwable Description + #[test] + fn test_consumable_desc() { + let item_description = "mushrooms"; -// Utility Description + assert_eq!( + "Consumable\n\nmushrooms\n\n", + consumable_desc(item_description) + ); + } -// Ingredient Description + #[test] + fn test_throwable_desc() { + let item_description = "mushrooms"; -// Lantern Description + assert_eq!( + "Can be thrown\n\nmushrooms\n\n", + throwable_desc(item_description) + ); + } + + #[test] + fn test_utility_desc() { + let item_description = "mushrooms"; + + assert_eq!( + "mushrooms\n\n", + utility_desc(item_description) + ); + } + + #[test] + fn test_ingredient_desc() { + let item_description = "mushrooms"; + + assert_eq!( + "Crafting Ingredient\n\nmushrooms", + ingredient_desc(item_description) + ); + } + + #[test] + fn test_lantern_desc() { + let item_description = "mushrooms"; + + assert_eq!( + "Lantern\n\nmushrooms\n\n", + lantern_desc(item_description) + ); + } +}