Ejemplo n.º 1
0
        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");
        }
Ejemplo n.º 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",
            }));
        }
Ejemplo n.º 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"
            }));
        }
Ejemplo n.º 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",
            }));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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"
            }));
        }
Ejemplo n.º 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));
        }