From 4a33af4387e490a7f7f0fc1dfababb211e466950 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 21 Aug 2019 16:59:15 +0200 Subject: [PATCH] [clippy]: api-test: fix unsuffixed memory values Clippy actually noticed that the else branch was the same as the one for the 'b' suffix... Signed-off-by: Wolfgang Bumiller --- api-test/src/schema/types/memory.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/api-test/src/schema/types/memory.rs b/api-test/src/schema/types/memory.rs index bbbec02a..82d720d1 100644 --- a/api-test/src/schema/types/memory.rs +++ b/api-test/src/schema/types/memory.rs @@ -37,12 +37,25 @@ impl std::str::FromStr for Memory { } else if s.ends_with('b') || s.ends_with('B') { Ok(Self::from_bytes(s[..s.len() - 1].parse()?)) } else { - Ok(Self::from_bytes(s[..s.len() - 1].parse()?)) + Ok(Self::from_bytes(s.parse()?)) } } } proxmox::api::derive_parse_cli_from_str!(Memory); +#[test] +fn test_suffixes() { + use std::str::FromStr; + assert_eq!( + Memory::from_str("1234b").unwrap(), + Memory::from_str("1234").unwrap() + ); + assert_eq!( + Memory::from_str("4096K").unwrap(), + Memory::from_str("4M").unwrap() + ); +} + impl std::fmt::Display for Memory { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { const SUFFIXES: &'static [&'static str] = &["b", "KiB", "MiB", "GiB", "TiB"];