use serde::Deserialize;
const MATRIX_JSON: &str = include_str!("../resources/compatibility-matrix.json");
#[derive(Debug, Deserialize)]
struct MatrixRoot {
#[allow(
dead_code,
reason = "Deserialized for validation, not yet used at runtime"
)]
schema_version: u32,
#[allow(
dead_code,
reason = "Deserialized for validation, not yet used at runtime"
)]
updated_at: String,
platforms: Vec<PlatformCompat>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct PlatformCompat {
pub name: String,
pub identifier: String,
pub cli_binary: String,
pub min_version: String,
pub tested_versions: Vec<String>,
pub install_url: String,
pub doc_link: String,
}
#[must_use]
#[allow(
clippy::expect_used,
reason = "Embedded JSON is compile-time data; parse failure means corrupted build artifacts"
)]
pub fn platform_compatibility() -> Vec<PlatformCompat> {
let root: MatrixRoot =
serde_json::from_str(MATRIX_JSON).expect("embedded compatibility-matrix.json is invalid");
root.platforms
}
#[must_use]
pub fn platform_requirement(identifier: &str) -> Option<PlatformCompat> {
platform_compatibility()
.into_iter()
.find(|p| p.identifier == identifier)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_should_load_all_three_platforms() {
let platforms = platform_compatibility();
assert_eq!(platforms.len(), 3);
}
#[test]
fn test_should_return_github_requirement() {
let gh = platform_requirement("github").expect("github should exist");
assert_eq!(gh.cli_binary, "gh");
assert_eq!(gh.min_version, "2.0.0");
assert!(!gh.install_url.is_empty());
assert!(!gh.doc_link.is_empty());
}
#[test]
fn test_should_return_gitcode_min_version_0_6() {
let gc = platform_requirement("gitcode").expect("gitcode should exist");
assert_eq!(gc.min_version, "0.6.0");
}
#[test]
fn test_should_return_none_for_unknown_platform() {
assert!(platform_requirement("bitbucket").is_none());
}
}