summaryrefslogtreecommitdiffstats
path: root/vendor/gix-glob/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/gix-glob/tests
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-glob/tests')
-rw-r--r--vendor/gix-glob/tests/glob.rs1
-rw-r--r--vendor/gix-glob/tests/parse/mod.rs31
-rw-r--r--vendor/gix-glob/tests/pattern/matching.rs2
-rw-r--r--vendor/gix-glob/tests/search/mod.rs1
-rw-r--r--vendor/gix-glob/tests/search/pattern.rs90
-rw-r--r--vendor/gix-glob/tests/wildmatch/mod.rs4
6 files changed, 108 insertions, 21 deletions
diff --git a/vendor/gix-glob/tests/glob.rs b/vendor/gix-glob/tests/glob.rs
index 3a90f1d51..256a74bc7 100644
--- a/vendor/gix-glob/tests/glob.rs
+++ b/vendor/gix-glob/tests/glob.rs
@@ -1,3 +1,4 @@
mod parse;
mod pattern;
+mod search;
mod wildmatch;
diff --git a/vendor/gix-glob/tests/parse/mod.rs b/vendor/gix-glob/tests/parse/mod.rs
index d6be0df24..fc668d1e6 100644
--- a/vendor/gix-glob/tests/parse/mod.rs
+++ b/vendor/gix-glob/tests/parse/mod.rs
@@ -106,11 +106,11 @@ fn trailing_slashes_are_marked_and_removed() {
}
#[test]
-fn trailing_spaces_are_ignored() {
- assert_eq!(gix_glob::parse(br"a "), pat("a", Mode::NO_SUB_DIR, None));
+fn trailing_spaces_are_taken_literally() {
+ assert_eq!(gix_glob::parse(br"a "), pat("a ", Mode::NO_SUB_DIR, None));
assert_eq!(
gix_glob::parse(b"a\t\t "),
- pat("a\t\t", Mode::NO_SUB_DIR, None),
+ pat("a\t\t ", Mode::NO_SUB_DIR, None),
"trailing tabs are not ignored"
);
}
@@ -119,37 +119,32 @@ fn trailing_spaces_are_ignored() {
fn trailing_spaces_can_be_escaped_to_be_literal() {
assert_eq!(
gix_glob::parse(br"a \ "),
- pat("a ", Mode::NO_SUB_DIR, None),
- "a single escape in front of the last desired space is enough"
+ pat("a \\ ", Mode::NO_SUB_DIR, Some(3)),
+ "there is no escaping"
);
assert_eq!(
gix_glob::parse(br"a b c "),
- pat("a b c", Mode::NO_SUB_DIR, None),
- "spaces in the middle are fine"
+ pat("a b c ", Mode::NO_SUB_DIR, None),
+ "spaces in the middle are fine and also at the end"
);
assert_eq!(
gix_glob::parse(br"a\ \ \ "),
- pat("a ", Mode::NO_SUB_DIR, None),
- "one can also escape every single one"
- );
- assert_eq!(
- gix_glob::parse(br"a \ "),
- pat("a ", Mode::NO_SUB_DIR, None),
- "or just the one in the middle, losing the last actual space"
+ pat(r"a\ \ \ ", Mode::NO_SUB_DIR, Some(1)),
+ "one can also escape every single space, but it's interpreted by the globbing engine"
);
assert_eq!(
gix_glob::parse(br"a \"),
- pat("a ", Mode::NO_SUB_DIR, None),
- "escaping nothing also works as a whitespace protection"
+ pat(r"a \", Mode::NO_SUB_DIR, Some(4)),
+ "escaping nothing also works"
);
assert_eq!(
gix_glob::parse(br"a \\\ "),
- pat(r"a ", Mode::NO_SUB_DIR, None),
+ pat(r"a \\\ ", Mode::NO_SUB_DIR, Some(4)),
"strange things like these work too"
);
assert_eq!(
gix_glob::parse(br"a \\ "),
- pat(r"a ", Mode::NO_SUB_DIR, None),
+ pat(r"a \\ ", Mode::NO_SUB_DIR, Some(4)),
"strange things like these work as well"
);
}
diff --git a/vendor/gix-glob/tests/pattern/matching.rs b/vendor/gix-glob/tests/pattern/matching.rs
index 3e757f8d6..8a5208d9a 100644
--- a/vendor/gix-glob/tests/pattern/matching.rs
+++ b/vendor/gix-glob/tests/pattern/matching.rs
@@ -271,7 +271,7 @@ fn names_do_not_automatically_match_entire_directories() {
#[test]
fn directory_patterns_do_not_match_files_within_a_directory_as_well_like_slash_star_star() {
- // this feature is implemented with the directory stack, which excludes entire directories
+ // this feature is implemented with the directory stack in `gix-ignore`, which excludes entire directories
let pattern = &pat("dir/");
assert!(!match_path(pattern, "dir/file", None, Case::Sensitive));
assert!(!match_path(pattern, "base/dir/file", None, Case::Sensitive));
diff --git a/vendor/gix-glob/tests/search/mod.rs b/vendor/gix-glob/tests/search/mod.rs
new file mode 100644
index 000000000..e88c9a605
--- /dev/null
+++ b/vendor/gix-glob/tests/search/mod.rs
@@ -0,0 +1 @@
+mod pattern;
diff --git a/vendor/gix-glob/tests/search/pattern.rs b/vendor/gix-glob/tests/search/pattern.rs
new file mode 100644
index 000000000..0313b5564
--- /dev/null
+++ b/vendor/gix-glob/tests/search/pattern.rs
@@ -0,0 +1,90 @@
+mod list {
+ use std::path::Path;
+
+ use gix_glob::{
+ pattern::Case,
+ search::{
+ pattern::{List, Mapping},
+ Pattern,
+ },
+ };
+
+ #[derive(Clone, PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Default)]
+ struct Dummy;
+
+ impl Pattern for Dummy {
+ type Value = ();
+
+ fn bytes_to_patterns(_bytes: &[u8], _source: &Path) -> Vec<Mapping<Self::Value>> {
+ vec![]
+ }
+
+ fn may_use_glob_pattern(_pattern: &gix_glob::Pattern) -> bool {
+ unreachable!("won't be called")
+ }
+ }
+
+ #[test]
+ fn from_bytes_base() {
+ {
+ let list = List::<Dummy>::from_bytes(&[], "a/b/source", None);
+ assert_eq!(list.base, None, "no root always means no-base, i.e. globals lists");
+ assert_eq!(
+ list.source.as_deref(),
+ Some(Path::new("a/b/source")),
+ "source is verbatim"
+ );
+ }
+
+ {
+ let cwd = std::env::current_dir().expect("cwd available");
+ let list = List::<Dummy>::from_bytes(&[], cwd.join("a/b/source"), Some(cwd.as_path()));
+ assert_eq!(
+ list.base.as_ref().expect("set"),
+ "a/b/",
+ "bases are always relative, needs properly set root"
+ );
+ assert_eq!(
+ list.source.as_deref(),
+ Some(cwd.join("a/b/source").as_path()),
+ "source is verbatim"
+ );
+ }
+
+ {
+ let list = List::<Dummy>::from_bytes(&[], "a/b/source", Some(Path::new("c/")));
+ assert_eq!(
+ list.base, None,
+ "if root doesn't contain source, it silently skips it as base"
+ );
+ assert_eq!(
+ list.source.as_deref(),
+ Some(Path::new("a/b/source")),
+ "source is always verbatim"
+ );
+ }
+ }
+
+ #[test]
+ fn strip_base_handle_recompute_basename_pos() {
+ let list = List::<Dummy>::from_bytes(&[], "a/b/source", Some(Path::new("")));
+ assert_eq!(
+ list.base.as_ref().expect("set"),
+ "a/b/",
+ "bases are computed if `root` is set, and always uses slashes"
+ );
+ let res = list.strip_base_handle_recompute_basename_pos("a/b/file".into(), Some(4), Case::Sensitive);
+ assert_eq!(
+ res,
+ Some(("file".into(), None)),
+ "files don't have a basename position anymore"
+ );
+
+ let res = list.strip_base_handle_recompute_basename_pos("a/B/c/File".into(), Some(6), Case::Fold);
+ assert_eq!(
+ res,
+ Some(("c/File".into(), Some(2))),
+ "otherwise the basename is recomputed, case folding is effective"
+ );
+ }
+}
diff --git a/vendor/gix-glob/tests/wildmatch/mod.rs b/vendor/gix-glob/tests/wildmatch/mod.rs
index 2e74dabf3..11fbd664b 100644
--- a/vendor/gix-glob/tests/wildmatch/mod.rs
+++ b/vendor/gix-glob/tests/wildmatch/mod.rs
@@ -73,8 +73,8 @@ fn corpus() {
(0,0,0,0, "]", "[!]-]"),
(1,1,1,1, "a", "[!]-]"),
(0,0,0,0, "", r"\"),
- (0,0,1,1, r"XXX/\", r"*/\"),
- (0,0,1,1, r"XXX/\", r"*/\\"),
+ (0,0,0,0, r"XXX/\", r"*/\"),
+ (1,1,1,1, r"XXX/\", r"*/\\"),
(1,1,1,1, "foo", "foo"),
(1,1,1,1, "@foo", "@foo"),
(0,0,0,0, "foo", "@foo"),