Skip to content

Commit

Permalink
Merge pull request #59 from epage/fc
Browse files Browse the repository at this point in the history
feat(path): support file-based str predicates
  • Loading branch information
epage authored Jul 20, 2018
2 parents 2504357 + 4b43053 commit ade901d
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/path/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ impl BinaryFilePredicate {
/// assert_eq!(true, predicate_file.eval(Path::new("Cargo.toml")));
/// assert_eq!(false, predicate_file.eval(Path::new("Cargo.lock")));
/// assert_eq!(false, predicate_file.eval(Path::new("src")));
///
/// assert_eq!(false, predicate_file.eval("Not a real Cargo.toml file content"));
/// ```
pub fn utf8(self) -> Option<StrFilePredicate> {
let path = self.path;
Expand All @@ -58,6 +60,12 @@ impl Predicate<path::Path> for BinaryFilePredicate {
}
}

impl Predicate<[u8]> for BinaryFilePredicate {
fn eval(&self, actual: &[u8]) -> bool {
self.content == actual
}
}

impl fmt::Display for BinaryFilePredicate {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "var is {}", self.path.display())
Expand Down Expand Up @@ -100,14 +108,20 @@ impl StrFilePredicate {
}
}

impl fmt::Display for StrFilePredicate {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "var is {}", self.path.display())
}
}

impl Predicate<path::Path> for StrFilePredicate {
fn eval(&self, path: &path::Path) -> bool {
self.eval(path).unwrap_or(false)
}
}

impl Predicate<str> for StrFilePredicate {
fn eval(&self, actual: &str) -> bool {
self.content == actual
}
}

impl fmt::Display for StrFilePredicate {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "var is {}", self.path.display())
}
}

0 comments on commit ade901d

Please # to comment.