aboutsummaryrefslogtreecommitdiff
path: root/tests/basic.rs
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-05-10 07:23:16 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-05-10 07:23:16 +0000
commite42091b9afa8b1d9cb0d0418bba7a2b1e23eeca8 (patch)
tree0ee35a94c440d4b17b59f4adbc625f2cee3fb7f3 /tests/basic.rs
parente19c8c561565fcf1fec05e94aefa07728f69409a (diff)
parent6f0fadcda199702a28974afba6e4b75bf6a20b2a (diff)
downloadwhich-e42091b9afa8b1d9cb0d0418bba7a2b1e23eeca8.tar.gz
Change-Id: Ic5119e86eef4af1a83cc4a5cf482ac2e7b915bf7
Diffstat (limited to 'tests/basic.rs')
-rw-r--r--tests/basic.rs48
1 files changed, 47 insertions, 1 deletions
diff --git a/tests/basic.rs b/tests/basic.rs
index 7cb7a08..897e912 100644
--- a/tests/basic.rs
+++ b/tests/basic.rs
@@ -1,11 +1,13 @@
extern crate tempdir;
extern crate which;
-use std::env;
+#[cfg(feature = "regex")]
+use regex::Regex;
use std::ffi::{OsStr, OsString};
use std::fs;
use std::io;
use std::path::{Path, PathBuf};
+use std::{env, vec};
use tempdir::TempDir;
struct TestFixture {
@@ -126,6 +128,50 @@ fn test_which() {
}
#[test]
+#[cfg(all(unix, feature = "regex"))]
+fn test_which_re_in_with_matches() {
+ let f = TestFixture::new();
+ f.mk_bin("a/bin_0", "").unwrap();
+ f.mk_bin("b/bin_1", "").unwrap();
+ let re = Regex::new(r"bin_\d").unwrap();
+
+ let result: Vec<PathBuf> = which::which_re_in(re, Some(f.paths))
+ .unwrap()
+ .into_iter()
+ .collect();
+
+ let temp = f.tempdir;
+
+ assert_eq!(
+ result,
+ vec![temp.path().join("a/bin_0"), temp.path().join("b/bin_1")]
+ )
+}
+
+#[test]
+#[cfg(all(unix, feature = "regex"))]
+fn test_which_re_in_without_matches() {
+ let f = TestFixture::new();
+ let re = Regex::new(r"bi[^n]").unwrap();
+
+ let result: Vec<PathBuf> = which::which_re_in(re, Some(f.paths))
+ .unwrap()
+ .into_iter()
+ .collect();
+
+ assert_eq!(result, Vec::<PathBuf>::new())
+}
+
+#[test]
+#[cfg(all(unix, feature = "regex"))]
+fn test_which_re_accepts_owned_and_borrow() {
+ which::which_re(Regex::new(r".").unwrap());
+ which::which_re(&Regex::new(r".").unwrap());
+ which::which_re_in(Regex::new(r".").unwrap(), Some("pth"));
+ which::which_re_in(&Regex::new(r".").unwrap(), Some("pth"));
+}
+
+#[test]
#[cfg(unix)]
fn test_which_extension() {
let f = TestFixture::new();