Пример #1
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",
            }));
        }
Пример #2
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");
        }
Пример #3
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"
            }));
        }