Exemple #1
0
        public void ProductionGetHashCodeShouldProduceSameValueForSameRightHandSides()
        {
            var production1 = new Production(new NonTerminal("A"), new CharacterTerminal('a'), new NonTerminal("B"));
            var production2 = new Production(new NonTerminal("A"), new CharacterTerminal('a'), new NonTerminal("B"));

            Assert.AreEqual(production1.GetHashCode(), production2.GetHashCode());
        }
Exemple #2
0
 public void ProductionGetHashCodeShouldProduceSameValueForSameObject()
 {
     var production = new Production(new NonTerminal("Z"),
         new CharacterTerminal('a'),
         new NonTerminal("B"),
         new SetTerminal('a','z'));
     var hashCode = production.GetHashCode();
     Assert.AreEqual(hashCode, production.GetHashCode());
 }
Exemple #3
0
 public IGrammarBuilder Production(string name, Action<IRuleBuilder> rules)
 {
     if (rules == null)
         _productions.Add(new Production(name));
     else
     {
         var ruleBuilder = new RuleBuilder();
         rules(ruleBuilder);
         foreach (var rule in ruleBuilder.GetRules())
         {
             var production = new Production(name, rule.ToArray());
             _productions.Add(production);
         }
     }
     return this;
 }
Exemple #4
0
 public void Test_Production_That_A_B_ToString_Generates_Appropriate_String()
 {
     var production = new Production("A", new NonTerminal("B"));
     Assert.AreEqual("A -> B", production.ToString());
 }
Exemple #5
0
 private IGrammarLexerRule CreateGrammarLexerRule(IList<ITerminal> terminalNeighborList)
 {
     var startNonTerminal = new NonTerminal("S");
     var production = new Production(
         startNonTerminal,
         terminalNeighborList.ToArray());
     var grammar = new Grammar(startNonTerminal, new[] { production }, null, null);
     return new GrammarLexerRule(Guid.NewGuid().ToString(), grammar);
 }
Exemple #6
0
 public void ProductionToStringShouldGenerateCorrectlyFormattedString()
 {
     var production = new Production(new NonTerminal("A"), new NonTerminal("B"));
     Assert.AreEqual("A -> B", production.ToString());
 }
Exemple #7
0
 public void ProductionGetHashCodeShouldProduceSameValueForEmptyProductionWithSameLeftHandSide()
 {
     var production1 = new Production(new NonTerminal("A"));
     var production2 = new Production(new NonTerminal("A"));
     Assert.AreEqual(production1.GetHashCode(), production2.GetHashCode());
 }
Exemple #8
0
 public void ProductionGetHashCodeShouldNotProduceSameValueForDifferentLeftHandSides()
 {
     var production1 = new Production(new NonTerminal("A"));
     var production2 = new Production(new NonTerminal("B"));
     Assert.AreNotEqual(production1.GetHashCode(), production2.GetHashCode());
 }