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,57 +413,122 @@ mod test {
} }
} }
#[test] mod users {
fn user_with_name() { use super::*;
let mut stat = dummy_stat();
stat.unstable.uid = 1000;
let file = File::with_stat(stat, &Path::new("/hi"), None); #[test]
fn named() {
let mut stat = dummy_stat();
stat.unstable.uid = 1000;
let mut users = MockUsers::with_current_uid(1000); let file = File::with_stat(stat, &Path::new("/hi"), None);
users.add_user(User { uid: 1000, name: "enoch".to_string(), primary_group: 100 });
let cell = Cell::paint(Yellow.bold(), "enoch"); let mut users = MockUsers::with_current_uid(1000);
assert_eq!(cell, file.display(&Column::User, &mut users)) users.add_user(User { uid: 1000, name: "enoch".to_string(), primary_group: 100 });
let cell = Cell::paint(Yellow.bold(), "enoch");
assert_eq!(cell, file.display(&Column::User, &mut users))
}
#[test]
fn unnamed() {
let mut stat = dummy_stat();
stat.unstable.uid = 1000;
let file = File::with_stat(stat, &Path::new("/hi"), None);
let mut users = MockUsers::with_current_uid(1000);
let cell = Cell::paint(Yellow.bold(), "1000");
assert_eq!(cell, file.display(&Column::User, &mut users))
}
#[test]
fn different_named() {
let mut stat = dummy_stat();
stat.unstable.uid = 1000;
let file = File::with_stat(stat, &Path::new("/hi"), None);
let mut users = MockUsers::with_current_uid(3);
users.add_user(User { uid: 1000, name: "enoch".to_string(), primary_group: 100 });
let cell = Cell::paint(Plain, "enoch");
assert_eq!(cell, file.display(&Column::User, &mut users))
}
#[test]
fn different_unnamed() {
let mut stat = dummy_stat();
stat.unstable.uid = 1000;
let file = File::with_stat(stat, &Path::new("/hi"), None);
let mut users = MockUsers::with_current_uid(3);
let cell = Cell::paint(Plain, "1000");
assert_eq!(cell, file.display(&Column::User, &mut users))
}
} }
#[test] mod groups {
fn user_with_no_name() { use super::*;
let mut stat = dummy_stat();
stat.unstable.uid = 1000;
let file = File::with_stat(stat, &Path::new("/hi"), None); #[test]
fn named() {
let mut stat = dummy_stat();
stat.unstable.gid = 100;
let mut users = MockUsers::with_current_uid(1000); let file = File::with_stat(stat, &Path::new("/hi"), None);
let cell = Cell::paint(Yellow.bold(), "1000"); let mut users = MockUsers::with_current_uid(3);
assert_eq!(cell, file.display(&Column::User, &mut users)) users.add_group(Group { gid: 100, name: "folk".to_string(), members: vec![] });
}
#[test] let cell = Cell::paint(Plain, "folk");
fn a_different_user() { assert_eq!(cell, file.display(&Column::Group, &mut users))
let mut stat = dummy_stat(); }
stat.unstable.uid = 1000;
let file = File::with_stat(stat, &Path::new("/hi"), None); #[test]
fn unnamed() {
let mut stat = dummy_stat();
stat.unstable.gid = 100;
let mut users = MockUsers::with_current_uid(3); let file = File::with_stat(stat, &Path::new("/hi"), None);
users.add_user(User { uid: 1000, name: "enoch".to_string(), primary_group: 100 });
let cell = Cell::paint(Plain, "enoch"); let mut users = MockUsers::with_current_uid(3);
assert_eq!(cell, file.display(&Column::User, &mut users))
}
#[test] let cell = Cell::paint(Plain, "100");
fn a_different_yet_unnamed_user() { assert_eq!(cell, file.display(&Column::Group, &mut users))
let mut stat = dummy_stat(); }
stat.unstable.uid = 1000;
let file = File::with_stat(stat, &Path::new("/hi"), None); #[test]
fn primary() {
let mut stat = dummy_stat();
stat.unstable.gid = 100;
let mut users = MockUsers::with_current_uid(3); let file = File::with_stat(stat, &Path::new("/hi"), None);
let cell = Cell::paint(Plain, "1000"); let mut users = MockUsers::with_current_uid(3);
assert_eq!(cell, file.display(&Column::User, &mut users)) 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))
}
} }
} }