aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cache/src/lib.rs2
-rw-r--r--common/src/lib.rs2
-rw-r--r--import/asset_token/src/lib.rs13
-rw-r--r--import/fallback_generator/src/lib.rs5
-rw-r--r--ui/src/format.rs22
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<Config> = 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<Aes256GcmSiv> = LazyLock::new(|| {
}
});
-#[derive(Debug, Encode, Decode, Serialize)]
+#[derive(Debug, Encode, Decode, Serialize, PartialEq, Eq)]
pub enum AssetInner {
Federated { host: String, asset: Vec<u8> },
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<f32> {
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)
}