Example #1
0
        public void TwoAsterisksBeforeEnd()
        {
            GitIgnoreReader reader = new GitIgnoreReader();

            reader.Parse(new string[] { "abc/**" });

            var cases = new Dictionary <string, bool>()
            {
                { "abc", true },
                { "abc/bbb", true },
                { "abc/abc", true },
                { "abc/bbb/ccc", true },
                { "bbb/ccc", false },
                { "bbb", false },
                { "zhopa", false },
            };

            foreach (var pair in cases)
            {
                Assert.AreEqual(pair.Value, !reader.IsMatch(pair.Key), pair.Key);
            }
        }
Example #2
0
        public void TwoAsterisksAtStart()
        {
            GitIgnoreReader reader = new GitIgnoreReader();

            reader.Parse(new string[] { "**/foo", "**/foo/bar" });

            var cases = new Dictionary <string, bool>()
            {
                { "foo", true },
                { "aa/foo", true },
                { "aa/bb/foo", true },
                { "foo/bar", true },
                { "aa/bb/foo/bar", true },
                { "bar", false },
                { "aaa/bar", false },
                { "zhopa", false },
            };

            foreach (var pair in cases)
            {
                Assert.AreEqual(pair.Value, !reader.IsMatch(pair.Key), pair.Key);
            }
        }
Example #3
0
        public void OneAsterisk()
        {
            GitIgnoreReader reader = new GitIgnoreReader();

            reader.Parse(new string[] {
                "hello.*",
                "hello*.*",
                "node_modules/",
            });

            var cases = new Dictionary <string, bool>()
            {
                { "hello.java", true },
                { "hello.cs", true },
                { "abc/hello_world.c", true },
                { "abc/foo/hello_hello.hello", true },
                { "hello_world", false },
                { "goodbye.c", false },
                { "bar/goodbye", false },

                { "C:/foo/.git/", true },
                { "C:/foo/.git/abc", true },
                { "C:/foo/node_modules/", true },
                { "C:/foo/node_modules/abc", true },
            };

            foreach (var pair in cases)
            {
                var(pos, neg) = reader.GetMatches(pair.Key);

                Console.WriteLine(pair.Key + ": ");
                Console.WriteLine(reader.MatchesToString(pos, neg));

                Assert.AreEqual(pair.Value, !reader.IsMatch(pair.Key), pair.Key);
            }
        }
Example #4
0
        public void TwoAsterisksInMiddle()
        {
            GitIgnoreReader reader = new GitIgnoreReader();

            reader.Parse(new string[] { "a/**/b" });

            var cases = new Dictionary <string, bool>()
            {
                { "a/", false },
                { "/b", false },
                { "axb", false },
                { "ab", false },
                { "a/b", true },
                { "a/x/b", true },
                { "a/x/y/b", true },
                { "a/x/y/z/b", true },
                { "a/x/y/z/b/sub", true },
            };

            foreach (var pair in cases)
            {
                Assert.AreEqual(pair.Value, !reader.IsMatch(pair.Key), pair.Key);
            }
        }