From 60b0d0eadba1bdb485f8b3ed9e17a03e1555cc67 Mon Sep 17 00:00:00 2001 From: MaxVerevkin <34583604+MaxVerevkin@users.noreply.github.com> Date: Wed, 16 Aug 2023 05:39:07 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20greshake?= =?UTF-8?q?/i3status-rust@1370e6b9145fcf49fc9de8ec7040d0eb8d11471a=20?= =?UTF-8?q?=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- i3status_rs/formatting/formatter/index.html | 2 +- .../formatting/prefix/enum.Prefix.html | 2 +- i3status_rs/formatting/prefix/index.html | 2 +- src/i3status_rs/formatting/formatter.rs.html | 100 +++++++- src/i3status_rs/formatting/prefix.rs.html | 220 +++++++++++++++++- 5 files changed, 315 insertions(+), 11 deletions(-) diff --git a/i3status_rs/formatting/formatter/index.html b/i3status_rs/formatting/formatter/index.html index 4a30ddac93..d8e4d94b24 100644 --- a/i3status_rs/formatting/formatter/index.html +++ b/i3status_rs/formatting/formatter/index.html @@ -1 +1 @@ -
Gi
T
Ti
self
and other
values to be equal, and is used
diff --git a/i3status_rs/formatting/prefix/index.html b/i3status_rs/formatting/prefix/index.html
index efe6e80443..ac3d34702b 100644
--- a/i3status_rs/formatting/prefix/index.html
+++ b/i3status_rs/formatting/prefix/index.html
@@ -1 +1 @@
-use chrono::format::{Item, StrftimeItems};
use chrono::{Local, Locale};
use once_cell::sync::Lazy;
@@ -1097,7 +1142,7 @@
let sign = if is_negative { "-" } else { "" };
let mut retval = match self.0.width as i32 - digits {
- i32::MIN..=0 => format!("{sign}{}", val.floor()),
+ i32::MIN..=0 => format!("{sign}{}", val.round()),
1 => format!("{}{sign}{}", self.0.pad_with, val.round() as i64),
rest => format!("{sign}{val:.*}", rest as usize - 1),
};
@@ -1233,9 +1278,17 @@
mod tests {
use super::*;
+ macro_rules! fmt {
+ ($name:ident, $($key:ident : $value:tt),*) => {
+ new_formatter(stringify!($name), &[
+ $( Arg { key: stringify!($key), val: stringify!($value) } ),*
+ ]).unwrap()
+ };
+}
+
#[test]
fn eng_rounding_and_negatives() {
- let fmt = new_formatter("eng", &[Arg { key: "w", val: "3" }]).unwrap();
+ let fmt = fmt!(eng, w: 3);
let config = SharedConfig::default();
let result = fmt
@@ -1260,8 +1313,7 @@
.unwrap();
assert_eq!(result, " 10");
- // TODO: This should be " 1KB"
- let result = fmt
+ let result = fmt
.format(
&Value::Number {
val: 999.9,
@@ -1270,7 +1322,7 @@
&config,
)
.unwrap();
- assert_eq!(result, "999B");
+ assert_eq!(result, "1.0KB");
let result = fmt
.format(
@@ -1304,6 +1356,44 @@
)
.unwrap();
assert_eq!(result, " 10");
+
+ let fmt = fmt!(eng, w: 5, p: 1);
+ let result = fmt
+ .format(
+ &Value::Number {
+ val: 321_600_000_000.,
+ unit: Unit::Bytes,
+ },
+ &config,
+ )
+ .unwrap();
+ assert_eq!(result, "321.6GB");
+ }
+
+ #[test]
+ fn eng_prefixes() {
+ let config = SharedConfig::default();
+ // 14.96 GiB
+ let val = Value::Number {
+ val: 14.96 * 1024. * 1024. * 1024.,
+ unit: Unit::Bytes,
+ };
+
+ let fmt = fmt!(eng, w: 5, p: Mi);
+ let result = fmt.format(&val, &config).unwrap();
+ assert_eq!(result, "14.96GiB");
+
+ let fmt = fmt!(eng, w: 4, p: Mi);
+ let result = fmt.format(&val, &config).unwrap();
+ assert_eq!(result, "15.0GiB");
+
+ let fmt = fmt!(eng, w: 3, p: Mi);
+ let result = fmt.format(&val, &config).unwrap();
+ assert_eq!(result, " 15GiB");
+
+ let fmt = fmt!(eng, w: 2, p: Mi);
+ let result = fmt.format(&val, &config).unwrap();
+ assert_eq!(result, "15GiB");
}
}