diff --git a/tests/iteminfo_test.cpp b/tests/iteminfo_test.cpp index 3d9adb4f45aec..d6afa98c423a8 100644 --- a/tests/iteminfo_test.cpp +++ b/tests/iteminfo_test.cpp @@ -7,6 +7,7 @@ #include "game.h" #include "item.h" #include "iteminfo_query.h" +#include "recipe_dictionary.h" static void iteminfo_test( const item &i, const iteminfo_query &q, const std::string &reference ) { @@ -100,42 +101,84 @@ TEST_CASE( "nutrient_ranges_for_recipe_exemplars", "[item][iteminfo]" ) "Vitamin A (3-11%), Vitamin B12 (2-6%), and Vitamin C (1-85%)\n" ); } -TEST_CASE( "show_available_recipes_using_item", "[item][iteminfo]" ) +TEST_CASE( "show available recipes with item as an ingredient", "[item][iteminfo][recipes]" ) { iteminfo_query q( { iteminfo_parts::DESCRIPTION_APPLICABLE_RECIPES } ); + const recipe *crowbar = &recipe_id( "makeshift_crowbar" ).obj(); + const recipe *purtab = &recipe_id( "pur_tablets" ).obj(); + g->u.empty_skills(); - GIVEN( "a character with no cooking skill" ) { - avatar character; - const recipe *pur = &recipe_id( "pur_tablets" ).obj(); + GIVEN( "character has a pipe and no skill" ) { + item &pipe = g->u.i_add( item( "pipe" ) ); - REQUIRE( character.get_skill_level( pur->skill_used ) == 0 ); - REQUIRE_FALSE( character.knows_recipe( pur ) ); + REQUIRE( g->u.get_skill_level( crowbar->skill_used ) == 0 ); - WHEN( "they have potassium iodide tablets in their inventory" ) { - item &iodine = character.i_add( item( "iodine" ) ); + THEN( "they can craft a makeshift crowbar from it" ) { + iteminfo_test( + pipe, q, + "--\nYou could use it to craft: makeshift crowbar\n" ); + } + } + + GIVEN( "character has potassium iodide tablets" ) { + item &iodine = g->u.i_add( item( "iodine" ) ); + + WHEN( "they don't have skills or recipes" ) { + g->u.set_skill_level( purtab->skill_used, 0 ); + + REQUIRE( g->u.get_skill_level( purtab->skill_used ) == 0 ); + REQUIRE_FALSE( g->u.get_available_recipes( g->u.crafting_inventory() ).contains( purtab ) ); THEN( "nothing is craftable from it" ) { - std::vector info_v; - std::string info = iodine.info( info_v, &q, 1 ); - CHECK( info == "--\nYou know of nothing you could craft with it.\n" ); + iteminfo_test( + iodine, q, + "--\nYou know of nothing you could craft with it.\n" ); + } + } + + AND_WHEN( "they acquire the needed skill" ) { + g->u.set_skill_level( purtab->skill_used, purtab->difficulty ); + + REQUIRE( g->u.get_skill_level( purtab->skill_used ) == purtab->difficulty ); + REQUIRE_FALSE( g->u.get_available_recipes( g->u.crafting_inventory() ).contains( purtab ) ); + + THEN( "still nothing is craftable from it" ) { + iteminfo_test( + iodine, q, + "--\nYou know of nothing you could craft with it.\n" ); } - AND_WHEN( "they have the water purification tablet recipe memorized" ) { - item &textbook = character.i_add( item( "textbook_chemistry" ) ); - character.set_skill_level( pur->skill_used, pur->difficulty + 1 ); - character.learn_recipe( pur ); - REQUIRE( character.knows_recipe( pur ) ); + WHEN( "they have no book, but have the recipe memorized" ) { + g->u.learn_recipe( purtab ); + + REQUIRE( g->u.knows_recipe( purtab ) ); + REQUIRE( g->u.get_available_recipes( g->u.crafting_inventory() ).contains( purtab ) ); THEN( "they can use potassium iodide tablets to craft it" ) { - std::vector info_v; - std::string info = iodine.info( info_v, &q, 1 ); - CHECK( info == "--\n" - "You could use it to craft: " - "water purification tablet\n" ); + iteminfo_test( + iodine, q, + "--\n" + "You could use it to craft: " + "water purification tablet\n" ); } } - } + WHEN( "they have the recipe in a book, but not memorized" ) { + item &book = g->u.i_add( item( "textbook_chemistry" ) ); + g->u.do_read( book ); + + REQUIRE_FALSE( g->u.knows_recipe( purtab ) ); + REQUIRE( g->u.get_available_recipes( g->u.crafting_inventory() ).contains( purtab ) ); + + THEN( "they can use potassium iodide tablets to craft it" ) { + iteminfo_test( + iodine, q, + "--\n" + "You could use it to craft: " + "water purification tablet\n" ); + } + } + } } }