Esempio n. 1
0
        public void ExactlyN()
        {
            for (int n = 0; n < 15; ++n)
            {
                var parser = new QuantifiedParser <string>(AsteriscParser, QuantificationRule.ExactlyN, n);

                for (var i = n - 1; i >= 0; --i)
                {
                    parser.Parse(AsteriscStream(i)).Success.ShouldBe(false);
                    parser.ParseGenerally(AsteriscStream(i)).Success.ShouldBe(false);
                }

                var r = parser.Parse(AsteriscStream(n));

                r.Success.ShouldBe(true);
                r.ParsedValue.Count.ShouldBe(n);

                parser.ParseGenerally(AsteriscStream(n)).Success.ShouldBe(true);

                for (var i = n + 1; i < n + 15; ++i)
                {
                    parser.Parse(AsteriscStream(i)).Success.ShouldBe(false);
                    parser.ParseGenerally(AsteriscStream(i)).Success.ShouldBe(false);
                }
            }

            for (int n = 0; n < 15; ++n)
            {
                var parser = new QuantifiedParser <string>(AsteriscParser, QuantificationRule.ExactlyN, n, -1, SeparatorParser);

                for (var i = n - 1; i >= 0; --i)
                {
                    parser.Parse(AsteriscStream(i, true)).Success.ShouldBe(false);
                    parser.ParseGenerally(AsteriscStream(i, true)).Success.ShouldBe(false);
                }

                var r = parser.Parse(AsteriscStream(n, true));

                r.Success.ShouldBe(true);
                r.ParsedValue.Count.ShouldBe(n);

                parser.ParseGenerally(AsteriscStream(n, true)).Success.ShouldBe(true);

                for (var i = n + 1; i < n + 15; ++i)
                {
                    parser.Parse(AsteriscStream(i, true)).Success.ShouldBe(false);
                    parser.ParseGenerally(AsteriscStream(i, true)).Success.ShouldBe(false);
                }
            }
        }
Esempio n. 2
0
        public void NOrLess()
        {
            for (int n = 0; n < 15; ++n)
            {
                var parser = new QuantifiedParser <string>(AsteriscParser, QuantificationRule.NOrLess, n);

                for (var i = 0; i <= n; ++i)
                {
                    var r = parser.Parse(AsteriscStream(i));

                    r.Success.ShouldBe(true);
                    r.ParsedValue.Count.ShouldBe(i);

                    parser.ParseGenerally(AsteriscStream(i)).Success.ShouldBe(true);
                }

                for (var i = n + 1; i <= n + 15; ++i)
                {
                    parser.Parse(AsteriscStream(i)).Success.ShouldBe(false);
                    parser.ParseGenerally(AsteriscStream(i)).Success.ShouldBe(false);
                }
            }

            for (int n = 0; n < 15; ++n)
            {
                var parser = new QuantifiedParser <string>(AsteriscParser, QuantificationRule.NOrLess, n, -1, SeparatorParser);

                for (var i = 0; i <= n; ++i)
                {
                    var r = parser.Parse(AsteriscStream(i, true));

                    r.Success.ShouldBe(true);
                    r.ParsedValue.Count.ShouldBe(i);

                    parser.ParseGenerally(AsteriscStream(i, true)).Success.ShouldBe(true);
                }

                for (var i = n + 1; i <= n + 15; ++i)
                {
                    parser.Parse(AsteriscStream(i, true)).Success.ShouldBe(false);
                    parser.ParseGenerally(AsteriscStream(i, true)).Success.ShouldBe(false);
                }
            }
        }
Esempio n. 3
0
        public void NtoM()
        {
            for (int n = 0; n < 15; ++n)
            {
                for (int m = n; m < n + 10; ++m)
                {
                    var parser = new QuantifiedParser <string>(AsteriscParser, QuantificationRule.NtoM, n, m);

                    for (var i = 0; i < n; ++i)
                    {
                        parser.Parse(AsteriscStream(i)).Success.ShouldBe(false);
                        parser.ParseGenerally(AsteriscStream(i)).Success.ShouldBe(false);
                    }

                    for (var i = n; i <= m; ++i)
                    {
                        var r = parser.Parse(AsteriscStream(i));

                        r.Success.ShouldBe(true);
                        r.ParsedValue.Count.ShouldBe(i);

                        parser.ParseGenerally(AsteriscStream(i)).Success.ShouldBe(true);
                    }

                    for (var i = m + 1; i < m + 15; ++i)
                    {
                        parser.Parse(AsteriscStream(i)).Success.ShouldBe(false);
                        parser.ParseGenerally(AsteriscStream(i)).Success.ShouldBe(false);
                    }
                }
            }

            for (int n = 0; n < 15; ++n)
            {
                for (int m = n; m < n + 10; ++m)
                {
                    var parser = new QuantifiedParser <string>(AsteriscParser, QuantificationRule.NtoM, n, m, SeparatorParser);

                    for (var i = 0; i < n; ++i)
                    {
                        parser.Parse(AsteriscStream(i, true)).Success.ShouldBe(false);
                        parser.ParseGenerally(AsteriscStream(i, true)).Success.ShouldBe(false);
                    }

                    for (var i = n; i <= m; ++i)
                    {
                        var r = parser.Parse(AsteriscStream(i, true));

                        r.Success.ShouldBe(true);
                        r.ParsedValue.Count.ShouldBe(i);

                        parser.ParseGenerally(AsteriscStream(i, true)).Success.ShouldBe(true);
                    }

                    for (var i = m + 1; i < m + 15; ++i)
                    {
                        parser.Parse(AsteriscStream(i, true)).Success.ShouldBe(false);
                        parser.ParseGenerally(AsteriscStream(i, true)).Success.ShouldBe(false);
                    }
                }
            }
        }