mirror of
https://github.com/nushell/nushell.git
synced 2025-08-12 21:57:50 +02:00
Make default precision None
This commit is contained in:
@ -129,7 +129,6 @@ fn format_value_impl(val: &Value, arg: &Arguments, span: Span) -> Value {
|
|||||||
match val {
|
match val {
|
||||||
Value::Filesize { val, .. } => FilesizeFormatter::new()
|
Value::Filesize { val, .. } => FilesizeFormatter::new()
|
||||||
.unit(arg.unit)
|
.unit(arg.unit)
|
||||||
.precision(None)
|
|
||||||
.format(*val)
|
.format(*val)
|
||||||
.to_string()
|
.to_string()
|
||||||
.into_value(span),
|
.into_value(span),
|
||||||
|
@ -623,7 +623,7 @@ impl FromStr for FilesizeUnitFormat {
|
|||||||
/// let formatter = FilesizeFormatter::new();
|
/// let formatter = FilesizeFormatter::new();
|
||||||
///
|
///
|
||||||
/// assert_eq!(formatter.unit(FilesizeUnit::B).format(filesize).to_string(), "4096 B");
|
/// assert_eq!(formatter.unit(FilesizeUnit::B).format(filesize).to_string(), "4096 B");
|
||||||
/// assert_eq!(formatter.unit(FilesizeUnit::KiB).format(filesize).to_string(), "4.0 KiB");
|
/// assert_eq!(formatter.unit(FilesizeUnit::KiB).format(filesize).to_string(), "4 KiB");
|
||||||
/// assert_eq!(formatter.precision(2).format(filesize).to_string(), "4.09 kB");
|
/// assert_eq!(formatter.precision(2).format(filesize).to_string(), "4.09 kB");
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// formatter
|
/// formatter
|
||||||
@ -646,13 +646,13 @@ impl FilesizeFormatter {
|
|||||||
///
|
///
|
||||||
/// The default formatter has:
|
/// The default formatter has:
|
||||||
/// - a [`unit`](Self::unit) of [`FilesizeUnitFormat::Metric`].
|
/// - a [`unit`](Self::unit) of [`FilesizeUnitFormat::Metric`].
|
||||||
/// - a [`precision`](Self::precision) of `Some(1)`.
|
/// - a [`precision`](Self::precision) of `None`.
|
||||||
/// - a [`locale`](Self::locale) of [`Locale::en_US_POSIX`]
|
/// - a [`locale`](Self::locale) of [`Locale::en_US_POSIX`]
|
||||||
/// (a very plain format with no thousands separators).
|
/// (a very plain format with no thousands separators).
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
FilesizeFormatter {
|
FilesizeFormatter {
|
||||||
unit: FilesizeUnitFormat::Metric,
|
unit: FilesizeUnitFormat::Metric,
|
||||||
precision: Some(1),
|
precision: None,
|
||||||
locale: Locale::en_US_POSIX,
|
locale: Locale::en_US_POSIX,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -667,7 +667,7 @@ impl FilesizeFormatter {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
/// # use nu_protocol::{Filesize, FilesizeFormatter, FilesizeUnit, FilesizeUnitFormat};
|
/// # use nu_protocol::{Filesize, FilesizeFormatter, FilesizeUnit, FilesizeUnitFormat};
|
||||||
/// let formatter = FilesizeFormatter::new();
|
/// let formatter = FilesizeFormatter::new().precision(1);
|
||||||
///
|
///
|
||||||
/// let filesize = Filesize::from_unit(4, FilesizeUnit::KiB).unwrap();
|
/// let filesize = Filesize::from_unit(4, FilesizeUnit::KiB).unwrap();
|
||||||
/// assert_eq!(formatter.unit(FilesizeUnit::B).format(filesize).to_string(), "4096 B");
|
/// assert_eq!(formatter.unit(FilesizeUnit::B).format(filesize).to_string(), "4096 B");
|
||||||
@ -738,7 +738,7 @@ impl FilesizeFormatter {
|
|||||||
/// # use nu_protocol::{Filesize, FilesizeFormatter, FilesizeUnit, FilesizeUnitFormat};
|
/// # use nu_protocol::{Filesize, FilesizeFormatter, FilesizeUnit, FilesizeUnitFormat};
|
||||||
/// # use num_format::Locale;
|
/// # use num_format::Locale;
|
||||||
/// let filesize = Filesize::from_unit(-4, FilesizeUnit::MiB).unwrap();
|
/// let filesize = Filesize::from_unit(-4, FilesizeUnit::MiB).unwrap();
|
||||||
/// let formatter = FilesizeFormatter::new().unit(FilesizeUnit::KB);
|
/// let formatter = FilesizeFormatter::new().unit(FilesizeUnit::KB).precision(1);
|
||||||
///
|
///
|
||||||
/// assert_eq!(formatter.format(filesize).to_string(), "-4194.3 kB");
|
/// assert_eq!(formatter.format(filesize).to_string(), "-4194.3 kB");
|
||||||
/// assert_eq!(formatter.locale(Locale::en).format(filesize).to_string(), "-4,194.3 kB");
|
/// assert_eq!(formatter.locale(Locale::en).format(filesize).to_string(), "-4,194.3 kB");
|
||||||
@ -759,8 +759,8 @@ impl FilesizeFormatter {
|
|||||||
/// let filesize = Filesize::from_unit(4, FilesizeUnit::KB).unwrap();
|
/// let filesize = Filesize::from_unit(4, FilesizeUnit::KB).unwrap();
|
||||||
/// let formatter = FilesizeFormatter::new();
|
/// let formatter = FilesizeFormatter::new();
|
||||||
///
|
///
|
||||||
/// assert_eq!(format!("{}", formatter.format(filesize)), "4.0 kB");
|
/// assert_eq!(format!("{}", formatter.format(filesize)), "4 kB");
|
||||||
/// assert_eq!(formatter.format(filesize).to_string(), "4.0 kB");
|
/// assert_eq!(formatter.format(filesize).to_string(), "4 kB");
|
||||||
/// ```
|
/// ```
|
||||||
pub fn format(&self, filesize: Filesize) -> FormattedFilesize {
|
pub fn format(&self, filesize: Filesize) -> FormattedFilesize {
|
||||||
FormattedFilesize {
|
FormattedFilesize {
|
||||||
@ -860,7 +860,6 @@ mod tests {
|
|||||||
exp,
|
exp,
|
||||||
FilesizeFormatter::new()
|
FilesizeFormatter::new()
|
||||||
.unit(unit)
|
.unit(unit)
|
||||||
.precision(None)
|
|
||||||
.format(Filesize::new(bytes))
|
.format(Filesize::new(bytes))
|
||||||
.to_string()
|
.to_string()
|
||||||
);
|
);
|
||||||
@ -875,7 +874,6 @@ mod tests {
|
|||||||
exp,
|
exp,
|
||||||
FilesizeFormatter::new()
|
FilesizeFormatter::new()
|
||||||
.unit(FilesizeUnitFormat::Binary)
|
.unit(FilesizeUnitFormat::Binary)
|
||||||
.precision(None)
|
|
||||||
.format(Filesize::new(val))
|
.format(Filesize::new(val))
|
||||||
.to_string()
|
.to_string()
|
||||||
);
|
);
|
||||||
@ -890,7 +888,6 @@ mod tests {
|
|||||||
exp,
|
exp,
|
||||||
FilesizeFormatter::new()
|
FilesizeFormatter::new()
|
||||||
.unit(FilesizeUnitFormat::Metric)
|
.unit(FilesizeUnitFormat::Metric)
|
||||||
.precision(None)
|
|
||||||
.format(Filesize::new(val))
|
.format(Filesize::new(val))
|
||||||
.to_string()
|
.to_string()
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user