Beispiel #1
0
        public void ElementLineShouldReplaceExisting()
        {
            Section section = new Section();

            section.AddElement("Foo = Bar");
            section.AddElement("Foo = Baz");
            Assert.Equal(1, section.ElementCount);
            Assert.Equal("Baz", (section["Foo"] as ScalarElement).Value);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Book   discoTitanic = new Book("Titanic");
            Author rPowel       = new Author("Radu Powell");

            discoTitanic.AddAuthor(rPowel);

            #region Part1
            //int indexOfChapter = discoTitanic.CreateChapter("Chapter One");
            //Chapter chptOne = discoTitanic.GetChapter(indexOfChapter);
            //int indexOfSubChapter = chptOne.CreateSubChapter("chpt 1 1");
            //SubChapter chptOneOne = chptOne.GetSubChapter(indexOfSubChapter);
            //int indexOfParagraph = chptOneOne.CreateParagraph("Paragraph");
            //Paragraph paragraph1 = chptOneOne.GetParagraph(indexOfParagraph);
            //int indexOfImage1 = chptOneOne.CreateImage("Image");
            //Image image1 = chptOneOne.GetImage(indexOfImage1);
            //int indexOfImage2 = chptOneOne.CreateImage("Image");
            //Image image2 = chptOneOne.GetImage(indexOfImage2);
            //int indexOfImage3 = chptOneOne.CreateImage("Image");
            //Image image3 = chptOneOne.GetImage(indexOfImage3);
            //int indexOfTable = chptOneOne.CreateTable("Table");
            //Table table1 = chptOneOne.GetTable(indexOfTable);

            //ConsoleLog(discoTitanic);
            #endregion

            #region Composition_Pattern
            Section chpt1    = new Section("Chapter 1");
            Section chpt11   = new Section("Chapter 1.1");
            Section chpt111  = new Section("Chapter 1.1.1");
            Section chpt1111 = new Section("Chapter 1.1.1.1");
            discoTitanic.AddContent(new Paragraph("Paragraph pentru carte"));
            discoTitanic.AddContent(chpt1);

            chpt1.AddElement(new Paragraph("Moto capitol"));
            chpt1.AddElement(chpt11);

            chpt11.AddElement(new Paragraph("Text from SubChapter 1.1"));
            chpt11.AddElement(chpt111);

            chpt111.AddElement(new Paragraph("Text from subchapter 1.1.1"));
            chpt111.AddElement(chpt1111);

            chpt1111.AddElement(new Image("Image from subchapter 1.1.1.1"));

            discoTitanic.Print();
            #endregion

            Console.Read();
        }
Beispiel #3
0
        public void EmptyElementLineShouldNotAddElement()
        {
            Section section = new Section();

            section.AddElement("");
            Assert.Equal(0, section.ElementCount);
        }
Beispiel #4
0
        public void NullElementLineShouldNotAddElement()
        {
            Section section = new Section();

            section.AddElement(null);
            Assert.Equal(0, section.ElementCount);
        }
Beispiel #5
0
        public void InvalidInputShouldBeEmpty()
        {
            Section section = new Section();

            section.AddElement("Foo");
            Assert.Equal(0, section.ElementCount);
        }
Beispiel #6
0
        public void NullInputShouldBeEmpty()
        {
            Section section = new Section();

            section.AddElement(null);
            Assert.Equal(0, section.ElementCount);
        }
Beispiel #7
0
        public void NullAssignmentShouldRemoveElement()
        {
            Section section = new Section();

            section.AddElement("Foo = Bar");
            section["Foo"] = null;
            Assert.Equal(0, section.ElementCount);
        }
Beispiel #8
0
        public void MultiAssignmentLineShouldAddOneElement()
        {
            Section section = new Section();

            section.AddElement("Foo = Bar = moo");
            Assert.Equal(1, section.ElementCount);
            Assert.Equal("Bar = moo", (section["Foo"] as ScalarElement).Value);
        }
Beispiel #9
0
        public void ElementLineShouldAddOneElement()
        {
            Section section = new Section();

            section.AddElement("Foo = Bar");
            Assert.Equal(1, section.ElementCount);
            Assert.NotNull(section["Foo"]);
            Assert.Equal("Bar", (section["Foo"] as ScalarElement).Value);
        }
Beispiel #10
0
        public void MultipleAssignmentsShouldResultInOneElement()
        {
            Section section = new Section();

            section.AddElement("Foo = Bar = moo");
            Assert.Equal(1, section.ElementCount);
            ScalarElement element = section["Foo"] as ScalarElement;

            Assert.NotNull(element);
            Assert.Equal("Foo", element.Name);
            Assert.Equal("Bar = moo", element.Value);
        }
Beispiel #11
0
        public void SingleAssignment()
        {
            Section section = new Section();

            section.AddElement("Foo = Bar");
            Assert.Equal(1, section.ElementCount);
            ScalarElement element = section["Foo"] as ScalarElement;

            Assert.NotNull(element);
            Assert.Equal("Foo", element.Name);
            Assert.Equal("Bar", element.Value);
        }
Beispiel #12
0
        //REVIEW: Might be better to pass a filename/stream
        public void Open(String source)
        {
            elements = new Section();

            //REVIEW: Need to check for colons and newlines in comments
            char[] split = new char[] { ';', '\n' };

            Stack <Section> sections = new Stack <Section>();

            String  sectionType = "";
            Section curSection  = elements;

            int i = 0;

            while (i < source.Length)
            {
                int j = source.IndexOfAny(split, i);
                if (j == -1)
                {
                    break;
                }

                String line = source.Substring(i, j - i).Trim();
                if (source[j] == ';')
                {
                    curSection.AddElement(line);
                }
                else if (line.Length > 0)
                {
                    char firstChar = line[0];
                    if (firstChar == '{')
                    {
                        sections.Push(curSection);
                        Section newSection = new Section();
                        curSection.AddSection(sectionType, newSection);
                        curSection = newSection;
                    }
                    else if (firstChar == '}')
                    {
                        curSection = sections.Pop();
                    }
                    else
                    {
                        sectionType = line;
                    }
                }

                i = j + 1;
            }
        }