Skip to content

Commit

Permalink
Stop iteminfo test from failing w/ mod damage type
Browse files Browse the repository at this point in the history
When mods add additional damage types, additional data is added to the
iteminfo strings, making testing for the whole string fail. But we can
instead test for the specific damage types and the coverage header that
we're testing for, and the test will no longer fail with additional
damage types.
  • Loading branch information
ehughsbaird committed Jul 27, 2024
1 parent f3bcc4d commit c1297b9
Showing 1 changed file with 88 additions and 52 deletions.
140 changes: 88 additions & 52 deletions tests/iteminfo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2961,7 +2961,7 @@ TEST_CASE( "item_debug_info", "[iteminfo][debug][!mayfail][.]" )
}
}

TEST_CASE( "Armor_values_preserved_after_copy-from", "[iteminfo][armor][protection][!mayfail]" )
TEST_CASE( "Armor_values_preserved_after_copy-from", "[iteminfo][armor][protection]" )
{
// Normal item definition, no copy
item armor( itype_test_armor_chitin );
Expand All @@ -2988,55 +2988,91 @@ TEST_CASE( "Armor_values_preserved_after_copy-from", "[iteminfo][armor][protecti
std::string a_copy_rel_str = item_info_str( armor_copy_rel, infoparts );
std::string a_copy_w_armor_rel_str = item_info_str( armor_copy_w_armor_rel, infoparts );

const std::string info_str =
"--\n"
"<color_c_white>Protection for</color>: The <color_c_cyan>legs</color>. The <color_c_cyan>torso</color>.\n"
"<color_c_white>Coverage</color>: <color_c_light_blue>Outer</color>.\n"
" Default: <color_c_yellow>90</color>\n"
"<color_c_white>Protection</color>:\n"
" Bash: <color_c_yellow>10.00</color>\n"
" Cut: <color_c_yellow>16.00</color>\n"
" Ballistic: <color_c_yellow>5.60</color>\n"
" Pierce: <color_c_yellow>12.80</color>\n"
" Acid: <color_c_yellow>3.60</color>\n"
" Fire: <color_c_yellow>1.50</color>\n"
" Environmental: <color_c_yellow>6</color>\n";

CHECK( a_str == info_str );
CHECK( a_copy_str == info_str );
CHECK( a_copy_w_armor_str == info_str );

const std::string info_prop_str =
"--\n"
"<color_c_white>Protection for</color>: The <color_c_cyan>legs</color>. The <color_c_cyan>torso</color>.\n"
"<color_c_white>Coverage</color>: <color_c_light_blue>Outer</color>.\n"
" Default: <color_c_yellow>90</color>\n"
"<color_c_white>Protection</color>:\n"
" Bash: <color_c_yellow>12.00</color>\n"
" Cut: <color_c_yellow>19.20</color>\n"
" Ballistic: <color_c_yellow>6.72</color>\n"
" Pierce: <color_c_yellow>15.36</color>\n"
" Acid: <color_c_yellow>4.20</color>\n"
" Fire: <color_c_yellow>1.75</color>\n"
" Environmental: <color_c_yellow>7</color>\n";

CHECK( a_copy_prop_str == info_prop_str );
CHECK( a_copy_w_armor_prop_str == info_prop_str );

const std::string info_rel_str =
"--\n"
"<color_c_white>Protection for</color>: The <color_c_cyan>legs</color>. The <color_c_cyan>torso</color>.\n"
"<color_c_white>Coverage</color>: <color_c_light_blue>Outer</color>.\n"
" Default: <color_c_yellow>90</color>\n"
"<color_c_white>Protection</color>:\n"
" Bash: <color_c_yellow>15.00</color>\n"
" Cut: <color_c_yellow>24.00</color>\n"
" Ballistic: <color_c_yellow>8.40</color>\n"
" Pierce: <color_c_yellow>19.20</color>\n"
" Acid: <color_c_yellow>4.80</color>\n"
" Fire: <color_c_yellow>2.00</color>\n"
" Environmental: <color_c_yellow>8</color>\n";

CHECK( a_copy_rel_str == info_rel_str );
CHECK( a_copy_w_armor_rel_str == info_rel_str );
const auto test_string = []( const std::string & info, const std::string & tested ) {
INFO( string_format( "Checking for \"%s\" in:", tested ) );
INFO( info );
CHECK( info.find( tested ) != std::string::npos );
};

const auto copy_from_test = [&test_string]( const std::string & info ) {
const std::string header_string =
"--\n"
"<color_c_white>Protection for</color>: The <color_c_cyan>legs</color>. The <color_c_cyan>torso</color>.\n"
"<color_c_white>Coverage</color>: <color_c_light_blue>Outer</color>.\n"
" Default: <color_c_yellow>90</color>\n"
"<color_c_white>Protection</color>:\n";
const std::string bash_string = " Bash: <color_c_yellow>10.00</color>\n";
const std::string cut_string = " Cut: <color_c_yellow>16.00</color>\n";
const std::string ballistic_string = " Ballistic: <color_c_yellow>5.60</color>\n";
const std::string pierce_string = " Pierce: <color_c_yellow>12.80</color>\n";
const std::string acid_string = " Acid: <color_c_yellow>3.60</color>\n";
const std::string fire_string = " Fire: <color_c_yellow>1.50</color>\n";
const std::string env_string = " Environmental: <color_c_yellow>6</color>\n";

test_string( info, header_string );
test_string( info, bash_string );
test_string( info, cut_string );
test_string( info, ballistic_string );
test_string( info, acid_string );
test_string( info, fire_string );
test_string( info, env_string );
};

copy_from_test( a_str );
copy_from_test( a_copy_str );
copy_from_test( a_copy_w_armor_str );

const auto proportional_test = [&test_string]( const std::string & info ) {
const std::string header_str =
"--\n"
"<color_c_white>Protection for</color>: The <color_c_cyan>legs</color>. The <color_c_cyan>torso</color>.\n"
"<color_c_white>Coverage</color>: <color_c_light_blue>Outer</color>.\n"
" Default: <color_c_yellow>90</color>\n"
"<color_c_white>Protection</color>:\n";
const std::string bash_str = " Bash: <color_c_yellow>12.00</color>\n";
const std::string cut_str = " Cut: <color_c_yellow>19.20</color>\n";
const std::string ballistic_str = " Ballistic: <color_c_yellow>6.72</color>\n";
const std::string pierce_str = " Pierce: <color_c_yellow>15.36</color>\n";
const std::string acid_str = " Acid: <color_c_yellow>4.20</color>\n";
const std::string fire_str = " Fire: <color_c_yellow>1.75</color>\n";
const std::string env_str = " Environmental: <color_c_yellow>7</color>\n";

test_string( info, header_str );
test_string( info, bash_str );
test_string( info, cut_str );
test_string( info, ballistic_str );
test_string( info, acid_str );
test_string( info, fire_str );
test_string( info, env_str );
};

proportional_test( a_copy_prop_str );
proportional_test( a_copy_w_armor_prop_str );

const auto relative_test = [&test_string]( const std::string & info ) {
const std::string header_str =
"--\n"
"<color_c_white>Protection for</color>: The <color_c_cyan>legs</color>. The <color_c_cyan>torso</color>.\n"
"<color_c_white>Coverage</color>: <color_c_light_blue>Outer</color>.\n"
" Default: <color_c_yellow>90</color>\n"
"<color_c_white>Protection</color>:\n";
const std::string bash_str = " Bash: <color_c_yellow>15.00</color>\n";
const std::string cut_str = " Cut: <color_c_yellow>24.00</color>\n";
const std::string ballistic_str = " Ballistic: <color_c_yellow>8.40</color>\n";
const std::string pierce_str = " Pierce: <color_c_yellow>19.20</color>\n";
const std::string acid_str = " Acid: <color_c_yellow>4.80</color>\n";
const std::string fire_str = " Fire: <color_c_yellow>2.00</color>\n";
const std::string env_str = " Environmental: <color_c_yellow>8</color>\n";

test_string( info, header_str );
test_string( info, bash_str );
test_string( info, cut_str );
test_string( info, ballistic_str );
test_string( info, acid_str );
test_string( info, fire_str );
test_string( info, env_str );
};

relative_test( a_copy_rel_str );
relative_test( a_copy_w_armor_rel_str );
}

0 comments on commit c1297b9

Please sign in to comment.