示例#1
0
        public void ComplexNested2Test()
        {
            var    parser = new GenericParserHelper <ComplexNested2>("ComplexNested2");
            string expectedParsedConcept = "ComplexNested2 Module1.Entity1.Module2.Entity2.Description";

            // In root:
            Assert.AreEqual(expectedParsedConcept, parser.QuickParse(
                                dsl: "ComplexNested2 Module1.Entity1 Module2.Entity2 Description",
                                contextParent: null)
                            .GetUserDescription());

            // Nested in entity:
            Assert.AreEqual(expectedParsedConcept, parser.QuickParse(
                                dsl: "ComplexNested2 Module1.Entity1 Description",
                                contextParent: new LikeEntity {
                Module = new LikeModule {
                    Name = "Module2"
                }, Name = "Entity2"
            })
                            .GetUserDescription());

            // Nested in module:
            Assert.AreEqual(expectedParsedConcept, parser.QuickParse(
                                dsl: "ComplexNested2 Module1.Entity1 Entity2 Description",
                                contextParent: new LikeModule {
                Name = "Module2"
            })
                            .GetUserDescription());
        }
示例#2
0
        public void RootCannotBeNested()
        {
            var parser = new GenericParserHelper <LikeModule>("Module");

            Assert.AreEqual("LikeModule Module1", parser.QuickParse("Module Module1").GetUserDescription());

            TestUtility.ShouldFail <InvalidOperationException>(
                () => parser.QuickParse("Module Module1", new LikeModule {
                Name = "Module0"
            }),
                "cannot be nested");
        }
示例#3
0
        public void ParseNotEnoughParameters()
        {
            var simpleParser = new GenericParserHelper <SimpleConceptInfo>("module");

            TestUtility.ShouldFail(() => simpleParser.QuickParse("module"),
                                   "Name", "SimpleConceptInfo", "past the end");
        }
示例#4
0
        public void ParseKeywordCaseInsensitive()
        {
            var simpleParser     = new GenericParserHelper <SimpleConceptInfo>("simple");
            SimpleConceptInfo ci = simpleParser.QuickParse("SIMple abc");

            Assert.AreEqual("abc", ci.Name);
        }
示例#5
0
        public void ParseTest()
        {
            var simpleParser     = new GenericParserHelper <SimpleConceptInfo>("module");
            SimpleConceptInfo ci = simpleParser.QuickParse("module Wholesale");

            Assert.AreEqual("Wholesale", ci.Name);
        }
示例#6
0
        public void ParseComplex()
        {
            var complexParser     = new GenericParserHelper <ComplexConceptInfo>("complex");
            ComplexConceptInfo ci = complexParser.QuickParse("complex a b");

            Assert.AreEqual("a", ci.Name);
            Assert.AreEqual("b", ci.SimpleConceptInfo.Name);
        }
示例#7
0
        public void ParseEnclosedPartiallyInline()
        {
            var enclosedParser = new GenericParserHelper <EnclosedConceptInfoLevel2>("enclosedlevel2");
            var root           = new SimpleConceptInfo {
                Name = "a"
            };
            EnclosedConceptInfoLevel2 ci = enclosedParser.QuickParse("enclosedlevel2 b c", root);

            Assert.AreEqual("a", ci.Parent.Parent.Name);
            Assert.AreEqual("b", ci.Parent.Name);
            Assert.AreEqual("c", ci.Name);

            ci = enclosedParser.QuickParse("enclosedlevel2 a.b c");
            Assert.AreEqual("a", ci.Parent.Parent.Name);
            Assert.AreEqual("b", ci.Parent.Name);
            Assert.AreEqual("c", ci.Name);
        }
示例#8
0
        public void KeyReferenceReferenceSeparator()
        {
            var    parser = new GenericParserHelper <KeyReferenceReference>("KeyReferenceReference");
            string expectedParsedConcept = "KeyReferenceReference Module1.Entity1.Module2.Entity2";
            string dsl = "KeyReferenceReference Module1.Entity1 Module2.Entity2";

            Assert.AreEqual(expectedParsedConcept, parser.QuickParse(dsl).GetUserDescription());
        }
示例#9
0
        public void ParseEnclosedInline()
        {
            var enclosedParser     = new GenericParserHelper <EnclosedConceptInfo>("enclosed");
            EnclosedConceptInfo ci = enclosedParser.QuickParse("enclosed a.b");

            Assert.AreEqual("a", ci.Parent.Name);
            Assert.AreEqual("b", ci.Name);
        }
示例#10
0
        public void ParseDerived()
        {
            var derivedParser     = new GenericParserHelper <DerivedConceptInfo>("derived");
            DerivedConceptInfo ci = derivedParser.QuickParse("derived abc def 123");

            Assert.AreEqual("abc", ci.Name);
            Assert.AreEqual("def", ci.Name2);
            Assert.AreEqual("123", ci.Name3);
        }
示例#11
0
        public void KeyReferenceStringSeparator()
        {
            // Currently KeyReferenceString expects '.' separator in DSL script, while KeyReferenceReference does not.
            // More consistent behavior would be to use dot only for referenced concept keys, and not here before string property.
            var    parser = new GenericParserHelper <KeyReferenceString>("KeyReferenceString");
            string expectedParsedConcept = "KeyReferenceString Module1.Entity1.Name";
            string dsl = "KeyReferenceString Module1.Entity1 Name";

            Assert.AreEqual(expectedParsedConcept, parser.QuickParse(dsl).GetUserDescription());
        }
示例#12
0
        public void ParseReferenceToDerivedWithKey()
        {
            string dsl    = "reference wholesale.product";
            var    parser = new GenericParserHelper <ReferenceToDerivedWithKey>("reference");
            ReferenceToDerivedWithKey ci = parser.QuickParse(dsl);

            Assert.AreEqual("wholesale", ci.Parent.Parent.Name);
            Assert.AreEqual("product", ci.Parent.Name);
            Assert.AreEqual(default(string), ci.Parent.Comment);
        }
示例#13
0
        public void ParseEnclosedInlineError()
        {
            var enclosedParser = new GenericParserHelper <EnclosedConceptInfoLevel2>("enclosedlevel2");
            var root           = new SimpleConceptInfo {
                Name = "a"
            };

            TestUtility.ShouldFail <InvalidOperationException>(
                () => enclosedParser.QuickParse("enclosedlevel2 a b c"),
                "\".\"");
        }
示例#14
0
        public void ParseNotEnoughParametersInSingleConceptDescription()
        {
            var simpleParser = new GenericParserHelper <SimpleConceptInfo>("module");

            TestUtility.ShouldFail <InvalidOperationException>(
                () => simpleParser.QuickParse("module { entiti e }"),
                "SimpleConceptInfo",
                "Special",
                "{",
                "quotes");
        }
示例#15
0
        public void ParseEnclosedSinglePropertyConcept()
        {
            var parent = new SimpleConceptInfo {
                Name = "parent"
            };
            var enclosed1 = new EnclosedSingleProperty1 {
                Parent = parent
            };
            var enclosed2 = new EnclosedSingleProperty2 {
                Parent = enclosed1
            };

            {
                // simple parent { enclosed1; }
                var context = new Stack <IConceptInfo>(new[] { parent });
                var parser  = new GenericParserHelper <EnclosedSingleProperty1>("enclosed1");
                var ci      = parser.QuickParse("enclosed1", context);
                Assert.AreEqual("parent", ci.Parent.Name);
            }

            {
                // simple parent; enclosed1 parent;
                var context = new Stack <IConceptInfo>();
                var parser  = new GenericParserHelper <EnclosedSingleProperty1>("enclosed1");
                var ci      = parser.QuickParse("enclosed1 parent", context);
                Assert.AreEqual("parent", ci.Parent.Name);
            }

            {
                // simple parent { enclosed1 { enclosed2; } }
                var context = new Stack <IConceptInfo>(new IConceptInfo[] { parent, enclosed1 });
                var parser  = new GenericParserHelper <EnclosedSingleProperty2>("enclosed2");
                var ci      = parser.QuickParse("enclosed2", context);
                Assert.AreEqual("parent", ci.Parent.Parent.Name);
            }

            {
                // simple parent { enclosed1; enclosed2; }
                var context = new Stack <IConceptInfo>(new[] { parent });
                var parser  = new GenericParserHelper <EnclosedSingleProperty2>("enclosed2");
                TestUtility.ShouldFail(() => parser.QuickParse("enclosed2", context),
                                       "EnclosedSingleProperty2 must be enclosed within the referenced parent concept EnclosedSingleProperty1");
            }

            {
                // simple parent { enclosed1; } enclosed2 parent;
                var context = new Stack <IConceptInfo>();
                var parser  = new GenericParserHelper <EnclosedSingleProperty2>("enclosed2");
                TestUtility.ShouldFail(() => parser.QuickParse("enclosed2 parent", context),
                                       "EnclosedSingleProperty2 must be enclosed within the referenced parent concept EnclosedSingleProperty1");
            }
        }
示例#16
0
        public void ParseMultipleReferenceWithKey()
        {
            string dsl    = "reference wholesale.product maticni.mjestotroska";
            var    parser = new GenericParserHelper <MultipleReferenceWithKey>("reference");
            MultipleReferenceWithKey ci = parser.QuickParse(dsl);

            Assert.AreEqual("wholesale", ci.Parent.Parent.Name);
            Assert.AreEqual("product", ci.Parent.Name);
            Assert.AreEqual(default(string), ci.Parent.Comment);
            Assert.AreEqual("maticni", ci.Reference.Parent.Name);
            Assert.AreEqual("mjestotroska", ci.Reference.Name);
            Assert.AreEqual(default(string), ci.Reference.Comment);
        }
示例#17
0
        public void ParseEnclosedInWrongConcept()
        {
            var parser = new GenericParserHelper <EnclosedConceptInfo>("enclosed");

            TestUtility.ShouldFail <InvalidOperationException>(
                () => parser.QuickParse(
                    "enclosed myparent.myname",
                    new ComplexConceptInfo {
                Name = "c", SimpleConceptInfo = new SimpleConceptInfo {
                    Name = "s"
                }
            }),
                "EnclosedConceptInfo",
                "ComplexConceptInfo");
        }
示例#18
0
 public void ParseNotEnoughParametersInSingleConceptDescription()
 {
     try
     {
         var simpleParser     = new GenericParserHelper <SimpleConceptInfo>("module");
         SimpleConceptInfo ci = simpleParser.QuickParse("module { entiti e }");
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         Assert.IsTrue(ex.Message.Contains("SimpleConceptInfo"), "Concept type.");
         Assert.IsTrue(ex.Message.Contains("Special"), "Unexpected special token while reading text.");
         Assert.IsTrue(ex.Message.Contains("{"), "Unexpected special token '{' while reading text.");
         Assert.IsTrue(ex.Message.Contains("quotes"), "Use quotes to specify text (e.g. '{')");
         throw;
     }
 }
示例#19
0
        public void ParseEnclosedReference()
        {
            // simple parent1 { enclosed other_enclosed; } simple parent2 { reference (parent1.other_enclosed); }

            var context = new Stack <IConceptInfo>();

            context.Push(new SimpleConceptInfo {
                Name = "parent2"
            });
            var referenceParser = new GenericParserHelper <EnclosedReference>("reference");

            var ci = referenceParser.QuickParse("reference parent1.other_enclosed", context);

            Assert.AreEqual("parent2", ci.Parent.Name);
            Assert.AreEqual("parent1", ci.Reference.Parent.Name);
            Assert.AreEqual("other_enclosed", ci.Reference.Name);
        }
示例#20
0
        public void ParseEnclosedInlineError()
        {
            var dsl    = "enclosed abc def";
            var parser = new GenericParserHelper <EnclosedConceptInfo>("enclosed");

            try
            {
                EnclosedConceptInfo ci = parser.QuickParse(dsl);
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.Message.Contains("\".\""), "Expecting \".\"");
                var msg = parser.tokenReader.ReportPosition();
                Assert.IsTrue(msg.Contains("def"), "Report the unexpected text.");
                throw;
            }
        }
示例#21
0
        public void ParseEnclosedInWrongConcept()
        {
            var parser = new GenericParserHelper <EnclosedConceptInfo>("enclosed");

            try
            {
                EnclosedConceptInfo ci = parser.QuickParse(
                    "enclosed myparent.myname",
                    new ComplexConceptInfo {
                    Name = "c", SimpleConceptInfo = new SimpleConceptInfo {
                        Name = "s"
                    }
                });
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.Message.Contains("EnclosedConceptInfo"), "EnclosedConceptInfo");
                Assert.IsTrue(e.Message.Contains("ComplexConceptInfo"), "ComplexConceptInfo");
                throw;
            }
        }