Skip to content

Commit ee144fa

Browse files
committed
test: use to_string_format in tests
1 parent 9fae90c commit ee144fa

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

src/lib.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -456,38 +456,38 @@ mod tests {
456456
}
457457

458458
#[track_caller]
459-
fn assert_to_string(expected: &str, b: ByteSize, si: bool) {
460-
assert_eq!(expected.to_string(), b.to_string_as(si));
459+
fn assert_to_string(expected: &str, b: ByteSize, format: Format) {
460+
assert_eq!(expected.to_string(), to_string_format(b.0, format));
461461
}
462462

463463
#[test]
464464
fn test_to_string_as() {
465-
assert_to_string("215 B", ByteSize::b(215), false);
466-
assert_to_string("215 B", ByteSize::b(215), true);
465+
assert_to_string("215 B", ByteSize::b(215), Format::IEC);
466+
assert_to_string("215 B", ByteSize::b(215), Format::SI);
467467

468-
assert_to_string("1.0 KiB", ByteSize::kib(1), false);
469-
assert_to_string("1.0 kB", ByteSize::kib(1), true);
468+
assert_to_string("1.0 KiB", ByteSize::kib(1), Format::IEC);
469+
assert_to_string("1.0 kB", ByteSize::kib(1), Format::SI);
470470

471-
assert_to_string("293.9 KiB", ByteSize::kb(301), false);
472-
assert_to_string("301.0 kB", ByteSize::kb(301), true);
471+
assert_to_string("293.9 KiB", ByteSize::kb(301), Format::IEC);
472+
assert_to_string("301.0 kB", ByteSize::kb(301), Format::SI);
473473

474-
assert_to_string("1024.0 KiB", ByteSize::mib(1), false);
475-
assert_to_string("1.0 MB", ByteSize::mib(1), true);
474+
assert_to_string("1024.0 KiB", ByteSize::mib(1), Format::IEC);
475+
assert_to_string("1.0 MB", ByteSize::mib(1), Format::SI);
476476

477-
assert_to_string("1.9 GiB", ByteSize::mib(1907), false);
478-
assert_to_string("2.0 GB", ByteSize::mib(1908), true);
477+
assert_to_string("1.9 GiB", ByteSize::mib(1907), Format::IEC);
478+
assert_to_string("2.0 GB", ByteSize::mib(1908), Format::SI);
479479

480-
assert_to_string("399.6 MiB", ByteSize::mb(419), false);
481-
assert_to_string("419.0 MB", ByteSize::mb(419), true);
480+
assert_to_string("399.6 MiB", ByteSize::mb(419), Format::IEC);
481+
assert_to_string("419.0 MB", ByteSize::mb(419), Format::SI);
482482

483-
assert_to_string("482.4 GiB", ByteSize::gb(518), false);
484-
assert_to_string("518.0 GB", ByteSize::gb(518), true);
483+
assert_to_string("482.4 GiB", ByteSize::gb(518), Format::IEC);
484+
assert_to_string("518.0 GB", ByteSize::gb(518), Format::SI);
485485

486-
assert_to_string("741.2 TiB", ByteSize::tb(815), false);
487-
assert_to_string("815.0 TB", ByteSize::tb(815), true);
486+
assert_to_string("741.2 TiB", ByteSize::tb(815), Format::IEC);
487+
assert_to_string("815.0 TB", ByteSize::tb(815), Format::SI);
488488

489-
assert_to_string("540.9 PiB", ByteSize::pb(609), false);
490-
assert_to_string("609.0 PB", ByteSize::pb(609), true);
489+
assert_to_string("540.9 PiB", ByteSize::pb(609), Format::IEC);
490+
assert_to_string("609.0 PB", ByteSize::pb(609), Format::SI);
491491
}
492492

493493
#[test]
@@ -497,6 +497,6 @@ mod tests {
497497

498498
#[test]
499499
fn test_to_string() {
500-
assert_to_string("609.0 PB", ByteSize::pb(609), true);
500+
assert_to_string("609.0 PB", ByteSize::pb(609), Format::SI);
501501
}
502502
}

src/parse.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ impl std::str::FromStr for Unit {
181181

182182
#[cfg(test)]
183183
mod tests {
184+
use crate::to_string_format;
185+
184186
use super::*;
185187

186188
#[test]
@@ -234,7 +236,7 @@ mod tests {
234236

235237
assert_eq!(parse(&format!("{}", parse("128GB"))), 128 * Unit::GigaByte);
236238
assert_eq!(
237-
parse(&crate::to_string(parse("128.000 GiB"), false)),
239+
parse(&to_string_format(parse("128.000 GiB"), crate::Format::IEC,)),
238240
128 * Unit::GibiByte
239241
);
240242
}

0 commit comments

Comments
 (0)