Ejemplo n.º 1
0
        public void TestAdvanceToEndSimpleRegex()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("A1B");
            IBeforeItemGraphkenState <string, int, Func <string, bool>, Func <int, bool> > initState = regex.CreateState();

            Func <Func <string, bool>, string, bool> itemMatch = (f, i) => f(i);
            Func <Func <int, bool>, int, bool>       dependencyMatch = (f, d) => f(d);
            bool atEnd, atCount;

            IBeforeDependencyGraphkenState <string, int, Func <string, bool>, Func <int, bool> > stateAfterA =
                initState.Advance("A", itemMatch, out atEnd, out atCount);

            Assert.IsTrue(stateAfterA.CanContinue);
            Assert.IsFalse(atEnd);

            IBeforeItemGraphkenState <string, int, Func <string, bool>, Func <int, bool> > stateAfter1 =
                stateAfterA.Advance(1, dependencyMatch, out atCount);

            Assert.IsTrue(stateAfter1.CanContinue);

            IBeforeDependencyGraphkenState <string, int, Func <string, bool>, Func <int, bool> > stateAfterB =
                stateAfter1.Advance("B", itemMatch, out atEnd, out atCount);

            Assert.IsTrue(stateAfterB.CanContinue);
            Assert.IsTrue(atEnd);
        }
Ejemplo n.º 2
0
        public void TestUsePredefinedItemMatch()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("A.B",
                                                                new Dictionary <string, Func <string, bool> > {
                { "A", i => i == "B" }
            });

            Assert.IsNotNull(regex);
        }
Ejemplo n.º 3
0
        public void TestUsePredefinedDependencyMatch()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex(":1:",
                                                                definedDependencyMatches: new Dictionary <string, Func <int, bool> > {
                { "1", i => i == 2 }
            });

            Assert.IsNotNull(regex);
        }
Ejemplo n.º 4
0
        public void TestCreateStateFromSimpleRegex()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("A1B");

            Assert.IsNotNull(regex);
            IBeforeItemGraphkenState <string, int, Func <string, bool>, Func <int, bool> > initState = regex.CreateState();

            Assert.IsTrue(initState.CanContinue);
        }
Ejemplo n.º 5
0
        private IBeforeDependencyGraphkenState <string, int, Func <string, bool>, Func <int, bool> > AdvanceToEnd(
            string pattern, string msg, string[] objects)
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex(pattern);

            //Console.WriteLine(regex.GetGraphkenRepresentation());

            IBeforeItemGraphkenState <string, int, Func <string, bool>, Func <int, bool> > beforeItemState =
                regex.CreateState();

            Assert.IsTrue(beforeItemState.CanContinue);

            Func <Func <string, bool>, string, bool> itemMatch       = (f, i) => f(i);
            Func <Func <int, bool>, int, bool>       dependencyMatch = (f, d) => f(d);

            for (int i = 0; ; i++)
            {
                bool atCount;
                IBeforeDependencyGraphkenState <string, int, Func <string, bool>, Func <int, bool> > beforeDependencyState;
                {
                    string item = objects[i];
                    bool   atEnd;
                    beforeDependencyState = beforeItemState.Advance(item.TrimStart('+', '#', '$'), itemMatch, out atEnd,
                                                                    out atCount);
                    Assert.AreNotEqual(item.Contains("#"), beforeDependencyState.CanContinue,
                                       "CanContinue wrong for " + item + msg);
                    Assert.AreEqual(item.Contains("-"), atEnd, "AtEnd wrong for " + item + msg);
                    Assert.AreEqual(item.Contains("$"), atCount, "AtCount wrong for " + item + msg);
                }
                if (++i >= objects.Length)
                {
                    return(beforeDependencyState);
                }
                {
                    string dependency = objects[i];
                    beforeItemState = beforeDependencyState.Advance(int.Parse(dependency.TrimStart('+', '#', '$')),
                                                                    dependencyMatch, out atCount);
                    Assert.AreNotEqual(dependency.Contains("#"), beforeItemState.CanContinue,
                                       "CanContinue wrong for " + dependency + msg);
                    Assert.AreEqual(dependency.Contains("$"), atCount, "AtCount wrong for " + dependency + msg);
                }
            }
        }
Ejemplo n.º 6
0
        public void TestCreateSingleItemSetRegex()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("[A]1B");

            Assert.IsNotNull(regex);
        }
Ejemplo n.º 7
0
        public void TestCreateAlternativeRegex()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("A|B");

            Assert.IsNotNull(regex);
        }
Ejemplo n.º 8
0
        public void TestCreateOptionalRegex()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("A(1B)?2C");

            Assert.IsNotNull(regex);
        }
Ejemplo n.º 9
0
        public void TestCreateAnyItemRegexes()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex(":1:");

            Assert.IsNotNull(regex);
        }
Ejemplo n.º 10
0
        public void TestCreateAnyDependencyRegex()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("A.B");

            Assert.IsNotNull(regex);
        }
Ejemplo n.º 11
0
        public void TestCreateNegativeItemSetRegex()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("[^A]2B");

            Assert.IsNotNull(regex);
        }
Ejemplo n.º 12
0
        public void TestCreateNegativeDependencySetRegex()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("A[^2]B");

            Assert.IsNotNull(regex);
        }
Ejemplo n.º 13
0
        public void TestCreateEmptySequenceRegex()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("A()2B");

            Assert.IsNotNull(regex);
        }
Ejemplo n.º 14
0
        public void TestCreateDependencySetRegex()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("{Abc}[2{34}]C");

            Assert.IsNotNull(regex);
        }
Ejemplo n.º 15
0
        public void TestCreateSimpleRegex()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("A1B");

            Assert.IsNotNull(regex);
        }
Ejemplo n.º 16
0
        public void TestCreateAlternativeWithEmptyDependencyRegex()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("A(1B|2C|)");

            Assert.IsNotNull(regex);
        }
Ejemplo n.º 17
0
        public void TestCreateSimpleLongnameRegex()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("{Abc}{123}{Bcd}");

            Assert.IsNotNull(regex);
        }
Ejemplo n.º 18
0
        public void TestCreateSimpleDependencyCountRegex()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("A1(B2#)*C");

            Assert.IsNotNull(regex);
        }
Ejemplo n.º 19
0
        public void TestCreateSimpleItemCountRegex()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("A1(B#2)*C");

            Assert.IsNotNull(regex);
        }
Ejemplo n.º 20
0
        public void TestCreateNestedRegex()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("A((1B|(2C(3D)?)*|)+)*");

            Assert.IsNotNull(regex);
        }
Ejemplo n.º 21
0
        public void TestCreateAlternativeWithEmptyItemRegex()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("(B1|C2|)D3");

            Assert.IsNotNull(regex);
        }
Ejemplo n.º 22
0
        public void TestCreateSingleDependencySetRegex()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("A[1]B");

            Assert.IsNotNull(regex);
        }
Ejemplo n.º 23
0
        public void TestCreateItemSetRegex()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("[{Abc}B]2C");

            Assert.IsNotNull(regex);
        }
Ejemplo n.º 24
0
        public void TestCreateLoopRegex()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("A(1B)*");

            Assert.IsNotNull(regex);
        }
Ejemplo n.º 25
0
        public void TestCreateOneOrMoreRegex()
        {
            SimpleTestPathRegex regex = new SimpleTestPathRegex("A(1B)+");

            Assert.IsNotNull(regex);
        }