Skip to content

Commit

Permalink
Add Arbitrary to Glob
Browse files Browse the repository at this point in the history
Derive `Arbitrary` for `Glob` struct. This feature is optional so the
derive will only take place when the feature is enabled. This feature is
mandatory when using Glob in fuzz testing.

Signed-off-by: William Johnson <wjohnson@whamcloud.com>
  • Loading branch information
johnsonw committed Jan 24, 2024
1 parent 9b42af9 commit 579ef12
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/globset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ bench = false

[dependencies]
aho-corasick = "1.1.1"
arbitrary = { version = "1.3.2", optional = true, features = ["derive"] }
bstr = { version = "1.6.2", default-features = false, features = ["std"] }
log = { version = "0.4.20", optional = true }
serde = { version = "1.0.188", optional = true }
Expand Down
4 changes: 4 additions & 0 deletions crates/globset/src/glob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +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)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct Glob {
glob: String,
re: String,
Expand Down Expand Up @@ -193,6 +194,7 @@ pub struct GlobBuilder<'a> {
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
struct GlobOptions {
/// Whether to match case insensitively.
case_insensitive: bool,
Expand All @@ -219,6 +221,7 @@ impl GlobOptions {
}

#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
struct Tokens(Vec<Token>);

impl std::ops::Deref for Tokens {
Expand All @@ -235,6 +238,7 @@ impl std::ops::DerefMut for Tokens {
}

#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
enum Token {
Literal(char),
Any,
Expand Down

0 comments on commit 579ef12

Please sign in to comment.