From 0a5c23757c2a0fc8784ea1b5a3ad5b0cba0709e0 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 3 May 2025 11:53:50 +0200 Subject: tests in some places --- cache/src/lib.rs | 2 +- common/src/lib.rs | 2 +- import/asset_token/src/lib.rs | 13 ++++++++++++- import/fallback_generator/src/lib.rs | 5 +++++ ui/src/format.rs | 22 ++++++++++++++++++++++ 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/cache/src/lib.rs b/cache/src/lib.rs index 2d31d6c..1154ddf 100644 --- a/cache/src/lib.rs +++ b/cache/src/lib.rs @@ -44,7 +44,7 @@ static CONF: LazyLock = LazyLock::new(|| { .expect("cache config not preloaded. logic error") }); -#[derive(Debug, Encode, Decode, Serialize, Clone)] +#[derive(Debug, Encode, Decode, Serialize, Clone, PartialEq, Eq)] pub struct CachePath(pub PathBuf); impl CachePath { pub fn abs(&self) -> PathBuf { diff --git a/common/src/lib.rs b/common/src/lib.rs index 8993d22..366c514 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -207,7 +207,7 @@ pub enum TrackSource { pub type TrackID = usize; -#[derive(Debug, Clone, Deserialize, Serialize, Hash, Encode, Decode)] +#[derive(Debug, Clone, Deserialize, Serialize, Hash, Encode, Decode, PartialEq, Eq)] pub struct LocalTrack { pub path: PathBuf, pub track: TrackID, diff --git a/import/asset_token/src/lib.rs b/import/asset_token/src/lib.rs index de7d2be..7334076 100644 --- a/import/asset_token/src/lib.rs +++ b/import/asset_token/src/lib.rs @@ -48,7 +48,7 @@ static ASSET_KEY: LazyLock = LazyLock::new(|| { } }); -#[derive(Debug, Encode, Decode, Serialize)] +#[derive(Debug, Encode, Decode, Serialize, PartialEq, Eq)] pub enum AssetInner { Federated { host: String, asset: Vec }, Cache(CachePath), @@ -101,3 +101,14 @@ impl AssetInner { matches!(self, Self::Federated { .. }) } } + +#[test] +fn test_identities() { + *CONF_PRELOAD.lock().unwrap() = Some(Config { asset_key: None }); + + let a = AssetInner::Assets(PathBuf::new()); + let b = a.ser(); + let c = AssetInner::deser(&b.0).unwrap(); + + assert_eq!(a, c) +} diff --git a/import/fallback_generator/src/lib.rs b/import/fallback_generator/src/lib.rs index efb6579..eef40fe 100644 --- a/import/fallback_generator/src/lib.rs +++ b/import/fallback_generator/src/lib.rs @@ -101,3 +101,8 @@ fn random_accent(text: &str, y: f32) -> Rgba { v *= 0.2; Rgba([y - u * 0.5 - v * 0.5, y + v, y + u, 1.]) } + +#[test] +fn generate_fallback_test() { + generate_fallback("Hello world!", &mut Vec::new()).unwrap(); +} diff --git a/ui/src/format.rs b/ui/src/format.rs index 84e4c27..f3dd120 100644 --- a/ui/src/format.rs +++ b/ui/src/format.rs @@ -45,6 +45,28 @@ fn format_duration_mode(mut d: f64, long_units: bool, lang: Language) -> String } format!("{sign}{}", s.trim()) } + +#[test] +fn test_duration_short() { + assert_eq!(format_duration(61.).as_str(), "1m 1s"); + assert_eq!(format_duration(3661.).as_str(), "1h 1m 1s"); +} +#[test] +fn test_duration_long() { + assert_eq!( + format_duration_long(61., Language::English).as_str(), + "1 minute and 1 second" + ); + assert_eq!( + format_duration_long(121., Language::English).as_str(), + "2 minutes and 1 second" + ); + assert_eq!( + format_duration_long(3661., Language::English).as_str(), + "1 hour, 1 minute and 1 second" + ); +} + pub fn format_size(size: u64) -> String { humansize::format_size(size, humansize::DECIMAL) } -- cgit v1.3