refactored: DRY repetitive test fixtures with owning struct + rstest

Picks up the remaining test-only suggestions from the style audit. No
production code change.

- launch_profile/templates.rs: introduces a Fixture struct that owns
  the four PathBuf inputs (lib/nat/game/assets) and exposes a ctx()
  method. Eight tests that each rebuilt the same context inline now
  collapse into one rstest with eight cases plus two standalone
  tests for the recursive-substitution and Windows-backslash edge
  cases. Net code: ~120 lines saved.

- launch_profile/render.rs: same pattern. Fixture::new() owns the
  paths plus a FeatureSet; ctx() and rule_ctx() expose what every
  test needs. Six tests stop redeclaring four PathBufs + a five-line
  RuleContext literal apiece.

- instance/launch/mod.rs: three installer_version_dir_name tests
  (Forge / NeoForge / non-installer loaders) become one rstest with
  five cases (one per ModLoader variant). A regression that
  misorders the match arms would now fail a specific case, not just
  the catch-all "non-installer" test.

- instance/content/resource_packs.rs: ten extract_description_*
  tests become one rstest with ten cases. Each case still hits a
  distinct match arm (string, object{text}, object{no text}, array
  variants, null, number, bool); the rstest is cosmetic, not a
  consolidation that loses coverage.

Net effect: same coverage, ~250 lines less repetitive test setup,
clearer intent. Test count rises by 2 because rstest expands cases
into separate test functions.
This commit is contained in:
objz committed 2026-05-27 17:35:50 +02:00
1 parent 41d6da8008
commit 8d7a0903fd
4 files changed
+174 -350

No files matched your search

+17 -19
View File
@@ -755,29 +755,27 @@ mod tests {
);
}
#[test]
fn installer_version_dir_name_for_forge() {
// each loader maps to a distinct directory-naming branch. one rstest
// exercises every variant so a regression that misorders the match
// arms in installer_version_dir_name is caught.
#[rstest::rstest]
#[case::forge(ModLoader::Forge, "1.20.1", "47.2.0", Some("1.20.1-forge-47.2.0"))]
#[case::neoforge(ModLoader::NeoForge, "1.21.1", "21.1.0", Some("neoforge-21.1.0"))]
#[case::vanilla(ModLoader::Vanilla, "1.20.1", "v", None)]
#[case::fabric(ModLoader::Fabric, "1.20.1", "0.14.21", None)]
#[case::quilt(ModLoader::Quilt, "1.20.1", "0.20.0", None)]
fn installer_version_dir_name_per_loader(
#[case] loader: ModLoader,
#[case] game_version: &str,
#[case] loader_version: &str,
#[case] expected: Option<&str>,
) {
assert_eq!(
installer_version_dir_name(ModLoader::Forge, "1.20.1", "47.2.0"),
Some("1.20.1-forge-47.2.0".to_string())
installer_version_dir_name(loader, game_version, loader_version),
expected.map(str::to_owned)
);
}
#[test]
fn installer_version_dir_name_for_neoforge() {
assert_eq!(
installer_version_dir_name(ModLoader::NeoForge, "1.21.1", "21.1.0"),
Some("neoforge-21.1.0".to_string())
);
}
#[test]
fn installer_version_dir_name_for_non_installer_loaders() {
assert!(installer_version_dir_name(ModLoader::Vanilla, "1.20.1", "v").is_none());
assert!(installer_version_dir_name(ModLoader::Fabric, "1.20.1", "0.14.21").is_none());
assert!(installer_version_dir_name(ModLoader::Quilt, "1.20.1", "0.20.0").is_none());
}
// exercises the modern-profile early-return in
// migrate_legacy_loader_profile_if_needed. any of inheritsFrom,
// arguments, minecraftArguments present (or game_arguments absent)