Use locale-defined decimal separator

Also, fix the broken tests by just using the default locale at test
time.
This commit is contained in:
Ben S 2015-02-10 16:42:25 +00:00
parent 84b18e5521
commit e39a20a5d4

View File

@ -287,16 +287,13 @@ impl<'a> File<'a> {
let result = match size_format { let result = match size_format {
SizeFormat::DecimalBytes => decimal_prefix(self.stat.size as f64), SizeFormat::DecimalBytes => decimal_prefix(self.stat.size as f64),
SizeFormat::BinaryBytes => binary_prefix(self.stat.size as f64), SizeFormat::BinaryBytes => binary_prefix(self.stat.size as f64),
SizeFormat::JustBytes => { SizeFormat::JustBytes => return Cell::paint(Green.bold(), &locale.format_int(self.stat.size as isize)[]),
return Cell::paint(Green.bold(), &locale.format_int(self.stat.size as isize)[])
},
}; };
match result { match result {
Standalone(bytes) => Cell::paint(Green.bold(), &*bytes.to_string()), Standalone(bytes) => Cell::paint(Green.bold(), &*bytes.to_string()),
Prefixed(prefix, n) => { Prefixed(prefix, n) => {
let number = if n < 10f64 { format!("{:.1}", n) } else { format!("{:.0}", n) }; let number = if n < 10f64 { locale.format_float(n, 1, false) } else { locale.format_int(n as isize) };
let symbol = prefix.symbol(); let symbol = prefix.symbol();
Cell { Cell {
@ -450,6 +447,8 @@ pub mod test {
pub use ansi_term::Style::Plain; pub use ansi_term::Style::Plain;
pub use ansi_term::Colour::Yellow; pub use ansi_term::Colour::Yellow;
pub use locale;
#[test] #[test]
fn extension() { fn extension() {
assert_eq!(Some("dat".to_string()), super::ext("fester.dat")) assert_eq!(Some("dat".to_string()), super::ext("fester.dat"))
@ -492,6 +491,10 @@ pub mod test {
} }
} }
pub fn dummy_locale() -> locale::Numeric {
locale::Numeric::default()
}
mod users { mod users {
use super::*; use super::*;
@ -506,7 +509,7 @@ pub mod test {
users.add_user(User { uid: 1000, name: "enoch".to_string(), primary_group: 100 }); users.add_user(User { uid: 1000, name: "enoch".to_string(), primary_group: 100 });
let cell = Cell::paint(Yellow.bold(), "enoch"); let cell = Cell::paint(Yellow.bold(), "enoch");
assert_eq!(cell, file.display(&Column::User, &mut users)) assert_eq!(cell, file.display(&Column::User, &mut users, &dummy_locale()))
} }
#[test] #[test]
@ -519,7 +522,7 @@ pub mod test {
let mut users = MockUsers::with_current_uid(1000); let mut users = MockUsers::with_current_uid(1000);
let cell = Cell::paint(Yellow.bold(), "1000"); let cell = Cell::paint(Yellow.bold(), "1000");
assert_eq!(cell, file.display(&Column::User, &mut users)) assert_eq!(cell, file.display(&Column::User, &mut users, &dummy_locale()))
} }
#[test] #[test]
@ -533,7 +536,7 @@ pub mod test {
users.add_user(User { uid: 1000, name: "enoch".to_string(), primary_group: 100 }); users.add_user(User { uid: 1000, name: "enoch".to_string(), primary_group: 100 });
let cell = Cell::paint(Plain, "enoch"); let cell = Cell::paint(Plain, "enoch");
assert_eq!(cell, file.display(&Column::User, &mut users)) assert_eq!(cell, file.display(&Column::User, &mut users, &dummy_locale()))
} }
#[test] #[test]
@ -546,7 +549,7 @@ pub mod test {
let mut users = MockUsers::with_current_uid(3); let mut users = MockUsers::with_current_uid(3);
let cell = Cell::paint(Plain, "1000"); let cell = Cell::paint(Plain, "1000");
assert_eq!(cell, file.display(&Column::User, &mut users)) assert_eq!(cell, file.display(&Column::User, &mut users, &dummy_locale()))
} }
} }
@ -564,7 +567,7 @@ pub mod test {
users.add_group(Group { gid: 100, name: "folk".to_string(), members: vec![] }); users.add_group(Group { gid: 100, name: "folk".to_string(), members: vec![] });
let cell = Cell::paint(Plain, "folk"); let cell = Cell::paint(Plain, "folk");
assert_eq!(cell, file.display(&Column::Group, &mut users)) assert_eq!(cell, file.display(&Column::Group, &mut users, &dummy_locale()))
} }
#[test] #[test]
@ -577,7 +580,7 @@ pub mod test {
let mut users = MockUsers::with_current_uid(3); let mut users = MockUsers::with_current_uid(3);
let cell = Cell::paint(Plain, "100"); let cell = Cell::paint(Plain, "100");
assert_eq!(cell, file.display(&Column::Group, &mut users)) assert_eq!(cell, file.display(&Column::Group, &mut users, &dummy_locale()))
} }
#[test] #[test]
@ -592,7 +595,7 @@ pub mod test {
users.add_group(Group { gid: 100, name: "folk".to_string(), members: vec![] }); users.add_group(Group { gid: 100, name: "folk".to_string(), members: vec![] });
let cell = Cell::paint(Yellow.bold(), "folk"); let cell = Cell::paint(Yellow.bold(), "folk");
assert_eq!(cell, file.display(&Column::Group, &mut users)) assert_eq!(cell, file.display(&Column::Group, &mut users, &dummy_locale()))
} }
#[test] #[test]
@ -607,7 +610,7 @@ pub mod test {
users.add_group(Group { gid: 100, name: "folk".to_string(), members: vec![ "eve".to_string() ] }); users.add_group(Group { gid: 100, name: "folk".to_string(), members: vec![ "eve".to_string() ] });
let cell = Cell::paint(Yellow.bold(), "folk"); let cell = Cell::paint(Yellow.bold(), "folk");
assert_eq!(cell, file.display(&Column::Group, &mut users)) assert_eq!(cell, file.display(&Column::Group, &mut users, &dummy_locale()))
} }
} }
} }