public void ParseNextConcept_SameKeyWordDifferentContext_Enclosed() { string dsl = "concept name data { concept ref; }"; var syntax = DslSyntaxHelper.CreateDslSyntax(typeof(SimpleConceptInfo), typeof(EnclosedRefConceptInfo)); var conceptParsersList = new List <IConceptParser>() { new GenericParserHelper <SimpleConceptInfo>(syntax, "concept"), new GenericParserHelper <EnclosedRefConceptInfo>(syntax, "concept") }; var conceptParsers = new MultiDictionary <string, IConceptParser>(); conceptParsers.Add("concept", conceptParsersList); var context = new Stack <IConceptInfo>(); TokenReader tokenReader = TestTokenReader(dsl); IConceptInfo concept = new TestDslParser(dsl, syntax).ParseNextConcept(tokenReader, context, conceptParsers); Assert.AreEqual(typeof(SimpleConceptInfo), concept.GetType()); Assert.AreEqual("name", (concept as SimpleConceptInfo).Name); Assert.AreEqual("data", (concept as SimpleConceptInfo).Data); Assert.IsTrue(tokenReader.TryRead("{"), "Reading '{' between concepts."); context.Push(concept); concept = new TestDslParser(dsl, syntax).ParseNextConcept(tokenReader, context, conceptParsers); Assert.AreEqual(typeof(EnclosedRefConceptInfo), concept.GetType()); Assert.AreEqual("ref", (concept as EnclosedRefConceptInfo).Name); Assert.AreEqual("name", (concept as EnclosedRefConceptInfo).Reference.Name); Assert.AreEqual("data", (concept as EnclosedRefConceptInfo).Reference.Data); }
public void ParseNextConcept_SameKeyWordDifferentContext() { string dsl = "concept simple simpledata; concept ext extdata extdata2;"; var syntax = DslSyntaxHelper.CreateDslSyntax(typeof(SimpleConceptInfo), typeof(ExtendedConceptInfo)); var conceptParsersList = new List <IConceptParser>() { new GenericParserHelper <SimpleConceptInfo>(syntax, "concept"), new GenericParserHelper <ExtendedConceptInfo>(syntax, "concept") }; var conceptParsers = new MultiDictionary <string, IConceptParser>(); conceptParsers.Add("concept", conceptParsersList); var noContext = new Stack <IConceptInfo>(); TokenReader tokenReader = TestTokenReader(dsl); IConceptInfo concept = new TestDslParser(dsl, syntax).ParseNextConcept(tokenReader, noContext, conceptParsers); Assert.AreEqual(typeof(SimpleConceptInfo), concept.GetType()); Assert.AreEqual("simple", (concept as SimpleConceptInfo).Name); Assert.AreEqual("simpledata", (concept as SimpleConceptInfo).Data); Assert.IsTrue(tokenReader.TryRead(";"), "Reading ';' between concepts."); concept = new TestDslParser(dsl, syntax).ParseNextConcept(tokenReader, noContext, conceptParsers); Assert.AreEqual(typeof(ExtendedConceptInfo), concept.GetType()); Assert.AreEqual("ext", (concept as ExtendedConceptInfo).Name); Assert.AreEqual("extdata", (concept as ExtendedConceptInfo).Data); Assert.AreEqual("extdata2", (concept as ExtendedConceptInfo).Data2); Assert.IsTrue(tokenReader.TryRead(";"), "Reading ';' after the concept."); }
public void ParseNextConcept_SameKeyWordDifferentContext_Enclosed() { string dsl = "concept name data { concept ref; }"; var conceptParsers = new List<IConceptParser>() { new GenericParserHelper<SimpleConceptInfo>("concept"), new GenericParserHelper<EnclosedRefConceptInfo>("concept") }; var context = new Stack<IConceptInfo>(); TokenReader tokenReader = TestTokenReader(dsl); IConceptInfo concept = new TestDslParser(dsl).ParseNextConcept(tokenReader, context, conceptParsers); Assert.AreEqual(typeof(SimpleConceptInfo), concept.GetType()); Assert.AreEqual("name", (concept as SimpleConceptInfo).Name); Assert.AreEqual("data", (concept as SimpleConceptInfo).Data); tokenReader.Read("{", "Reading '{' between concepts."); context.Push(concept); concept = new TestDslParser(dsl).ParseNextConcept(tokenReader, context, conceptParsers); Assert.AreEqual(typeof(EnclosedRefConceptInfo), concept.GetType()); Assert.AreEqual("ref", (concept as EnclosedRefConceptInfo).Name); Assert.AreEqual("name", (concept as EnclosedRefConceptInfo).Reference.Name); Assert.AreEqual("data", (concept as EnclosedRefConceptInfo).Reference.Data); }
public void ParseNextConcept_SameKeyWordDifferentContext() { string dsl = "concept simple simpledata; concept ext extdata extdata2;"; var conceptParsers = new List<IConceptParser>() { new GenericParserHelper<SimpleConceptInfo>("concept"), new GenericParserHelper<ExtendedConceptInfo>("concept") }; var noContext = new Stack<IConceptInfo>(); TokenReader tokenReader = TestTokenReader(dsl); IConceptInfo concept = new TestDslParser(dsl).ParseNextConcept(tokenReader, noContext, conceptParsers); Assert.AreEqual(typeof(SimpleConceptInfo), concept.GetType()); Assert.AreEqual("simple", (concept as SimpleConceptInfo).Name); Assert.AreEqual("simpledata", (concept as SimpleConceptInfo).Data); tokenReader.Read(";", "Reading ';' between concepts."); concept = new TestDslParser(dsl).ParseNextConcept(tokenReader, noContext, conceptParsers); Assert.AreEqual(typeof(ExtendedConceptInfo), concept.GetType()); Assert.AreEqual("ext", (concept as ExtendedConceptInfo).Name); Assert.AreEqual("extdata", (concept as ExtendedConceptInfo).Data); Assert.AreEqual("extdata2", (concept as ExtendedConceptInfo).Data2); tokenReader.Read(";", "Reading ';' after the concept."); }