Exemple #1
0
        public void TerminalRuleReturnsNothingWhenNotMatched()
        {
            var rule = new TerminalRule(0, 'a');

            var matches = rule.Matches("b", 0).ToList();

            Assert.AreEqual(0, matches.Count);
        }
Exemple #2
0
        public void TerminalRuleReturns1WhenMatched()
        {
            var rule = new TerminalRule(0, 'a');

            var matches = rule.Matches("a", 0).ToList();

            Assert.AreEqual(1, matches.Single());
        }
Exemple #3
0
        public void TerminalRuleRespectsOffset()
        {
            var rule = new TerminalRule(0, 'a');

            var matches = rule.Matches("bbbabbb", 3).ToList();

            Assert.AreEqual(1, matches.Count);
            Assert.AreEqual(1, matches.Single());
        }
Exemple #4
0
        public void SimpleRuleWorks()
        {
            var terminal = new TerminalRule(1, 'a');
            var rule     = CreateSimpleRule(0, terminal);

            var matches = rule.Matches("a", 0).ToList();

            Assert.AreEqual(1, matches.Count);
            Assert.AreEqual(1, matches.Single());
        }
Exemple #5
0
        public void CombinedRuleWorks()
        {
            var terminalA = new TerminalRule(1, 'a');
            var terminalB = new TerminalRule(2, 'b');
            var rule      = CreateCombinedRule(0, terminalA, terminalB);

            var matches = rule.Matches("ab", 0).ToList();

            Assert.AreEqual(1, matches.Count);
            Assert.AreEqual(2, matches.Single());
        }
Exemple #6
0
        public void SplittingRuleWorks(string toMatch)
        {
            var terminalA = new TerminalRule(2, 'a');
            var terminalB = new TerminalRule(1, 'b');
            var rule      = CreateSplittingRule(0, terminalA, terminalB);

            var matches = rule.Matches(toMatch, 0).ToList();

            Assert.AreEqual(1, matches.Count);
            Assert.AreEqual(1, matches.Single());
        }
Exemple #7
0
        public void CanChainSimpleRules()
        {
            var terminal = new TerminalRule(2, 'a');
            var rule1    = CreateSimpleRule(1, terminal);
            var rule2    = CreateSimpleRule(2, rule1);

            var matches = rule2.Matches("a", 0).ToList();

            Assert.AreEqual(1, matches.Count);
            Assert.AreEqual(1, matches.Single());
        }
Exemple #8
0
        public void CanHandleRecursingRule()
        {
            var terminalA = new TerminalRule(1, 'a');
            var rule      = new Rule(0);

            rule.Products    = new IRule[2][];
            rule.Products[0] = new IRule[] { terminalA };
            rule.Products[1] = new IRule[] { terminalA, rule };

            var matches = rule.Matches("aaaaaaaa", 0).ToList();

            Assert.AreEqual(8, matches.Count);
            Assert.That(matches.Where(m => m == 8).Any());
        }