public void ShouldBuildAutomatonTableFromTwoSequencesUsingAnyTerminal() { AutomatonTableFactory <char> factory; IAutomatonTable <char> automatonTable; LexicalRule rule1, rule2; AutomatonTableParser parser; factory = new AutomatonTableFactory <char>(); rule1 = RuleHelper.BuildRule("A*=a.c;"); rule2 = RuleHelper.BuildRule("B*=abc;"); automatonTable = factory.BuildAutomatonTable(SituationCollectionFactoryHelper.BuildSituationCollectionFactory(new LexicalRule[] { rule1, rule2 }), new DistinctInputFactory(new RangeValueProvider())); Assert.IsNotNull(automatonTable); parser = new AutomatonTableParser(automatonTable); Assert.AreEqual(1, parser.ActionCount); Assert.IsTrue(parser.Parse(new TerminalInput('a'))); Assert.AreEqual(3, parser.ActionCount); Assert.IsTrue(parser.Parse(new TerminalInput('b'))); Assert.AreEqual(1, parser.ActionCount); Assert.IsTrue(parser.Parse(new TerminalInput('c'))); parser.Reset(); Assert.AreEqual(1, parser.ActionCount); Assert.IsTrue(parser.Parse(new TerminalInput('a'))); Assert.AreEqual(3, parser.ActionCount); Assert.IsTrue(parser.Parse(new TerminalInput('c'))); Assert.AreEqual(1, parser.ActionCount); Assert.IsTrue(parser.Parse(new TerminalInput('c'))); }
public void ShouldDeserializeFromResource() { List <IRule <char> > rules; IRule <char>[] results; RuleCollectionSerializer serializer; rules = new List <IRule <char> >(); rules.Add(RuleHelper.BuildRule("A*=a*{B}+c?.;")); rules.Add(RuleHelper.BuildRule("B={B}|c*|d+|e|f;")); serializer = new RuleCollectionSerializer(); //serializer.SaveToStream(new FileStream(@"d:\test.xml", FileMode.Create), rules); var assembly = Assembly.GetExecutingAssembly(); var resourceName = "FSMLib.LexicalAnalysis.UnitTest.Resources.test.xml"; using (Stream stream = assembly.GetManifestResourceStream(resourceName)) { results = serializer.LoadStream(stream).ToArray(); } Assert.AreEqual(2, results.Length); Assert.IsTrue(rules.IsIndenticalToEx(results)); }
public void ShouldSerializeAndDeserializeComplexRules() { List <IRule <char> > rules; IRule <char>[] results; RuleCollectionSerializer serializer; MemoryStream stream; rules = new List <IRule <char> >(); rules.Add(RuleHelper.BuildRule("A*=a*{B}+c?.;")); rules.Add(RuleHelper.BuildRule("B={B}|c*|d+|e|f;")); stream = new MemoryStream(); serializer = new RuleCollectionSerializer(); //serializer.SaveToStream(new FileStream(@"d:\test.xml", FileMode.Create), rules); serializer.SaveToStream(stream, rules); stream.Position = 0; results = serializer.LoadStream(stream).ToArray(); Assert.AreEqual(2, results.Length); Assert.IsTrue(rules.IsIndenticalToEx(results)); }
public void ShouldSerializeAndDeserializeRuleAttributes() { LexicalRule r1, r2; List <IRule <char> > rules; IRule <char>[] results; RuleCollectionSerializer serializer; MemoryStream stream; r1 = RuleHelper.BuildRule("A*=a;"); r1.Attributes.Add(new IgnoreNodeAttribute()); r2 = RuleHelper.BuildRule("B=b;"); r2.Attributes.Add(new DeserializerAttribute() { Value = typeof(LexicalRule) }); rules = new List <IRule <char> >(); rules.Add(r1); rules.Add(r2); stream = new MemoryStream(); serializer = new RuleCollectionSerializer(); serializer.SaveToStream(stream, rules); //serializer.SaveToStream(new FileStream(@"d:\test.xml", FileMode.Create), rules); stream.Position = 0; results = serializer.LoadStream(stream).ToArray(); Assert.AreEqual(2, results.Length); Assert.IsTrue(rules.IsIndenticalToEx(results)); Assert.IsTrue(results[0].Attributes.First() is IgnoreNodeAttribute); Assert.IsTrue(results[1].Attributes.First() is DeserializerAttribute); }
public void ShouldBeEquals() { SyntaxicRule rule1; SyntaxicRule rule2; rule1 = RuleHelper.BuildRule("A*=<C,a>;"); rule2 = RuleHelper.BuildRule("A*=<C,a>;"); Assert.IsTrue(rule1.Equals(rule2)); }
public void ShouldBeEquals() { LexicalRule rule1; LexicalRule rule2; rule1 = RuleHelper.BuildRule("A*=a;"); rule2 = RuleHelper.BuildRule("A*=a;"); Assert.IsTrue(rule1.Equals(rule2)); }
public void ShouldNotBeEquals() { SyntaxicRule rule1; SyntaxicRule rule2; SyntaxicRule rule3; SyntaxicRule rule4; rule1 = RuleHelper.BuildRule("A*=<C,a>;"); rule2 = RuleHelper.BuildRule("A*=<C,b>;"); rule3 = RuleHelper.BuildRule("A=<C,a>;"); rule4 = RuleHelper.BuildRule("B*=<C,a>;"); Assert.IsFalse(rule1.Equals(null)); Assert.IsFalse(rule1.Equals(rule2)); Assert.IsFalse(rule1.Equals(rule3)); Assert.IsFalse(rule1.Equals(rule4)); }
public void ShouldNotBeEquals() { LexicalRule rule1; LexicalRule rule2; LexicalRule rule3; LexicalRule rule4; rule1 = RuleHelper.BuildRule("A*=a;"); rule2 = RuleHelper.BuildRule("A*=b;"); rule3 = RuleHelper.BuildRule("A=a;"); rule4 = RuleHelper.BuildRule("B*=a;"); Assert.IsFalse(rule1.Equals(null)); Assert.IsFalse(rule1.Equals(rule2)); Assert.IsFalse(rule1.Equals(rule3)); Assert.IsFalse(rule1.Equals(rule4)); }
public void ShouldBuildAutomatonTableFromBasicSequence() { AutomatonTableFactory <char> factory; IAutomatonTable <char> automatonTable; LexicalRule rule; AutomatonTableParser parser; factory = new AutomatonTableFactory <char>( ); rule = RuleHelper.BuildRule("A*=abc;"); automatonTable = factory.BuildAutomatonTable(SituationCollectionFactoryHelper.BuildSituationCollectionFactory(rule.AsEnumerable()), new DistinctInputFactory(new RangeValueProvider())); Assert.IsNotNull(automatonTable); parser = new AutomatonTableParser(automatonTable); Assert.AreEqual(1, parser.ActionCount); Assert.IsTrue(parser.Parse(new TerminalInput('a'))); Assert.AreEqual(1, parser.ActionCount); Assert.IsTrue(parser.Parse(new TerminalInput('b'))); Assert.AreEqual(1, parser.ActionCount); Assert.IsTrue(parser.Parse(new TerminalInput('c'))); }
public void ShouldSerializeAndDeserializeSequenceRules() { List <IRule <char> > rules; IRule <char>[] results; RuleCollectionSerializer serializer; MemoryStream stream; rules = new List <IRule <char> >(); rules.Add(RuleHelper.BuildRule("A*=abc;")); rules.Add(RuleHelper.BuildRule("B=bcdef;")); stream = new MemoryStream(); serializer = new RuleCollectionSerializer(); serializer.SaveToStream(stream, rules); stream.Position = 0; results = serializer.LoadStream(stream).ToArray(); Assert.AreEqual(2, results.Length); Assert.IsTrue(rules.IsIndenticalToEx(results)); }