use std::collections::HashMap;
use std::iter;
use std::path;
use std::slice;
use itertools::Itertools as _;
use once_cell::sync::Lazy;
use thiserror::Error;
use crate::dsl_util::collect_similar;
use crate::fileset_parser;
use crate::fileset_parser::BinaryOp;
use crate::fileset_parser::ExpressionKind;
use crate::fileset_parser::ExpressionNode;
pub use crate::fileset_parser::FilesetParseError;
pub use crate::fileset_parser::FilesetParseErrorKind;
pub use crate::fileset_parser::FilesetParseResult;
use crate::fileset_parser::FunctionCallNode;
use crate::fileset_parser::UnaryOp;
use crate::matchers::DifferenceMatcher;
use crate::matchers::EverythingMatcher;
use crate::matchers::FileGlobsMatcher;
use crate::matchers::FilesMatcher;
use crate::matchers::IntersectionMatcher;
use crate::matchers::Matcher;
use crate::matchers::NothingMatcher;
use crate::matchers::PrefixMatcher;
use crate::matchers::UnionMatcher;
use crate::repo_path::RelativePathParseError;
use crate::repo_path::RepoPath;
use crate::repo_path::RepoPathBuf;
use crate::repo_path::RepoPathUiConverter;
use crate::repo_path::UiPathParseError;
#[derive(Debug, Error)]
pub enum FilePatternParseError {
#[error(r#"Invalid file pattern kind "{0}:""#)]
InvalidKind(String),
#[error(transparent)]
UiPath(#[from] UiPathParseError),
#[error(transparent)]
RelativePath(#[from] RelativePathParseError),
#[error(transparent)]
GlobPattern(#[from] glob::PatternError),
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum FilePattern {
FilePath(RepoPathBuf),
PrefixPath(RepoPathBuf),
FileGlob {
dir: RepoPathBuf,
pattern: glob::Pattern,
},
}
impl FilePattern {
pub fn from_str_kind(
path_converter: &RepoPathUiConverter,
input: &str,
kind: &str,
) -> Result<Self, FilePatternParseError> {
match kind {
"cwd" => Self::cwd_prefix_path(path_converter, input),
"cwd-file" | "file" => Self::cwd_file_path(path_converter, input),
"cwd-glob" | "glob" => Self::cwd_file_glob(path_converter, input),
"root" => Self::root_prefix_path(input),
"root-file" => Self::root_file_path(input),
"root-glob" => Self::root_file_glob(input),
_ => Err(FilePatternParseError::InvalidKind(kind.to_owned())),
}
}
pub fn cwd_file_path(
path_converter: &RepoPathUiConverter,
input: impl AsRef<str>,
) -> Result<Self, FilePatternParseError> {
let path = path_converter.parse_file_path(input.as_ref())?;
Ok(FilePattern::FilePath(path))
}
pub fn cwd_prefix_path(
path_converter: &RepoPathUiConverter,
input: impl AsRef<str>,
) -> Result<Self, FilePatternParseError> {
let path = path_converter.parse_file_path(input.as_ref())?;
Ok(FilePattern::PrefixPath(path))
}
pub fn cwd_file_glob(
path_converter: &RepoPathUiConverter,
input: impl AsRef<str>,
) -> Result<Self, FilePatternParseError> {
let (dir, pattern) = split_glob_path(input.as_ref());
let dir = path_converter.parse_file_path(dir)?;
Self::file_glob_at(dir, pattern)
}
pub fn root_file_path(input: impl AsRef<str>) -> Result<Self, FilePatternParseError> {
let path = RepoPathBuf::from_relative_path(input.as_ref())?;
Ok(FilePattern::FilePath(path))
}
pub fn root_prefix_path(input: impl AsRef<str>) -> Result<Self, FilePatternParseError> {
let path = RepoPathBuf::from_relative_path(input.as_ref())?;
Ok(FilePattern::PrefixPath(path))
}
pub fn root_file_glob(input: impl AsRef<str>) -> Result<Self, FilePatternParseError> {
let (dir, pattern) = split_glob_path(input.as_ref());
let dir = RepoPathBuf::from_relative_path(dir)?;
Self::file_glob_at(dir, pattern)
}
fn file_glob_at(dir: RepoPathBuf, input: &str) -> Result<Self, FilePatternParseError> {
if input.is_empty() {
return Ok(FilePattern::FilePath(dir));
}
let normalized = RepoPathBuf::from_relative_path(input)?;
let pattern = glob::Pattern::new(normalized.as_internal_file_string())?;
Ok(FilePattern::FileGlob { dir, pattern })
}
pub fn as_path(&self) -> Option<&RepoPath> {
match self {
FilePattern::FilePath(path) => Some(path),
FilePattern::PrefixPath(path) => Some(path),
FilePattern::FileGlob { .. } => None,
}
}
}
fn split_glob_path(input: &str) -> (&str, &str) {
const GLOB_CHARS: &[char] = &['?', '*', '[', ']']; let prefix_len = input
.split_inclusive(path::is_separator)
.take_while(|component| !component.contains(GLOB_CHARS))
.map(|component| component.len())
.sum();
input.split_at(prefix_len)
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum FilesetExpression {
None,
All,
Pattern(FilePattern),
UnionAll(Vec<FilesetExpression>),
Intersection(Box<FilesetExpression>, Box<FilesetExpression>),
Difference(Box<FilesetExpression>, Box<FilesetExpression>),
}
impl FilesetExpression {
pub fn none() -> Self {
FilesetExpression::None
}
pub fn all() -> Self {
FilesetExpression::All
}
pub fn pattern(pattern: FilePattern) -> Self {
FilesetExpression::Pattern(pattern)
}
pub fn file_path(path: RepoPathBuf) -> Self {
FilesetExpression::Pattern(FilePattern::FilePath(path))
}
pub fn prefix_path(path: RepoPathBuf) -> Self {
FilesetExpression::Pattern(FilePattern::PrefixPath(path))
}
pub fn union_all(expressions: Vec<FilesetExpression>) -> Self {
match expressions.len() {
0 => FilesetExpression::none(),
1 => expressions.into_iter().next().unwrap(),
_ => FilesetExpression::UnionAll(expressions),
}
}
pub fn intersection(self, other: Self) -> Self {
FilesetExpression::Intersection(Box::new(self), Box::new(other))
}
pub fn difference(self, other: Self) -> Self {
FilesetExpression::Difference(Box::new(self), Box::new(other))
}
fn as_union_all(&self) -> &[Self] {
match self {
FilesetExpression::None => &[],
FilesetExpression::UnionAll(exprs) => exprs,
_ => slice::from_ref(self),
}
}
fn dfs_pre(&self) -> impl Iterator<Item = &Self> {
let mut stack: Vec<&Self> = vec![self];
iter::from_fn(move || {
let expr = stack.pop()?;
match expr {
FilesetExpression::None
| FilesetExpression::All
| FilesetExpression::Pattern(_) => {}
FilesetExpression::UnionAll(exprs) => stack.extend(exprs.iter().rev()),
FilesetExpression::Intersection(expr1, expr2)
| FilesetExpression::Difference(expr1, expr2) => {
stack.push(expr2);
stack.push(expr1);
}
}
Some(expr)
})
}
pub fn explicit_paths(&self) -> impl Iterator<Item = &RepoPath> {
self.dfs_pre().flat_map(|expr| match expr {
FilesetExpression::Pattern(pattern) => pattern.as_path(),
_ => None,
})
}
pub fn to_matcher(&self) -> Box<dyn Matcher> {
build_union_matcher(self.as_union_all())
}
}
fn build_union_matcher(expressions: &[FilesetExpression]) -> Box<dyn Matcher> {
let mut file_paths = Vec::new();
let mut prefix_paths = Vec::new();
let mut file_globs = Vec::new();
let mut matchers: Vec<Option<Box<dyn Matcher>>> = Vec::new();
for expr in expressions {
let matcher: Box<dyn Matcher> = match expr {
FilesetExpression::None => Box::new(NothingMatcher),
FilesetExpression::All => Box::new(EverythingMatcher),
FilesetExpression::Pattern(pattern) => {
match pattern {
FilePattern::FilePath(path) => file_paths.push(path),
FilePattern::PrefixPath(path) => prefix_paths.push(path),
FilePattern::FileGlob { dir, pattern } => {
file_globs.push((dir, pattern.clone()))
}
}
continue;
}
FilesetExpression::UnionAll(exprs) => build_union_matcher(exprs),
FilesetExpression::Intersection(expr1, expr2) => {
let m1 = build_union_matcher(expr1.as_union_all());
let m2 = build_union_matcher(expr2.as_union_all());
Box::new(IntersectionMatcher::new(m1, m2))
}
FilesetExpression::Difference(expr1, expr2) => {
let m1 = build_union_matcher(expr1.as_union_all());
let m2 = build_union_matcher(expr2.as_union_all());
Box::new(DifferenceMatcher::new(m1, m2))
}
};
matchers.push(Some(matcher));
}
if !file_paths.is_empty() {
matchers.push(Some(Box::new(FilesMatcher::new(file_paths))));
}
if !prefix_paths.is_empty() {
matchers.push(Some(Box::new(PrefixMatcher::new(prefix_paths))));
}
if !file_globs.is_empty() {
matchers.push(Some(Box::new(FileGlobsMatcher::new(file_globs))));
}
union_all_matchers(&mut matchers)
}
fn union_all_matchers(matchers: &mut [Option<Box<dyn Matcher>>]) -> Box<dyn Matcher> {
match matchers {
[] => Box::new(NothingMatcher),
[matcher] => matcher.take().expect("matcher should still be available"),
_ => {
let (left, right) = matchers.split_at_mut(matchers.len() / 2);
let m1 = union_all_matchers(left);
let m2 = union_all_matchers(right);
Box::new(UnionMatcher::new(m1, m2))
}
}
}
type FilesetFunction =
fn(&RepoPathUiConverter, &FunctionCallNode) -> FilesetParseResult<FilesetExpression>;
static BUILTIN_FUNCTION_MAP: Lazy<HashMap<&'static str, FilesetFunction>> = Lazy::new(|| {
let mut map: HashMap<&'static str, FilesetFunction> = HashMap::new();
map.insert("none", |_path_converter, function| {
function.expect_no_arguments()?;
Ok(FilesetExpression::none())
});
map.insert("all", |_path_converter, function| {
function.expect_no_arguments()?;
Ok(FilesetExpression::all())
});
map
});
fn resolve_function(
path_converter: &RepoPathUiConverter,
function: &FunctionCallNode,
) -> FilesetParseResult<FilesetExpression> {
if let Some(func) = BUILTIN_FUNCTION_MAP.get(function.name) {
func(path_converter, function)
} else {
Err(FilesetParseError::new(
FilesetParseErrorKind::NoSuchFunction {
name: function.name.to_owned(),
candidates: collect_similar(function.name, BUILTIN_FUNCTION_MAP.keys()),
},
function.name_span,
))
}
}
fn resolve_expression(
path_converter: &RepoPathUiConverter,
node: &ExpressionNode,
) -> FilesetParseResult<FilesetExpression> {
let wrap_pattern_error =
|err| FilesetParseError::expression("Invalid file pattern", node.span).with_source(err);
match &node.kind {
ExpressionKind::Identifier(name) => {
let pattern =
FilePattern::cwd_prefix_path(path_converter, name).map_err(wrap_pattern_error)?;
Ok(FilesetExpression::pattern(pattern))
}
ExpressionKind::String(name) => {
let pattern =
FilePattern::cwd_prefix_path(path_converter, name).map_err(wrap_pattern_error)?;
Ok(FilesetExpression::pattern(pattern))
}
ExpressionKind::StringPattern { kind, value } => {
let pattern = FilePattern::from_str_kind(path_converter, value, kind)
.map_err(wrap_pattern_error)?;
Ok(FilesetExpression::pattern(pattern))
}
ExpressionKind::Unary(op, arg_node) => {
let arg = resolve_expression(path_converter, arg_node)?;
match op {
UnaryOp::Negate => Ok(FilesetExpression::all().difference(arg)),
}
}
ExpressionKind::Binary(op, lhs_node, rhs_node) => {
let lhs = resolve_expression(path_converter, lhs_node)?;
let rhs = resolve_expression(path_converter, rhs_node)?;
match op {
BinaryOp::Intersection => Ok(lhs.intersection(rhs)),
BinaryOp::Difference => Ok(lhs.difference(rhs)),
}
}
ExpressionKind::UnionAll(nodes) => {
let expressions = nodes
.iter()
.map(|node| resolve_expression(path_converter, node))
.try_collect()?;
Ok(FilesetExpression::union_all(expressions))
}
ExpressionKind::FunctionCall(function) => resolve_function(path_converter, function),
}
}
pub fn parse(
text: &str,
path_converter: &RepoPathUiConverter,
) -> FilesetParseResult<FilesetExpression> {
let node = fileset_parser::parse_program(text)?;
resolve_expression(path_converter, &node)
}
pub fn parse_maybe_bare(
text: &str,
path_converter: &RepoPathUiConverter,
) -> FilesetParseResult<FilesetExpression> {
let node = fileset_parser::parse_program_or_bare_string(text)?;
resolve_expression(path_converter, &node)
}
#[cfg(test)]
mod tests {
use std::path::PathBuf;
use super::*;
fn repo_path_buf(value: impl Into<String>) -> RepoPathBuf {
RepoPathBuf::from_internal_string(value)
}
fn insta_settings() -> insta::Settings {
let mut settings = insta::Settings::clone_current();
for _ in 0..4 {
settings.add_filter(
r"(?x)
\b([A-Z]\w*)\(\n
\s*(.{1,60}),\n
\s*\)",
"$1($2)",
);
}
settings
}
#[test]
fn test_parse_file_pattern() {
let path_converter = RepoPathUiConverter::Fs {
cwd: PathBuf::from("/ws/cur"),
base: PathBuf::from("/ws"),
};
let parse = |text| parse_maybe_bare(text, &path_converter);
assert_eq!(
parse(".").unwrap(),
FilesetExpression::prefix_path(repo_path_buf("cur"))
);
assert_eq!(
parse("..").unwrap(),
FilesetExpression::prefix_path(RepoPathBuf::root())
);
assert!(parse("../..").is_err());
assert_eq!(
parse("foo").unwrap(),
FilesetExpression::prefix_path(repo_path_buf("cur/foo"))
);
assert_eq!(
parse("cwd:.").unwrap(),
FilesetExpression::prefix_path(repo_path_buf("cur"))
);
assert_eq!(
parse("cwd-file:foo").unwrap(),
FilesetExpression::file_path(repo_path_buf("cur/foo"))
);
assert_eq!(
parse("file:../foo/bar").unwrap(),
FilesetExpression::file_path(repo_path_buf("foo/bar"))
);
assert_eq!(
parse("root:.").unwrap(),
FilesetExpression::prefix_path(RepoPathBuf::root())
);
assert!(parse("root:..").is_err());
assert_eq!(
parse("root:foo/bar").unwrap(),
FilesetExpression::prefix_path(repo_path_buf("foo/bar"))
);
assert_eq!(
parse("root-file:bar").unwrap(),
FilesetExpression::file_path(repo_path_buf("bar"))
);
}
#[test]
fn test_parse_glob_pattern() {
let path_converter = RepoPathUiConverter::Fs {
cwd: PathBuf::from("/ws/cur*"),
base: PathBuf::from("/ws"),
};
let parse = |text| parse_maybe_bare(text, &path_converter);
let glob_expr = |dir: &str, pattern: &str| {
FilesetExpression::pattern(FilePattern::FileGlob {
dir: repo_path_buf(dir),
pattern: glob::Pattern::new(pattern).unwrap(),
})
};
assert_eq!(
parse(r#"cwd-glob:"foo""#).unwrap(),
FilesetExpression::file_path(repo_path_buf("cur*/foo"))
);
assert_eq!(
parse(r#"glob:"""#).unwrap(),
FilesetExpression::file_path(repo_path_buf("cur*"))
);
assert_eq!(
parse(r#"glob:".""#).unwrap(),
FilesetExpression::file_path(repo_path_buf("cur*"))
);
assert_eq!(
parse(r#"glob:"..""#).unwrap(),
FilesetExpression::file_path(RepoPathBuf::root())
);
assert_eq!(parse(r#"glob:"*""#).unwrap(), glob_expr("cur*", "*"));
assert_eq!(parse(r#"glob:"./*""#).unwrap(), glob_expr("cur*", "*"));
assert_eq!(parse(r#"glob:"../*""#).unwrap(), glob_expr("", "*"));
assert_eq!(parse(r#"glob:"**""#).unwrap(), glob_expr("cur*", "**"));
assert_eq!(
parse(r#"glob:"../foo/b?r/baz""#).unwrap(),
glob_expr("foo", "b?r/baz")
);
assert!(parse(r#"glob:"../../*""#).is_err());
assert!(parse(r#"glob:"/*""#).is_err());
assert!(parse(r#"glob:"*/..""#).is_err());
assert_eq!(
parse(r#"glob:"..\\foo\\*\\bar""#).unwrap(),
if cfg!(windows) {
glob_expr("foo", "*/bar")
} else {
glob_expr("cur*", r"..\foo\*\bar")
}
);
assert_eq!(
parse(r#"root-glob:"foo""#).unwrap(),
FilesetExpression::file_path(repo_path_buf("foo"))
);
assert_eq!(
parse(r#"root-glob:"""#).unwrap(),
FilesetExpression::file_path(RepoPathBuf::root())
);
assert_eq!(
parse(r#"root-glob:".""#).unwrap(),
FilesetExpression::file_path(RepoPathBuf::root())
);
assert_eq!(parse(r#"root-glob:"*""#).unwrap(), glob_expr("", "*"));
assert_eq!(
parse(r#"root-glob:"foo/bar/b[az]""#).unwrap(),
glob_expr("foo/bar", "b[az]")
);
assert!(parse(r#"root-glob:"../*""#).is_err());
assert!(parse(r#"root-glob:"/*""#).is_err());
}
#[test]
fn test_parse_function() {
let settings = insta_settings();
let _guard = settings.bind_to_scope();
let path_converter = RepoPathUiConverter::Fs {
cwd: PathBuf::from("/ws/cur"),
base: PathBuf::from("/ws"),
};
let parse = |text| parse_maybe_bare(text, &path_converter);
assert_eq!(parse("all()").unwrap(), FilesetExpression::all());
assert_eq!(parse("none()").unwrap(), FilesetExpression::none());
insta::assert_debug_snapshot!(parse("all(x)").unwrap_err().kind(), @r###"
InvalidArguments {
name: "all",
message: "Expected 0 arguments",
}
"###);
insta::assert_debug_snapshot!(parse("ale()").unwrap_err().kind(), @r###"
NoSuchFunction {
name: "ale",
candidates: [
"all",
],
}
"###);
}
#[test]
fn test_parse_compound_expression() {
let settings = insta_settings();
let _guard = settings.bind_to_scope();
let path_converter = RepoPathUiConverter::Fs {
cwd: PathBuf::from("/ws/cur"),
base: PathBuf::from("/ws"),
};
let parse = |text| parse_maybe_bare(text, &path_converter);
insta::assert_debug_snapshot!(parse("~x").unwrap(), @r###"
Difference(
All,
Pattern(PrefixPath("cur/x")),
)
"###);
insta::assert_debug_snapshot!(parse("x|y|root:z").unwrap(), @r###"
UnionAll(
[
Pattern(PrefixPath("cur/x")),
Pattern(PrefixPath("cur/y")),
Pattern(PrefixPath("z")),
],
)
"###);
insta::assert_debug_snapshot!(parse("x|y&z").unwrap(), @r###"
UnionAll(
[
Pattern(PrefixPath("cur/x")),
Intersection(
Pattern(PrefixPath("cur/y")),
Pattern(PrefixPath("cur/z")),
),
],
)
"###);
}
#[test]
fn test_explicit_paths() {
let collect = |expr: &FilesetExpression| -> Vec<RepoPathBuf> {
expr.explicit_paths().map(|path| path.to_owned()).collect()
};
let file_expr = |path: &str| FilesetExpression::file_path(repo_path_buf(path));
assert!(collect(&FilesetExpression::none()).is_empty());
assert_eq!(collect(&file_expr("a")), ["a"].map(repo_path_buf));
assert_eq!(
collect(&FilesetExpression::union_all(vec![
file_expr("a"),
file_expr("b"),
file_expr("c"),
])),
["a", "b", "c"].map(repo_path_buf)
);
assert_eq!(
collect(&FilesetExpression::intersection(
FilesetExpression::union_all(vec![
file_expr("a"),
FilesetExpression::none(),
file_expr("b"),
file_expr("c"),
]),
FilesetExpression::difference(
file_expr("d"),
FilesetExpression::union_all(vec![file_expr("e"), file_expr("f")])
)
)),
["a", "b", "c", "d", "e", "f"].map(repo_path_buf)
);
}
#[test]
fn test_build_matcher_simple() {
let settings = insta_settings();
let _guard = settings.bind_to_scope();
insta::assert_debug_snapshot!(FilesetExpression::none().to_matcher(), @"NothingMatcher");
insta::assert_debug_snapshot!(FilesetExpression::all().to_matcher(), @"EverythingMatcher");
insta::assert_debug_snapshot!(
FilesetExpression::file_path(repo_path_buf("foo")).to_matcher(),
@r###"
FilesMatcher {
tree: Dir {
"foo": File {},
},
}
"###);
insta::assert_debug_snapshot!(
FilesetExpression::prefix_path(repo_path_buf("foo")).to_matcher(),
@r###"
PrefixMatcher {
tree: Dir {
"foo": Prefix {},
},
}
"###);
}
#[test]
fn test_build_matcher_glob_pattern() {
let settings = insta_settings();
let _guard = settings.bind_to_scope();
let glob_expr = |dir: &str, pattern: &str| {
FilesetExpression::pattern(FilePattern::FileGlob {
dir: repo_path_buf(dir),
pattern: glob::Pattern::new(pattern).unwrap(),
})
};
insta::assert_debug_snapshot!(glob_expr("", "*").to_matcher(), @r###"
FileGlobsMatcher {
tree: [
Pattern {
original: "*",
tokens: [
AnySequence,
],
is_recursive: false,
},
] {},
}
"###);
let expr =
FilesetExpression::union_all(vec![glob_expr("foo", "*"), glob_expr("foo/bar", "*")]);
insta::assert_debug_snapshot!(expr.to_matcher(), @r###"
FileGlobsMatcher {
tree: [] {
"foo": [
Pattern {
original: "*",
tokens: [
AnySequence,
],
is_recursive: false,
},
] {
"bar": [
Pattern {
original: "*",
tokens: [
AnySequence,
],
is_recursive: false,
},
] {},
},
},
}
"###);
}
#[test]
fn test_build_matcher_union_patterns_of_same_kind() {
let settings = insta_settings();
let _guard = settings.bind_to_scope();
let expr = FilesetExpression::union_all(vec![
FilesetExpression::file_path(repo_path_buf("foo")),
FilesetExpression::file_path(repo_path_buf("foo/bar")),
]);
insta::assert_debug_snapshot!(expr.to_matcher(), @r###"
FilesMatcher {
tree: Dir {
"foo": File {
"bar": File {},
},
},
}
"###);
let expr = FilesetExpression::union_all(vec![
FilesetExpression::prefix_path(repo_path_buf("bar")),
FilesetExpression::prefix_path(repo_path_buf("bar/baz")),
]);
insta::assert_debug_snapshot!(expr.to_matcher(), @r###"
PrefixMatcher {
tree: Dir {
"bar": Prefix {
"baz": Prefix {},
},
},
}
"###);
}
#[test]
fn test_build_matcher_union_patterns_of_different_kind() {
let settings = insta_settings();
let _guard = settings.bind_to_scope();
let expr = FilesetExpression::union_all(vec![
FilesetExpression::file_path(repo_path_buf("foo")),
FilesetExpression::prefix_path(repo_path_buf("bar")),
]);
insta::assert_debug_snapshot!(expr.to_matcher(), @r###"
UnionMatcher {
input1: FilesMatcher {
tree: Dir {
"foo": File {},
},
},
input2: PrefixMatcher {
tree: Dir {
"bar": Prefix {},
},
},
}
"###);
}
#[test]
fn test_build_matcher_unnormalized_union() {
let settings = insta_settings();
let _guard = settings.bind_to_scope();
let expr = FilesetExpression::UnionAll(vec![]);
insta::assert_debug_snapshot!(expr.to_matcher(), @"NothingMatcher");
let expr =
FilesetExpression::UnionAll(vec![FilesetExpression::None, FilesetExpression::All]);
insta::assert_debug_snapshot!(expr.to_matcher(), @r###"
UnionMatcher {
input1: NothingMatcher,
input2: EverythingMatcher,
}
"###);
}
#[test]
fn test_build_matcher_combined() {
let settings = insta_settings();
let _guard = settings.bind_to_scope();
let expr = FilesetExpression::union_all(vec![
FilesetExpression::intersection(FilesetExpression::all(), FilesetExpression::none()),
FilesetExpression::difference(FilesetExpression::none(), FilesetExpression::all()),
FilesetExpression::file_path(repo_path_buf("foo")),
FilesetExpression::prefix_path(repo_path_buf("bar")),
]);
insta::assert_debug_snapshot!(expr.to_matcher(), @r###"
UnionMatcher {
input1: UnionMatcher {
input1: IntersectionMatcher {
input1: EverythingMatcher,
input2: NothingMatcher,
},
input2: DifferenceMatcher {
wanted: NothingMatcher,
unwanted: EverythingMatcher,
},
},
input2: UnionMatcher {
input1: FilesMatcher {
tree: Dir {
"foo": File {},
},
},
input2: PrefixMatcher {
tree: Dir {
"bar": Prefix {},
},
},
},
}
"###);
}
}