Skip to content

Commit

Permalink
Add recipe name tests (+astyle)
Browse files Browse the repository at this point in the history
  • Loading branch information
moxian committed Jan 2, 2025
1 parent 2b14a94 commit 046dca5
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 9 deletions.
25 changes: 25 additions & 0 deletions data/mods/TEST_DATA/items.json
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,31 @@
}
]
},
{
"id": "test_xl_waist_apron_long",
"type": "GENERIC",
"name": { "str": "long waist apron" },
"copy-from": "test_waist_apron_long",
"extend": { "flags": [ "OVERSIZE", "PREFIX_XL" ] },
"//": "the variants are not copy-from'd at the time of writing so let's make some",
"variants": [
{
"id": "generic_apron_cotton",
"name": { "str": "long waist apron" },
"description": "It's colored white, like the ones commonly used by chefs, professional or otherwise.",
"weight": 50,
"append": true
},
{
"id": "pink_apron_cotton",
"name": { "str": "pink long waist apron" },
"description": "It's colored neon pink, commonly used by women or men who like pink.",
"color": "pink",
"weight": 3,
"append": true
}
]
},
{
"id": "test_umbrella",
"type": "GENERIC",
Expand Down
6 changes: 6 additions & 0 deletions data/mods/TEST_DATA/recipes.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@
"autolearn": true,
"using": [ [ "tailoring_cotton_patchwork", 6 ] ]
},
{
"//": "Variant version with XL prefix",
"result": "test_xl_waist_apron_long",
"type": "recipe",
"copy-from": "test_waist_apron_long_pink_apron_cotton"
},
{
"result": "test_200_kcal",
"type": "recipe",
Expand Down
4 changes: 2 additions & 2 deletions src/item_tname.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ constexpr uint64_t base_item_name_bits =
1ULL << static_cast<size_t>( tname::segments::TYPE ) |
1ULL << static_cast<size_t>( tname::segments::CUSTOM_ITEM_SUFFIX );
constexpr uint64_t variant_bits =
1ULL << static_cast<size_t>(tname::segments::VARIANT);
1ULL << static_cast<size_t>( tname::segments::VARIANT );
constexpr segment_bitset default_tname( default_tname_bits );
constexpr segment_bitset unprefixed_tname( default_tname_bits & ~tname_prefix_bits );
constexpr segment_bitset tname_sort_key( default_tname_bits & ~tname_unsortable_bits );
Expand All @@ -127,7 +127,7 @@ constexpr segment_bitset tname_conditional( tname_conditional_bits );
// For example in the sentence "To make some 'XL socks' I will need to cut up a 'blanket'",
// when we don't care which color (read: variant) 'XL socks' we want or 'blanket' we have.
constexpr segment_bitset base_item_name( base_item_name_bits );
// Name of a specific item in the game world, carries the item identity, and will not
// Name of a specific item in the game world, carries the item identity, and will not
// change in a normal playthrough except through exordinary means (e.g. via `iuse_transform`).
// E.g. "XL green socks" (notably, not "|. XL green socks (filthy)")
constexpr segment_bitset item_identity_name( base_item_name_bits | variant_bits );
Expand Down
2 changes: 1 addition & 1 deletion src/recipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ std::string recipe::result_name( const bool decorated ) const
// As of 2025-01-01 there's no better way around this.
item temp_item( result_ );
// Use generic item name by default.
tname::segment_bitset segs = tname::base_item_name;
tname::segment_bitset segs = tname::base_item_name;
if( !variant().empty() ) {
// ..but if the recipe calls for a specific varaint - then use that variant.
// Note that `temp_item` is likely to already have a random variant set at the time of creation.
Expand Down
24 changes: 18 additions & 6 deletions tests/crafting_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ static const recipe_id recipe_test_tallow2( "test_tallow2" );
static const recipe_id recipe_test_waist_apron_long( "test_waist_apron_long" );
static const recipe_id
recipe_test_waist_apron_long_pink_apron_cotton( "test_waist_apron_long_pink_apron_cotton" );
static const recipe_id
recipe_test_xl_waist_apron_long_pink_apron_cotton( "test_xl_waist_apron_long_pink_apron_cotton" );
static const recipe_id recipe_vambrace_larmor( "vambrace_larmor" );
static const recipe_id recipe_water_clean( "water_clean" );

Expand Down Expand Up @@ -2247,11 +2249,12 @@ TEST_CASE( "variant_crafting_recipes", "[crafting][slow]" )
tools.emplace_back( "scissors" );
tools.insert( tools.end(), 10, item( "sheet_cotton" ) );
tools.insert( tools.end(), 10, item( "thread" ) );
prep_craft( recipe_test_waist_apron_long, tools, true );
actually_test_craft( recipe_test_waist_apron_long, INT_MAX, 10 );
const recipe_id apron_recipe = recipe_test_waist_apron_long;
prep_craft( apron_recipe, tools, true );
actually_test_craft( apron_recipe, INT_MAX, 10 );
item_location apron = player_character.get_wielded_item();

REQUIRE( apron->type->get_id() == recipe_test_waist_apron_long->result() );
REQUIRE( apron->type->get_id() == apron_recipe->result() );
REQUIRE( apron->has_itype_variant() );

if( variant_counts.count( apron->itype_variant().id ) == 0 ) {
Expand All @@ -2275,11 +2278,12 @@ TEST_CASE( "variant_crafting_recipes", "[crafting][slow]" )
tools.emplace_back( "scissors" );
tools.insert( tools.end(), 10, item( "sheet_cotton" ) );
tools.insert( tools.end(), 10, item( "thread" ) );
prep_craft( recipe_test_waist_apron_long_pink_apron_cotton, tools, true );
actually_test_craft( recipe_test_waist_apron_long_pink_apron_cotton, INT_MAX, 10 );
const recipe_id apron_recipe = recipe_test_xl_waist_apron_long_pink_apron_cotton;
prep_craft( apron_recipe, tools, true );
actually_test_craft( apron_recipe, INT_MAX, 10 );
item_location apron = player_character.get_wielded_item();

REQUIRE( apron->type->get_id() == recipe_test_waist_apron_long_pink_apron_cotton->result() );
REQUIRE( apron->type->get_id() == apron_recipe->result() );
REQUIRE( apron->has_itype_variant() );

if( apron->itype_variant().id == "pink_apron_cotton" ) {
Expand All @@ -2288,6 +2292,14 @@ TEST_CASE( "variant_crafting_recipes", "[crafting][slow]" )
}
CHECK( specific_variant_count == max_iters );
}
SECTION( "recipe names" ) {
const recipe_id basic_recipe = recipe_test_waist_apron_long;
CHECK( basic_recipe.obj().result_name() == "long waist apron" );
const recipe_id variant_recipe = recipe_test_waist_apron_long_pink_apron_cotton;
CHECK( variant_recipe.obj().result_name() == "pink long waist apron" );
const recipe_id variant_prefix_recipe = recipe_test_xl_waist_apron_long_pink_apron_cotton;
CHECK( variant_prefix_recipe.obj().result_name() == "XL pink long waist apron" );
}
}

TEST_CASE( "pseudo_tools_in_crafting_inventory", "[crafting][tools]" )
Expand Down

0 comments on commit 046dca5

Please sign in to comment.