use nap_core::server::{LoreVersionInfo, PINNED_LORE_VERSION, check_lore_compatibility};
use semver::Version;
const EXPECTED_PINNED_VERSION: &str = "0.8.4-portals.9";
fn make_version_info(raw: &str, major: u64, minor: u64, patch: u64) -> LoreVersionInfo {
LoreVersionInfo {
parsed: Version::new(major, minor, patch),
raw: raw.to_string(),
}
}
#[test]
fn pinned_version_constant_matches_expected() {
assert_eq!(
PINNED_LORE_VERSION, EXPECTED_PINNED_VERSION,
"PINNED_LORE_VERSION has changed! Update EXPECTED_PINNED_VERSION \
in this test file if the change is intentional."
);
}
#[test]
fn exact_pinned_version_is_compatible() {
let installed = make_version_info("0.8.4-portals.9", 0, 8, 4);
assert!(
check_lore_compatibility(&installed).unwrap(),
"Version '0.8.4-portals.9' should be compatible with pinned version '{}'",
PINNED_LORE_VERSION
);
}
#[test]
fn nightly_version_is_incompatible_with_release_pin() {
let installed = make_version_info("0.8.4-nightly", 0, 8, 4);
assert!(
!check_lore_compatibility(&installed).unwrap(),
"Version '0.8.4-nightly' must NOT be compatible with '{}'",
PINNED_LORE_VERSION
);
}
#[test]
fn stable_channel_is_incompatible_with_release_pin() {
let installed = make_version_info("0.8.4-stable", 0, 8, 4);
assert!(
!check_lore_compatibility(&installed).unwrap(),
"Version '0.8.4-stable' must NOT be compatible with '{}'",
PINNED_LORE_VERSION
);
}
#[test]
fn wrong_semver_is_incompatible() {
let installed = make_version_info("0.9.0", 0, 9, 0);
assert!(
!check_lore_compatibility(&installed).unwrap(),
"Version '0.9.0' must NOT be compatible with '{}'",
PINNED_LORE_VERSION
);
}
#[test]
fn older_version_is_incompatible() {
let installed = make_version_info("0.7.0", 0, 7, 0);
assert!(
!check_lore_compatibility(&installed).unwrap(),
"Version '0.7.0' must NOT be compatible with '{}'",
PINNED_LORE_VERSION
);
}
#[test]
fn release_candidate_is_incompatible_with_release_pin() {
let installed = make_version_info("0.8.4-rc1", 0, 8, 4);
assert!(
!check_lore_compatibility(&installed).unwrap(),
"Version '0.8.4-rc1' must NOT be compatible with '{}'",
PINNED_LORE_VERSION
);
}
#[test]
fn pre_release_suffix_is_incompatible_with_release_pin() {
let installed = make_version_info("0.8.4-pre", 0, 8, 4);
assert!(
!check_lore_compatibility(&installed).unwrap(),
"Version '0.8.4-pre' must NOT be compatible with '{}'",
PINNED_LORE_VERSION
);
}
#[test]
fn newer_version_is_incompatible() {
let installed = make_version_info("0.9.0", 0, 9, 0);
assert!(
!check_lore_compatibility(&installed).unwrap(),
"Version '0.9.0' must NOT be compatible with '{}'",
PINNED_LORE_VERSION
);
}
#[test]
fn version_info_preserves_raw_and_parsed() {
let info = make_version_info("0.8.4-portals.9", 0, 8, 4);
assert_eq!(info.raw, "0.8.4-portals.9");
assert_eq!(info.parsed, Version::new(0, 8, 4));
}
#[test]
fn version_info_display_shows_raw() {
let info = make_version_info("0.8.4-portals.9", 0, 8, 4);
assert_eq!(format!("{}", info), "0.8.4-portals.9");
}