Test highlighting of groups and group names

This commit is contained in:
Benjamin Sago 2015-01-25 13:43:44 +00:00
parent 191c0e5b90
commit ef4428fab1

View File

@ -381,16 +381,16 @@ fn ext<'a>(name: &'a str) -> Option<String> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; pub use super::*;
use column::{Cell, Column}; pub use column::{Cell, Column};
use std::io; pub use std::io;
use users::User; pub use users::{User, Group};
use users::mock::MockUsers; pub use users::mock::MockUsers;
use ansi_term::Style::Plain; pub use ansi_term::Style::Plain;
use ansi_term::Colour::Yellow; pub use ansi_term::Colour::Yellow;
fn dummy_stat() -> io::FileStat { pub fn dummy_stat() -> io::FileStat {
io::FileStat { io::FileStat {
size: 0, size: 0,
kind: io::FileType::RegularFile, kind: io::FileType::RegularFile,
@ -413,8 +413,11 @@ mod test {
} }
} }
mod users {
use super::*;
#[test] #[test]
fn user_with_name() { fn named() {
let mut stat = dummy_stat(); let mut stat = dummy_stat();
stat.unstable.uid = 1000; stat.unstable.uid = 1000;
@ -428,7 +431,7 @@ mod test {
} }
#[test] #[test]
fn user_with_no_name() { fn unnamed() {
let mut stat = dummy_stat(); let mut stat = dummy_stat();
stat.unstable.uid = 1000; stat.unstable.uid = 1000;
@ -441,7 +444,7 @@ mod test {
} }
#[test] #[test]
fn a_different_user() { fn different_named() {
let mut stat = dummy_stat(); let mut stat = dummy_stat();
stat.unstable.uid = 1000; stat.unstable.uid = 1000;
@ -455,7 +458,7 @@ mod test {
} }
#[test] #[test]
fn a_different_yet_unnamed_user() { fn different_unnamed() {
let mut stat = dummy_stat(); let mut stat = dummy_stat();
stat.unstable.uid = 1000; stat.unstable.uid = 1000;
@ -466,4 +469,66 @@ mod test {
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))
} }
}
mod groups {
use super::*;
#[test]
fn named() {
let mut stat = dummy_stat();
stat.unstable.gid = 100;
let file = File::with_stat(stat, &Path::new("/hi"), None);
let mut users = MockUsers::with_current_uid(3);
users.add_group(Group { gid: 100, name: "folk".to_string(), members: vec![] });
let cell = Cell::paint(Plain, "folk");
assert_eq!(cell, file.display(&Column::Group, &mut users))
}
#[test]
fn unnamed() {
let mut stat = dummy_stat();
stat.unstable.gid = 100;
let file = File::with_stat(stat, &Path::new("/hi"), None);
let mut users = MockUsers::with_current_uid(3);
let cell = Cell::paint(Plain, "100");
assert_eq!(cell, file.display(&Column::Group, &mut users))
}
#[test]
fn primary() {
let mut stat = dummy_stat();
stat.unstable.gid = 100;
let file = File::with_stat(stat, &Path::new("/hi"), None);
let mut users = MockUsers::with_current_uid(3);
users.add_user(User { uid: 3, name: "eve".to_string(), primary_group: 100 });
users.add_group(Group { gid: 100, name: "folk".to_string(), members: vec![] });
let cell = Cell::paint(Yellow.bold(), "folk");
assert_eq!(cell, file.display(&Column::Group, &mut users))
}
#[test]
fn secondary() {
let mut stat = dummy_stat();
stat.unstable.gid = 100;
let file = File::with_stat(stat, &Path::new("/hi"), None);
let mut users = MockUsers::with_current_uid(3);
users.add_user(User { uid: 3, name: "eve".to_string(), primary_group: 12 });
users.add_group(Group { gid: 100, name: "folk".to_string(), members: vec![ "eve".to_string() ] });
let cell = Cell::paint(Yellow.bold(), "folk");
assert_eq!(cell, file.display(&Column::Group, &mut users))
}
}
} }