示例#1
0
        public void CanSetStyleOnBody()
        {
            var doc = new Document();

            var style = new StyleEx();

            style.SetIndent("body", 5);

            style.GetIndent(doc).ShouldBe(5);
        }
示例#2
0
        public void CanSetStyleOnParagraph()
        {
            var doc = new Document();
            var para = doc.AddParagraph();

            var style = new StyleEx();

            style.SetIndent("p", 5);

            style.GetIndent(para).ShouldBe(5);
        }
示例#3
0
        public void CanIndentOneLine()
        {
            var doc = new Document();
            var para = doc.AddParagraph();
            para.AddBlock("Lorem");
            para.AddBlock("ipsum");

            para.Style.Indent = 4;

            // Set console width to 20 to force wrapping
            var lines = Render(doc, 20);

            lines[0].ShouldBe("    Lorem ipsum");
        }
示例#4
0
        public void Format(Document doc)
        {
            foreach (var item in doc.Children)
            {
                int indent = item.Style.Indent + item.Style.FirstLineIndent;

                foreach (var block in item.Children)
                {
                    if (string.IsNullOrEmpty(block.Text))
                    {
                        continue;
                    }

                    var words = block.Text.SplitText();

                    foreach (var word in words)
                    {
                        if (word == "\t")
                        {
                            var spaces = item.Style.Tabs.FirstOrDefault(x => x > _position) - _position - 1;
                            if (spaces > 0)
                            {
                                // TODO - what if the tab stop is greater than the width?
                                _console.Write(new string(' ', spaces));
                                _position += spaces;
                                _needSeparator = false;
                            }

                            continue;
                        }

                        if (_position + word.Length + (_needSeparator ? 1 : 0) > _console.Width)
                        {
                            NewLine();
                            indent = item.Style.Indent;
                            // TODO - indent; need to handle edge case of indent + first word > width
                        }
                        else if (_needSeparator)
                        {
                            Whitespace(1);
                        }

                        WriteText(word, indent);
                    }
                }

                NewLine();
            }
        }
示例#5
0
        public void CanIndentMultipleLines()
        {
            var doc = new Document();
            var para = doc.AddParagraph();
            para.AddBlock("Lorem ipsum dolor sit amet, consectetur adipiscing elit.");

            para.Style.Indent = 4;

            // Set console width to 20 to force wrapping
            var lines = Render(doc, 20);

            lines[0].ShouldBe("    Lorem ipsum");
            lines[1].ShouldBe("    dolor sit amet,");
            lines[2].ShouldBe("    consectetur");
                            // 12345678901234567890
        }
示例#6
0
        public void CanWrapSingleBlock()
        {
            var doc = new Document();
            doc.AddParagraph().AddBlock("Lorem ipsum dolor sit amet, consectetur adipiscing elit.");
            //                           12345678901234567890
            //                                             12345678901234567890
            //                                                       12345678901234567890
            //                                                                   12345678901234567890

            // Set console width to 20 to force wrapping
            var lines = Render(doc, 20);

            lines[0].ShouldBe("Lorem ipsum dolor");
            lines[1].ShouldBe("sit amet,");
            lines[2].ShouldBe("consectetur");
            lines[3].ShouldBe("adipiscing elit.");
        }
示例#7
0
        public void CanWrapMultipleBlocks()
        {
            var doc = new Document();
            var para = doc.AddParagraph();
            para.AddBlock("Lorem");
            para.AddBlock("ipsum dolor");
            para.AddBlock("sit amet, consectetur adipiscing elit.");
            para.AddBlock("adipiscing elit.");

            // Set console width to 20 to force wrapping
            var lines = Render(doc, 20);

            lines[0].ShouldBe("Lorem ipsum dolor");
            lines[1].ShouldBe("sit amet,");
            lines[2].ShouldBe("consectetur");
            lines[3].ShouldBe("adipiscing elit.");
        }
示例#8
0
        public void EmptyBlocksAreIgnored()
        {
            var doc = new Document();
            var para = doc.AddParagraph();
            para.AddBlock("Hello");
            para.AddBlock("");
            para.AddBlock("World!");

            var lines = Render(doc);

            lines.ShouldNotBeEmpty();
            lines[0].ShouldBe("Hello World!");
        }
示例#9
0
 // TODO - styles should inherit from their parent - test that
 private IList<string> Render(Document doc, int width = 80)
 {
     var console = new MockConsole(width);
     var formatter = new ConsoleFormatter(console);
     formatter.Format(doc);
     return console.Result;
 }
示例#10
0
        public void TabStopInMiddleWorks()
        {
            var doc = new Document();
            var para = doc.AddParagraph();
            para.AddBlock("Lorem\tipsum");

            para.Style.Tabs = new[] { 3, 15 };
            para.Style.Indent = 5;

            var lines = Render(doc);

            // TODO - indent seems inconsistent with tab stop; should indent of 5 be five spaces or start at position 5??

            lines[0].ShouldBe("     Lorem    ipsum");
            //                 12345678901234567890
        }
示例#11
0
        public void TabStopAtStartWorks()
        {
            var doc = new Document();
            var para = doc.AddParagraph();
            para.AddBlock("\tLorem ipsum");

            para.Style.Tabs = new[] { 3 };

            var lines = Render(doc);

            lines[0].ShouldBe("  Lorem ipsum");
            //                 123456789012345678
        }
示例#12
0
        public void OneBlock()
        {
            var doc = new Document();
            doc.AddParagraph().AddBlock("Hello");

            var lines = Render(doc);

            lines.ShouldNotBeEmpty();
            lines[0].ShouldBe("Hello");
        }
示例#13
0
        public void FirstLineCanHaveNegativeIndent()
        {
            var doc = new Document();
            var para = doc.AddParagraph();
            para.AddBlock("Lorem ipsum dolor sit amet, consectetur adipiscing elit.");

            para.Style.Indent = 5;
            para.Style.FirstLineIndent = -3;

            var lines = Render(doc, 20);

            lines[0].ShouldBe("  Lorem ipsum dolor");
            lines[1].ShouldBe("     sit amet,");
            lines[2].ShouldBe("     consectetur");
            //                 12345678901234567890
        }