public void FullPattern_Terminal(string grammarName, string patternName, string terminalName) { RGG rGG = new RGG(grammarName); rGG.BuildPattern(patternName).Terminal(terminalName).PatternEnd(); rGG.BuildGraph(1); RGGNode startPatternNode = rGG.GetPatternStart(patternName); Assert.Equal(1, startPatternNode.TransitionCount); // Pattern Start RGGTransition candidateTransition = startPatternNode.Transitions.First(); Assert.Equal(TransitionType.PatternStart, candidateTransition.TransitionType); RGGNode candidateNode = candidateTransition.To; Assert.True(candidateNode.Name.StartsWith(patternName)); Assert.Equal(1, candidateNode.TransitionCount); // Terminal candidateTransition = candidateNode.Transitions.First(); Assert.Equal(TransitionType.Terminal, candidateTransition.TransitionType); Assert.Equal(terminalName, candidateTransition.Terminal.ToString()); candidateNode = candidateTransition.To; Assert.True(candidateNode.Name.StartsWith(patternName)); Assert.Equal(1, candidateNode.TransitionCount); // Pattern End candidateTransition = candidateNode.Transitions.First(); Assert.Equal(TransitionType.PatternEnd, candidateTransition.TransitionType); candidateNode = candidateTransition.To; Assert.True(candidateNode.Name.StartsWith(patternName)); Assert.Equal(0, candidateNode.TransitionCount); }
public void FullPattern_RepeatPrevious_GroupStart_Terminal(string grammarName, string patternName, string terminalName) { RGG rGG = new RGG(grammarName); rGG.BuildPattern(patternName).GroupStart.Terminal(terminalName).GroupEnd.RepeatPrevious(0, 3).PatternEnd(); rGG.BuildGraph(1); RGGNode startPatternNode = rGG.GetPatternStart(patternName); Assert.Equal(1, startPatternNode.TransitionCount); // Pattern Start RGGTransition candidateTransition = startPatternNode.Transitions.First(); Assert.Equal(TransitionType.PatternStart, candidateTransition.TransitionType); RGGNode candidateNode = candidateTransition.To; Assert.True(candidateNode.Name.StartsWith(patternName)); Assert.Equal(1, candidateNode.TransitionCount); // GroupStart candidateTransition = candidateNode.Transitions.First(); Assert.Equal(TransitionType.GroupStart, candidateTransition.TransitionType); Assert.Equal(Constants.UnnamedGroupStart, candidateTransition.Internal); candidateNode = candidateTransition.To; Assert.True(candidateNode.Name.StartsWith(patternName)); Assert.Equal(1, candidateNode.TransitionCount); // Terminal candidateTransition = candidateNode.Transitions.First(); Assert.Equal(TransitionType.Terminal, candidateTransition.TransitionType); Assert.Equal(terminalName, candidateTransition.Terminal.ToString()); candidateNode = candidateTransition.To; Assert.True(candidateNode.Name.StartsWith(patternName)); Assert.Equal(1, candidateNode.TransitionCount); // GroupEnd candidateTransition = candidateNode.Transitions.First(); Assert.Equal(TransitionType.GroupEnd, candidateTransition.TransitionType); Assert.Equal(string.Format(Constants.EndPattern, Constants.UnnamedGroupStart), candidateTransition.Internal); candidateNode = candidateTransition.To; Assert.True(candidateNode.Name.StartsWith(patternName)); Assert.Equal(1, candidateNode.TransitionCount); // Pattern End candidateTransition = candidateNode.Transitions.First(); Assert.Equal(TransitionType.PatternEnd, candidateTransition.TransitionType); candidateNode = candidateTransition.To; Assert.True(candidateNode.Name.StartsWith(patternName)); Assert.Equal(0, candidateNode.TransitionCount); }
public void FullPattern_Or(string grammarName, string patternName, string terminalName1, string terminalName2) { RGG rGG = new RGG(grammarName); rGG.BuildPattern(patternName).Terminal(terminalName1).Or.Terminal(terminalName2).PatternEnd(); rGG.BuildGraph(1); RGGNode startPatternNode = rGG.GetPatternStart(patternName); Assert.Equal(2, startPatternNode.TransitionCount); int counter = 0; foreach (RGGTransition startTransition in startPatternNode.Transitions) { // Pattern Start RGGTransition candidateTransition = startTransition; Assert.Equal(TransitionType.PatternStart, candidateTransition.TransitionType); RGGNode candidateNode = candidateTransition.To; Assert.True(candidateNode.Name.StartsWith(patternName)); Assert.Equal(1, candidateNode.TransitionCount); // Terminal candidateTransition = candidateNode.Transitions.First(); Assert.Equal(TransitionType.Terminal, candidateTransition.TransitionType); Assert.Equal(counter == 0?terminalName1:terminalName2, candidateTransition.Terminal.ToString()); candidateNode = candidateTransition.To; Assert.True(candidateNode.Name.StartsWith(patternName)); Assert.Equal(1, candidateNode.TransitionCount); // Pattern End candidateTransition = candidateNode.Transitions.First(); Assert.Equal(TransitionType.PatternEnd, candidateTransition.TransitionType); candidateNode = candidateTransition.To; Assert.True(candidateNode.Name.StartsWith(patternName)); Assert.Equal(0, candidateNode.TransitionCount); counter += 1; } }
public void FullPattern_NamedGroupStart_Or2(string grammarName, string patternName, string groupName, string terminalName1, string terminalName2, string terminalName3, string terminalName4) { RGG rGG = new RGG(grammarName); rGG.BuildPattern(patternName).NamedGroupStart(groupName).Terminal(terminalName1).Terminal(terminalName2).Or.Terminal(terminalName3).Terminal(terminalName4).GroupEnd.PatternEnd(); rGG.BuildGraph(1); RGGNode startPatternNode = rGG.GetPatternStart(patternName); Assert.Equal(1, startPatternNode.TransitionCount); // Pattern Start RGGTransition candidateTransition = startPatternNode.Transitions.First(); Assert.Equal(TransitionType.PatternStart, candidateTransition.TransitionType); RGGNode candidateNode = candidateTransition.To; Assert.True(candidateNode.Name.StartsWith(patternName)); Assert.Equal(1, candidateNode.TransitionCount); // NamedGroupStart candidateTransition = candidateNode.Transitions.First(); Assert.Equal(TransitionType.GroupStart, candidateTransition.TransitionType); Assert.Equal(groupName, candidateTransition.Internal); candidateNode = candidateTransition.To; Assert.True(candidateNode.Name.StartsWith(patternName)); Assert.Equal(2, candidateNode.TransitionCount); int counter = 0; string nextName = string.Empty; foreach (RGGTransition groupStartTransition in candidateNode.Transitions) { // Terminal candidateTransition = groupStartTransition; Assert.Equal(TransitionType.Terminal, candidateTransition.TransitionType); Assert.Equal(counter == 0 ? terminalName1 : terminalName3, candidateTransition.Terminal.ToString()); candidateNode = candidateTransition.To; Assert.True(candidateNode.Name.StartsWith(patternName)); Assert.Equal(1, candidateNode.TransitionCount); // Terminal candidateTransition = candidateNode.Transitions.First();; Assert.Equal(TransitionType.Terminal, candidateTransition.TransitionType); Assert.Equal(counter == 0 ? terminalName2 : terminalName4, candidateTransition.Terminal.ToString()); candidateNode = candidateTransition.To; Assert.True(candidateNode.Name.StartsWith(patternName)); Assert.Equal(1, candidateNode.TransitionCount); if (nextName == string.Empty) { nextName = candidateNode.Name; } else { Assert.Equal(nextName, candidateNode.Name); } counter += 1; } // GroupEnd candidateTransition = candidateNode.Transitions.First(); Assert.Equal(TransitionType.GroupEnd, candidateTransition.TransitionType); Assert.Equal(string.Format(Constants.EndPattern, groupName), candidateTransition.Internal); candidateNode = candidateTransition.To; Assert.True(candidateNode.Name.StartsWith(patternName)); Assert.Equal(1, candidateNode.TransitionCount); // Pattern End candidateTransition = candidateNode.Transitions.First(); Assert.Equal(TransitionType.PatternEnd, candidateTransition.TransitionType); candidateNode = candidateTransition.To; Assert.True(candidateNode.Name.StartsWith(patternName)); Assert.Equal(0, candidateNode.TransitionCount); }