diff --git a/src/mode/parser.rs b/src/mode/parser.rs index 6727707..5c6f692 100644 --- a/src/mode/parser.rs +++ b/src/mode/parser.rs @@ -164,7 +164,7 @@ impl Parser { fn remove_bits(&mut self) { for bit in &self.bits { - self.mode &= *bit as u32; + self.mode &= !(*bit as u32); } } @@ -175,9 +175,9 @@ impl Parser { Some(Op::Equals) => { for w in &self.who { match w { - Who::User => self.mode &= 0o4444, - Who::Group => self.mode &= 0o2222, - Who::Other => self.mode &= 0o1111, + Who::User => self.mode &= !0o4444, + Who::Group => self.mode &= !0o2222, + Who::Other => self.mode &= !0o1111, } } self.add_bits(); @@ -238,3 +238,36 @@ impl Parser { Ok(self.mode) } } + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn add() { + let mut parser = Parser::new(0o644); + let mode = parser.parse("ug+x"); + assert_eq!(mode, Ok(0o754)); + } + + #[test] + fn remove() { + let mut parser = Parser::new(0o777); + let mode = parser.parse("go-wx"); + assert_eq!(mode, Ok(0o744)); + } + + #[test] + fn octal() { + let mut parser = Parser::default(); + let mode = parser.parse("4755"); + assert_eq!(mode, Ok(0o4755)); + } + + #[test] + fn equals() { + let mut parser = Parser::new(0o701); + let mode = parser.parse("ugo=rw"); + assert_eq!(mode, Ok(0o666)); + } +}