mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-08-04 21:52:54 +02:00
globset: compact Debug impl for GlobSetBuilder
and Glob
Ideally we'd have a compact impl for `GlobSet` too, but that's a lot more work. In particular, the constituent types don't all store the original pattern string, so that would need to be added. Closes #3026
This commit is contained in:
committed by
Andrew Gallant
parent
0434b5034d
commit
fcfe98fe58
@ -71,7 +71,7 @@ impl MatchStrategy {
|
||||
///
|
||||
/// It cannot be used directly to match file paths, but it can be converted
|
||||
/// to a regular expression string or a matcher.
|
||||
#[derive(Clone, Debug, Eq)]
|
||||
#[derive(Clone, Eq)]
|
||||
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
|
||||
pub struct Glob {
|
||||
glob: String,
|
||||
@ -93,6 +93,21 @@ impl std::hash::Hash for Glob {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Glob {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
if f.alternate() {
|
||||
f.debug_struct("Glob")
|
||||
.field("glob", &self.glob)
|
||||
.field("re", &self.re)
|
||||
.field("opts", &self.opts)
|
||||
.field("tokens", &self.tokens)
|
||||
.finish()
|
||||
} else {
|
||||
f.debug_tuple("Glob").field(&self.glob).finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Glob {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
self.glob.fmt(f)
|
||||
|
@ -1100,4 +1100,16 @@ mod tests {
|
||||
let matches = set.matches("nada");
|
||||
assert_eq!(0, matches.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn debug() {
|
||||
let mut builder = GlobSetBuilder::new();
|
||||
builder.add(Glob::new("*foo*").unwrap());
|
||||
builder.add(Glob::new("*bar*").unwrap());
|
||||
builder.add(Glob::new("*quux*").unwrap());
|
||||
assert_eq!(
|
||||
format!("{builder:?}"),
|
||||
"GlobSetBuilder { pats: [Glob(\"*foo*\"), Glob(\"*bar*\"), Glob(\"*quux*\")] }",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user