Пример #1
0
        public void GenerateNFA()
        {
            const string expected =
                "0 -- e --> 1\r\n";

            Assert.That(FARenderer.Render(ReUtils.Build(ReEmptyString.Instance)), Is.EqualTo(expected));
        }
Пример #2
0
        public void GenerateNFA()
        {
            const string expected =
                "";

            Assert.That(FARenderer.Render(ReUtils.Build(ReEmptyLanguage.Instance)), Is.EqualTo(expected));
        }
Пример #3
0
        public void Concatenation_Single()
        {
            var child = ReUtils.NewDummy('1');

            var element = ReFactory.NewConcatenation(new ReElement[] { child });

            Assert.That(element, Is.SameAs(element));
        }
Пример #4
0
        public void Union_Single()
        {
            var child = ReUtils.NewDummy('1');

            var element = ReFactory.NewUnion(ImmutableArray.Create(child));

            Assert.That(element, Is.SameAs(child));
        }
Пример #5
0
        public void KleeneStar_NestedKleenStar()
        {
            var child   = ReUtils.NewDummy('1');
            var subStar = new ReKleeneStar(child);

            var element = ReFactory.NewKleeneStar(subStar);

            Assert.That(element, Is.SameAs(subStar));
        }
Пример #6
0
        public void GenerateNFA()
        {
            var element = new ReSingleton(CharSet.New('1'));

            const string expected =
                "0 -- [1] --> 1\r\n" +
                "";

            Assert.That(FARenderer.Render(ReUtils.Build(element)), Is.EqualTo(expected));
        }
Пример #7
0
        public void Concatenation_Broken()
        {
            var child1 = ReUtils.NewDummy('1');
            var child2 = ReUtils.NewDummy('2');
            var broke  = ReEmptyLanguage.Instance;

            var element = ReFactory.NewConcatenation(ImmutableArray.Create(child1, broke, child2));

            Assert.That(element, Is.SameAs(broke));
        }
Пример #8
0
        public void Repetition_0ToU()
        {
            var child = ReUtils.NewDummy('1');

            var element = ReFactory.NewRepetition(child, 0, null);

            Assert.That(element, Is.Not.Null);
            Assert.That(element, Is.TypeOf(typeof(ReKleeneStar)));

            var star = (ReKleeneStar)element;

            Assert.That(star.Element, Is.SameAs(child));
        }
Пример #9
0
        public void Repetition_2()
        {
            var child = ReUtils.NewDummy('1');

            var element = ReFactory.NewRepetition(child, 2, 2);

            Assert.That(element, Is.Not.Null);
            Assert.That(element, Is.TypeOf(typeof(ReConcatenation)));

            var concat = (ReConcatenation)element;

            Assert.That(concat.Elements, Is.EquivalentTo(new ReElement[] { child, child }));
        }
Пример #10
0
        public void GenerateNFA()
        {
            var element    = ReUtils.NewDummy('1');
            var kleeneStar = new ReKleeneStar(element);

            const string expected =
                "0 -- e --> 1\r\n" +
                "1 -- [1] --> 1\r\n" +
                "1 -- e --> 2\r\n" +
                "";

            Assert.That(FARenderer.Render(ReUtils.Build(kleeneStar)), Is.EqualTo(expected));
        }
Пример #11
0
        public void KleenStar_NonNested()
        {
            var child = ReUtils.NewDummy('1');

            var element = ReFactory.NewKleeneStar(child);

            Assert.That(element, Is.Not.Null);
            Assert.That(element, Is.TypeOf(typeof(ReKleeneStar)));

            var star = (ReKleeneStar)element;

            Assert.That(star.Element, Is.SameAs(child));
        }
Пример #12
0
        public void GenerateNFA()
        {
            var element1 = ReUtils.NewDummy('1');
            var element2 = ReUtils.NewDummy('2');

            var choice = new ReUnion(ImmutableArray.Create(element1, element2));

            const string expected =
                "0 -- [1] --> 1\r\n" +
                "0 -- [2] --> 1\r\n" +
                "";

            Assert.That(FARenderer.Render(ReUtils.Build(choice)), Is.EqualTo(expected));
        }
Пример #13
0
        public void Repetition_0To1()
        {
            var child = ReUtils.NewDummy('1');

            var element = ReFactory.NewRepetition(child, 0, 1);

            Assert.That(element, Is.Not.Null);
            Assert.That(element, Is.TypeOf(typeof(ReUnion)));

            var elements = new List <ReElement>(((ReUnion)element).Elements);

            Assert.That(elements.Count, Is.EqualTo(2));
            Assert.That(elements[0], Is.SameAs(child));
            Assert.That(elements[1], Is.Not.Null);
            Assert.That(elements[1], Is.TypeOf(typeof(ReEmptyString)));
        }
Пример #14
0
        public void Concatenation_Collapse()
        {
            var child1    = ReUtils.NewDummy('1');
            var child2    = ReUtils.NewDummy('2');
            var child3    = ReUtils.NewDummy('3');
            var child4    = ReUtils.NewDummy('4');
            var subConcat = new ReConcatenation(ImmutableArray.Create(child2, child3));

            var element = ReFactory.NewConcatenation(new ReElement[] { child1, subConcat, ReEmptyString.Instance, child4 });

            Assert.That(element, Is.Not.Null);
            Assert.That(element, Is.TypeOf(typeof(ReConcatenation)));

            var concat = (ReConcatenation)element;

            Assert.That(concat.Elements, Is.EquivalentTo(new ReElement[] { child1, child2, child3, child4 }));
        }
Пример #15
0
        public void Union_Collapse()
        {
            var child1 = ReUtils.NewDummy('1');
            var child2 = ReUtils.NewDummy('2');
            var child3 = ReUtils.NewDummy('3');
            var child4 = ReUtils.NewDummy('4');

            var subUnion = new ReUnion(ImmutableArray.Create(child2, child3));

            var element = ReFactory.NewUnion(new ReElement[] { child1, subUnion, ReEmptyLanguage.Instance, child4 });

            Assert.That(element, Is.Not.Null);
            Assert.That(element, Is.TypeOf(typeof(ReUnion)));

            var union = (ReUnion)element;

            Assert.That(union.Elements, Is.EquivalentTo(new ReElement[] { child1, child2, child3, child4 }));
        }
Пример #16
0
        public void Constructor()
        {
            var element1 = ReUtils.NewDummy('1');
            var element2 = ReUtils.NewDummy('2');

            var elements = ImmutableArray.Create(
                element1,
                element2);

            var choice = new ReUnion(elements);

            var enumerator = choice.Elements.GetEnumerator();

            Assert.That(enumerator.MoveNext(), Is.EqualTo(true), "should have element[0]");
            Assert.That(enumerator.Current, Is.SameAs(element1), "element[0] should be mock1");
            Assert.That(enumerator.MoveNext(), Is.EqualTo(true), "should have element[1]");
            Assert.That(enumerator.Current, Is.SameAs(element2), "element[1] should be mock2");
            Assert.That(enumerator.MoveNext(), Is.EqualTo(false), "should not have element[2]");
        }
Пример #17
0
        public void Repetition_1ToU()
        {
            var child = ReUtils.NewDummy('1');

            var element = ReFactory.NewRepetition(child, 1, null);

            Assert.That(element, Is.Not.Null);
            Assert.That(element, Is.TypeOf(typeof(ReConcatenation)));

            var concatElements = new List <ReElement>(((ReConcatenation)element).Elements);

            Assert.That(concatElements.Count, Is.EqualTo(2));
            Assert.That(concatElements[0], Is.SameAs(child));
            Assert.That(concatElements[1], Is.Not.Null);
            Assert.That(concatElements[1], Is.TypeOf(typeof(ReKleeneStar)));

            var star = (ReKleeneStar)concatElements[1];

            Assert.That(star.Element, Is.SameAs(child));
        }