예제 #1
0
        public void t11_Parse_Class_With_Multiple_Fields()
        {
            var tokens = TokenStreamBuilder.Class("className",
                                                  TokenStreamBuilder.CombineTokenStreams(
                                                      TokenStreamBuilder.Field("fieldName", "fieldType"),
                                                      new ClassDiagramTokenStream {
                TokenType.Comma.Token()
            },                                                                                                 // TODO single-token streams.
                                                      TokenStreamBuilder.Field("fieldName2", "fieldType2")
                                                      )
                                                  );

            var classDiagram = new ClassDiagramParser(tokens).ParseClassDiagram();
            var c            = classDiagram.Classes.ToList()[0];

            Assert.IsNotNull(classDiagram, "failed to parse the class");
            Assert.AreEqual("className", c.Name, "name wrong");
            Assert.IsNotNull(c.Fields, "fields MUST NOT be null");
            var l = c.Fields.ToList();

            Assert.AreEqual(2, l.Count, "There should be exactly one field");
            var f = l[0];

            Assert.AreEqual("fieldName", f.Name, "field name wrong");
            Assert.AreEqual("fieldType", f.Type, "field type wrong");
            f = l[1];
            Assert.AreEqual("fieldName2", f.Name, "2nd field name wrong");
            Assert.AreEqual("fieldType2", f.Type, "2nd field type wrong");
        }
예제 #2
0
        public void t08_Parse_ClassDiagram_Containing_Two_Associated_Classes_With_Multiplicities_Numbers(string sourceFrom, string sourceTo, string targetFrom, string targetTo)
        {
            var tokens = new ClassDiagramTokenStream();

            tokens.AddRange(TokenStreamBuilder.Class("a"));

            tokens.AddRange(new[] { sourceFrom.Token() });
            if (sourceTo != null)
            {
                tokens.AddRange(new[] { "..".Token(), sourceTo.Token() });
            }

            tokens.AddRange(new[] { TokenType.Dash.Token() });

            tokens.AddRange(new[] { targetFrom.Token() });
            if (targetTo != null)
            {
                tokens.AddRange(new[] { "..".Token(), targetTo.Token() });
            }

            tokens.AddRange(TokenStreamBuilder.Class("b"));

            var parser = new ClassDiagramParser(tokens);
            var cd     = parser.ParseClassDiagram();
            var assoc  = t08_check(cd);

            checkMultiplicityKind(assoc.SourceMultiplicity.FromKind, sourceFrom, "source from");
            checkMultiplicityKind(assoc.SourceMultiplicity.ToKind, sourceTo, "source to");
            checkMultiplicityKind(assoc.TargetMultiplicity.FromKind, targetFrom, "target from");
            checkMultiplicityKind(assoc.TargetMultiplicity.ToKind, targetTo, "target to");

            Assert.AreEqual(sourceFrom, assoc.SourceMultiplicity.From, "source wrong value");
            Assert.AreEqual(targetFrom, assoc.TargetMultiplicity.From, "target wrong value");
        }
예제 #3
0
        public void t07_Parse_ClassDiagram_Containing_Two_Associated_Classes_Aggregation_Alternative()
        {
            var tokens = TokenStreamBuilder.CombineTokenStreams(
                TokenStreamBuilder.Class("a"),
                new ClassDiagramTokenStream {
                TokenType.AngleOpen.Token(), TokenType.AngleClose.Token(), TokenType.Dash.Token(), TokenType.AngleClose.Token(),
            },
                TokenStreamBuilder.Class("b")
                );

            t07_Parse_ClassDiagram_Containing_Two_Associated_Classes(tokens, AssociationKind.Aggregation);
        }
예제 #4
0
        public void t15_Parse_Three_Associated_Classes()
        {
            // [a]-[b]-[c]
            var tokens = TokenStreamBuilder.CombineTokenStreams(
                TokenStreamBuilder.Class("a"),
                TokenStreamBuilder.PureAssociation("-"),
                TokenStreamBuilder.Class("b"),
                TokenStreamBuilder.PureAssociation("-"),
                TokenStreamBuilder.Class("c")
                );

            var cd = new ClassDiagramParser(tokens).ParseClassDiagram();

            Assert.IsNotNull(cd, "class diagram1 parse error");
            Assert.AreEqual(3, cd.Classes.Count(), "wrong class count");
            Assert.AreEqual(2, cd.Associations.Count(), "wrong association count");
            // TODO more tests...
        }
예제 #5
0
        public void t11_Parse_Class_With_Field()
        {
            var tokens = TokenStreamBuilder.Class("className", TokenStreamBuilder.Field("fieldName", "fieldType"));

            var classDiagram = new ClassDiagramParser(tokens).ParseClassDiagram();
            var c            = classDiagram.Classes.ToList()[0];

            Assert.IsNotNull(classDiagram, "failed to parse the class");
            Assert.AreEqual("className", c.Name, "name wrong");
            Assert.IsNotNull(c.Fields, "fields MUST NOT be null");
            var l = c.Fields.ToList();

            Assert.AreEqual(1, l.Count, "There should be exactly one field");
            var f = l[0];

            Assert.AreEqual("fieldName", f.Name, "field name wrong");
            Assert.AreEqual("fieldType", f.Type, "field type wrong");
        }