use nap_core::server::{LoreVersionInfo, PINNED_LORE_VERSION, check_lore_compatibility};
use semver::Version;
const EXPECTED_PINNED_VERSION: &str = "0.8.5-nightly";
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_nightly_version_is_compatible() {
let installed = make_version_info("0.8.5-nightly", 0, 8, 5);
assert!(
check_lore_compatibility(&installed).unwrap(),
"Version '0.8.5-nightly' should be compatible with pinned version '{}'",
PINNED_LORE_VERSION
);
}
#[test]
fn bare_version_without_suffix_is_incompatible() {
let installed = make_version_info("0.8.5", 0, 8, 5);
assert!(
!check_lore_compatibility(&installed).unwrap(),
"Version '0.8.5' (no suffix) must NOT be compatible with '{}'",
PINNED_LORE_VERSION
);
}
#[test]
fn stable_channel_is_incompatible_with_nightly_pin() {
let installed = make_version_info("0.8.5-stable", 0, 8, 5);
assert!(
!check_lore_compatibility(&installed).unwrap(),
"Version '0.8.5-stable' must NOT be compatible with '{}'",
PINNED_LORE_VERSION
);
}
#[test]
fn wrong_semver_is_incompatible() {
let installed = make_version_info("0.9.0-nightly", 0, 9, 0);
assert!(
!check_lore_compatibility(&installed).unwrap(),
"Version '0.9.0-nightly' must NOT be compatible with '{}'",
PINNED_LORE_VERSION
);
}
#[test]
fn older_version_is_incompatible() {
let installed = make_version_info("0.7.0-nightly", 0, 7, 0);
assert!(
!check_lore_compatibility(&installed).unwrap(),
"Version '0.7.0-nightly' must NOT be compatible with '{}'",
PINNED_LORE_VERSION
);
}
#[test]
fn release_candidate_is_incompatible_with_nightly_pin() {
let installed = make_version_info("0.8.5-rc1", 0, 8, 5);
assert!(
!check_lore_compatibility(&installed).unwrap(),
"Version '0.8.5-rc1' must NOT be compatible with '{}'",
PINNED_LORE_VERSION
);
}
#[test]
fn pre_release_suffix_is_incompatible_with_nightly_pin() {
let installed = make_version_info("0.8.5-pre", 0, 8, 5);
assert!(
!check_lore_compatibility(&installed).unwrap(),
"Version '0.8.5-pre' must NOT be compatible with '{}'",
PINNED_LORE_VERSION
);
}
#[test]
fn newer_version_is_incompatible() {
let installed = make_version_info("0.9.0-nightly", 0, 9, 0);
assert!(
!check_lore_compatibility(&installed).unwrap(),
"Version '0.9.0-nightly' must NOT be compatible with '{}'",
PINNED_LORE_VERSION
);
}
#[test]
fn version_info_preserves_raw_and_parsed() {
let info = make_version_info("0.8.5-nightly", 0, 8, 5);
assert_eq!(info.raw, "0.8.5-nightly");
assert_eq!(info.parsed, Version::new(0, 8, 5));
}
#[test]
fn version_info_display_shows_raw() {
let info = make_version_info("0.8.5-nightly", 0, 8, 5);
assert_eq!(format!("{}", info), "0.8.5-nightly");
}