Skip to content

Commit

Permalink
Add field type migration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Procyonae committed Jun 12, 2024
1 parent d961d99 commit e36ac14
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
7 changes: 7 additions & 0 deletions data/mods/TEST_DATA/field_type_migrations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"type": "field_type_migration",
"from_field": "test_fd_migration_old_id",
"to_field": "test_fd_migration_new_id"
}
]
5 changes: 5 additions & 0 deletions data/mods/TEST_DATA/fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,10 @@
"display_items": false,
"display_field": true,
"looks_like": "fd_fog"
},
{
"id": "test_fd_migration_new_id",
"type": "field_type",
"intensity_levels": [ { "name": "migrated" } ]
}
]
56 changes: 53 additions & 3 deletions tests/submap_load_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
static const construction_str_id construction_constr_ground_cable( "constr_ground_cable" );
static const construction_str_id construction_constr_rack_coat( "constr_rack_coat" );

static const field_type_str_id field_test_fd_migration_new_id( "test_fd_migration_new_id" );

static const furn_str_id furn_f_bookcase( "f_bookcase" );
static const furn_str_id furn_f_coffin_c( "f_coffin_c" );
static const furn_str_id furn_f_crate_o( "f_crate_o" );
Expand Down Expand Up @@ -781,7 +783,7 @@ static std::string submap_cosmetic_ss(
" \"computers\": [ ]\n"
"}\n"
);
static std::string submap_pre_migration_ss(
static std::string submap_ter_furn_pre_migration_ss(
"{\n"
" \"version\": 32,\n"
" \"coordinates\": [ 0, 0, 0 ],\n"
Expand All @@ -804,6 +806,25 @@ static std::string submap_pre_migration_ss(
" \"computers\": [ ]\n"
"}\n"
);
static std::string submap_fd_pre_migration_ss(
"{\n"
" \"version\": 32,\n"
" \"coordinates\": [ 0, 0, 0 ],\n"
" \"turn_last_touched\": 0,\n"
" \"temperature\": 0,\n"
" \"terrain\": [ [ \"t_dirt\", 144 ] ],\n"
" \"radiation\": [ 0, 144 ],\n"
" \"furniture\": [ ],\n"
" \"items\": [ ],\n"
" \"traps\": [ ],\n"
" \"fields\": [ 0, 0, [ \"test_fd_migration_old_id\", 1, 1997 ] ],\n"
" \"cosmetics\": [ ],\n"
" \"spawns\": [ ],\n"
" \"vehicles\": [ ],\n"
" \"partial_constructions\": [ ],\n"
" \"computers\": [ ]\n"
"}\n"
);

static_assert( SEEX == 12, "Reminder to update submap tests when SEEX changes." );
static_assert( SEEY == 12, "Reminder to update submap tests when SEEY changes." );
Expand All @@ -823,7 +844,9 @@ static JsonValue submap_vehicle = json_loader::from_string( submap_vehicle_ss );
static JsonValue submap_construction = json_loader::from_string( submap_construction_ss );
static JsonValue submap_computer = json_loader::from_string( submap_computer_ss );
static JsonValue submap_cosmetic = json_loader::from_string( submap_cosmetic_ss );
static JsonValue submap_pre_migration = json_loader::from_string( submap_pre_migration_ss );
static JsonValue submap_ter_furn_pre_migration = json_loader::from_string(
submap_ter_furn_pre_migration_ss );
static JsonValue submap_fd_pre_migration = json_loader::from_string( submap_fd_pre_migration_ss );

static void load_from_jsin( submap &sm, const JsonValue &jsin )
{
Expand Down Expand Up @@ -1448,7 +1471,7 @@ TEST_CASE( "submap_computer_load", "[submap][load]" )
TEST_CASE( "submap_ter_furn_migration", "[submap][load]" )
{
submap sm;
load_from_jsin( sm, submap_pre_migration );
load_from_jsin( sm, submap_ter_furn_pre_migration );
submap_checks checks;
checks.terrain = false;
checks.furniture = false;
Expand Down Expand Up @@ -1487,3 +1510,30 @@ TEST_CASE( "submap_ter_furn_migration", "[submap][load]" )
REQUIRE( furn_sw == furn_test_f_migration_new_id );
REQUIRE( furn_se == furn_test_f_migration_new_id );
}

TEST_CASE( "submap_fd_migration", "[submap][load]" )
{
submap sm;
load_from_jsin( sm, submap_fd_pre_migration );
submap_checks checks;
checks.fields = false;

REQUIRE( is_normal_submap( sm, checks ) );

const field field_ne = sm.get_field( corner_ne );

// North east corner should have migrated from test_fd_migration_old_id to test_fd_migration_new_id
std::string fields_list;
bool found_field_new_id = false;
int total_fields = 0;
auto it = field_ne.begin();
while( it != field_ne.end() ) {
const field_type_id &type = it->first;
fields_list += type.id().str() + " ";
found_field_new_id |= type == field_test_fd_migration_new_id;
total_fields++;
it++;
}
INFO( string_format( "%d fields found: %s", total_fields, fields_list ) );
REQUIRE( ( found_field_new_id && total_fields == 1 ) );
}

0 comments on commit e36ac14

Please sign in to comment.