public void ExerciseMultiGlobMatchEnumerator()
        {
            TestContext.WriteLine($"CLR Version: {Environment.Version}");
            TestContext.WriteLine($"Runtime: {AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName}");

            var parser   = new GlobParser();
            var includes = new []
            {
                parser.Parse("**/Microsoft*/**/*.dll"),
                parser.Parse("Program*/**/*.exe"),
            };
            var excludes = new []
            {
                parser.Parse("**/SQL*/**")
            };

            var hierarchy  = new FileSystemHierarchy(new DirectoryInfo("C:\\"), false);
            var enumerator = new MultiGlobMatchEnumerator()
                             .Exclude(excludes)
                             .Include(includes);

            var count = enumerator.EnumerateMatches(hierarchy).Count();

            TestContext.WriteLine($"{count} matches");
        }
示例#2
0
        public void EarlierRulesTakePrecedence_ExcludeBeforeInclude()
        {
            var hierarchy = new TestHierarchy(
                new SimpleMatchable("root",
                                    new SimpleMatchable("dev",
                                                        new SimpleMatchable("hda"),
                                                        new SimpleMatchable("hda1"),
                                                        new SimpleMatchable("hdb"),
                                                        new SimpleMatchable("hdb1"),
                                                        new SimpleMatchable("hdb2")),
                                    new SimpleMatchable("home",
                                                        new SimpleMatchable("me",
                                                                            new SimpleMatchable("hdmi")),
                                                        new SimpleMatchable("you")),
                                    new SimpleMatchable("var")));

            var parser = new GlobParser();

            var enumerator = new MultiGlobMatchEnumerator().Include(parser.Parse("**"));
            var filter     = new MultiGlobMatchFilter(hierarchy.CaseSensitive)
                             .Exclude(parser.Parse("dev/**"))
                             .Include(parser.Parse("**/hd[am]?"));

            var matches = enumerator.EnumerateMatches(hierarchy)
                          .Where(filter.Filter)
                          .ToArray();

            Assert.That(matches.Select(m => m.Item.Name).ToArray(),
                        Is.EquivalentTo(new []
            {
                "hdmi",
            }));
        }
示例#3
0
        public void FindsAllUniqueMatchesOfIncludesNotMatchedByExcludes()
        {
            var hierarchy = new TestHierarchy(
                new SimpleMatchable("root",
                                    new SimpleMatchable("dev",
                                                        new SimpleMatchable("hda"),
                                                        new SimpleMatchable("hda1"),
                                                        new SimpleMatchable("hdb"),
                                                        new SimpleMatchable("hdb1"),
                                                        new SimpleMatchable("hdb2")),
                                    new SimpleMatchable("home",
                                                        new SimpleMatchable("me",
                                                                            new SimpleMatchable("hdmi")),
                                                        new SimpleMatchable("you")),
                                    new SimpleMatchable("var")));

            var parser = new GlobParser();

            var matches = new MultiGlobMatchEnumerator()
                          .Exclude(parser.Parse("home/*/**"))
                          .Include(parser.Parse("**/h*"))
                          .EnumerateMatches(hierarchy);

            Assert.That(matches.Select(m => m.Item.Name).ToArray(),
                        Is.EquivalentTo(new []
            {
                "hda",
                "hda1",
                "hdb",
                "hdb1",
                "hdb2",
                "home"
            }));
        }
示例#4
0
        public void MatcherWithOnlyRecursiveExclusionRulesMatchingWithinASubtree_DoesNotMatchWithinThatSubtree()
        {
            var hierarchy = new TestHierarchy(
                new SimpleMatchable("root",
                                    new SimpleMatchable("dev",
                                                        new SimpleMatchable("hda"),
                                                        new SimpleMatchable("hda1"),
                                                        new SimpleMatchable("hdb"),
                                                        new SimpleMatchable("hdb1"),
                                                        new SimpleMatchable("hdb2")),
                                    new SimpleMatchable("home",
                                                        new SimpleMatchable("me",
                                                                            new SimpleMatchable("hdmi")),
                                                        new SimpleMatchable("you")),
                                    new SimpleMatchable("var")));

            var parser = new GlobParser();

            var matches = new MultiGlobMatchEnumerator()
                          .Exclude(parser.Parse("d*/**"))
                          .Include(parser.Parse("d*"))
                          .EnumerateMatches(hierarchy).ToArray();

            Assert.That(matches.Select(m => m.Item.Name).ToArray(),
                        Is.EquivalentTo(new []
            {
                "dev",
            }));
        }
示例#5
0
        public void MatcherWithOnlyExclusionRulesMatchingInitially_MatchesNothing()
        {
            var hierarchy = new TestHierarchy(
                new SimpleMatchable("root",
                                    new SimpleMatchable("dev",
                                                        new SimpleMatchable("hda"),
                                                        new SimpleMatchable("hda1"),
                                                        new SimpleMatchable("hdb"),
                                                        new SimpleMatchable("hdb1"),
                                                        new SimpleMatchable("hdb2")),
                                    new SimpleMatchable("home",
                                                        new SimpleMatchable("me",
                                                                            new SimpleMatchable("hdmi")),
                                                        new SimpleMatchable("you")),
                                    new SimpleMatchable("var")));

            var parser = new GlobParser();

            var matches = new MultiGlobMatchEnumerator()
                          .Exclude(parser.Parse("dev/**"))
                          .Exclude(parser.Parse("**/hd[am]?"))
                          .Include(parser.Parse("nothing/**"))
                          .EnumerateMatches(hierarchy).ToArray();

            Assert.That(matches.Select(m => m.Item.Name).ToArray(), Is.Empty);
        }
示例#6
0
        public void ContainerExclusionDoesNotApplyRecursively()
        {
            var hierarchy = new TestHierarchy(
                new SimpleMatchable("root",
                                    new SimpleMatchable("dev",
                                                        new SimpleMatchable("hda"),
                                                        new SimpleMatchable("hda1"),
                                                        new SimpleMatchable("hdb"),
                                                        new SimpleMatchable("hdb1"),
                                                        new SimpleMatchable("hdb2")),
                                    new SimpleMatchable("home",
                                                        new SimpleMatchable("me",
                                                                            new SimpleMatchable("hdmi")),
                                                        new SimpleMatchable("you")),
                                    new SimpleMatchable("var")));

            var parser   = new GlobParser();
            var includes = new []
            {
                parser.Parse("**/h*")
            };
            var excludes = new []
            {
                parser.Parse("home")
            };

            var enumerator = new MultiGlobMatchEnumerator().Include(parser.Parse("**"));
            var filter     = new MultiGlobMatchFilter(hierarchy.CaseSensitive)
                             .Exclude(excludes)
                             .Include(includes);

            var matches = enumerator.EnumerateMatches(hierarchy)
                          .Where(filter.Filter)
                          .ToArray();

            Assert.That(matches.Select(m => m.Item.Name).ToArray(),
                        Is.EquivalentTo(new []
            {
                "hda",
                "hda1",
                "hdb",
                "hdb1",
                "hdb2",
                "hdmi"
            }));
        }
示例#7
0
        public void YieldsDetailsForEveryMatchingIncludeGlob()
        {
            var hierarchy = new TestHierarchy(
                new SimpleMatchable("root",
                                    new SimpleMatchable("dev",
                                                        new SimpleMatchable("hda"),
                                                        new SimpleMatchable("hda1"),
                                                        new SimpleMatchable("hdb"),
                                                        new SimpleMatchable("hdb1"),
                                                        new SimpleMatchable("hdb2")),
                                    new SimpleMatchable("home",
                                                        new SimpleMatchable("me",
                                                                            new SimpleMatchable("hdmi")),
                                                        new SimpleMatchable("you")),
                                    new SimpleMatchable("var")));

            var parser   = new GlobParser();
            var includes = new []
            {
                parser.Parse("**/hd[am]?"),
                parser.Parse("home/**")
            };

            var matches = new MultiGlobMatchEnumerator()
                          .Include(includes)
                          .EnumerateMatches(hierarchy).ToArray();

            Assume.That(matches.Select(m => m.Item.Name).ToArray(),
                        Is.EquivalentTo(new []
            {
                "hda1",
                "me",
                "hdmi",
                "you"
            }));

            var hdmiMatch = matches.Single(m => m.Item.Name == "hdmi");

            Assert.That(hdmiMatch.Details.Select(s => s.Glob).ToArray(), Is.EquivalentTo(includes));
        }