mirror of
https://github.com/kristoferssolo/traxor.git
synced 2026-02-04 06:42:04 +00:00
test: fix errors
This commit is contained in:
@@ -20,3 +20,27 @@ impl Display for FileSize {
|
||||
write!(f, "{}", UnitDisplay::new(&self.0, UNITS))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_new() {
|
||||
let file_size = FileSize::new(1024);
|
||||
assert_eq!(file_size.0.as_raw(), 1024);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_display() {
|
||||
let file_size = FileSize::new(1024);
|
||||
assert_eq!(file_size.to_string(), "1.00 KB");
|
||||
|
||||
let file_size = FileSize::new(1024 * 1024);
|
||||
assert_eq!(file_size.to_string(), "1.00 MB");
|
||||
|
||||
let file_size = FileSize::new(1024 * 1024 * 1024);
|
||||
assert_eq!(file_size.to_string(), "1.00 GB");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,3 +20,27 @@ impl Display for NetSpeed {
|
||||
write!(f, "{}", UnitDisplay::new(&self.0, UNITS))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_new() {
|
||||
let net_speed = NetSpeed::new(1024);
|
||||
assert_eq!(net_speed.0.as_raw(), 1024);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_display() {
|
||||
let net_speed = NetSpeed::new(1024);
|
||||
assert_eq!(net_speed.to_string(), "1.00 KB/s");
|
||||
|
||||
let net_speed = NetSpeed::new(1024 * 1024);
|
||||
assert_eq!(net_speed.to_string(), "1.00 MB/s");
|
||||
|
||||
let net_speed = NetSpeed::new(1024 * 1024 * 1024);
|
||||
assert_eq!(net_speed.to_string(), "1.00 GB/s");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ impl Unit {
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn value(&self) -> u64 {
|
||||
pub const fn as_raw(&self) -> u64 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
@@ -126,3 +126,35 @@ macro_rules! impl_unit_newtype {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_unit_from_u64() {
|
||||
let unit = Unit::from(1024u64);
|
||||
assert_eq!(unit.as_raw(), 1024);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unit_from_raw() {
|
||||
let unit = Unit::from_raw(1024);
|
||||
assert_eq!(unit.as_raw(), 1024);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unit_display() {
|
||||
let unit = Unit::from_raw(1024);
|
||||
let display = UnitDisplay::new(&unit, &["B", "KB", "MB"]);
|
||||
assert_eq!(display.to_string(), "1.00 KB");
|
||||
|
||||
let unit = Unit::from_raw(1024 * 1024);
|
||||
let display = UnitDisplay::new(&unit, &["B", "KB", "MB"]);
|
||||
assert_eq!(display.to_string(), "1.00 MB");
|
||||
|
||||
let unit = Unit::from_raw(512);
|
||||
let display = UnitDisplay::new(&unit, &["B", "KB", "MB"]);
|
||||
assert_eq!(display.to_string(), "512 B");
|
||||
}
|
||||
}
|
||||
@@ -125,6 +125,9 @@ fn parse_keybind(key_str: &str) -> Result<KeyEvent, ParseKeybingError> {
|
||||
for raw in key_str.split('+') {
|
||||
let part = raw.trim();
|
||||
if part.is_empty() {
|
||||
if raw.contains(' ') {
|
||||
key_code = Some(KeyCode::Char(' '));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let low = part.to_lowercase();
|
||||
@@ -176,8 +179,8 @@ fn parse_keybind(key_str: &str) -> Result<KeyEvent, ParseKeybingError> {
|
||||
}
|
||||
|
||||
// single‐character fallback
|
||||
_ if low.len() == 1 => {
|
||||
if let Some(ch) = low.trim().chars().next() {
|
||||
_ if part.len() == 1 => {
|
||||
if let Some(ch) = part.chars().next() {
|
||||
key_code = Some(KeyCode::Char(ch));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user