#[derive(Debug, Clone)]
pub struct VersionInfo {
pub major: u32,
pub minor: u32,
pub patch: u32,
pub label: String,
}
impl VersionInfo {
pub fn new(major: u32, minor: u32, patch: u32, label: impl Into<String>) -> Self {
Self {
major,
minor,
patch,
label: label.into(),
}
}
pub fn version_string(&self) -> String {
format!("{}.{}.{}", self.major, self.minor, self.patch)
}
pub fn full_version_string(&self) -> String {
format!("{}-{}", self.version_string(), self.label)
}
}
pub fn get_current_version() -> VersionInfo {
VersionInfo::new(0, 15, 0, "dev")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_version_info() {
let version = VersionInfo::new(1, 2, 3, "stable");
assert_eq!(version.version_string(), "1.2.3");
assert_eq!(version.full_version_string(), "1.2.3-stable");
}
#[test]
fn test_current_version() {
let current = get_current_version();
assert_eq!(current.major, 0);
assert_eq!(current.minor, 15);
assert_eq!(current.patch, 0);
assert_eq!(current.label, "dev");
}
}