Пример #1
0
        public Task Should_Render_Grid_Column_Alignment_Correctly()
        {
            // Given
            var console = new FakeConsole(width: 80);
            var grid    = new Grid();

            grid.AddColumn(new GridColumn {
                Alignment = Justify.Right
            });
            grid.AddColumn(new GridColumn {
                Alignment = Justify.Center
            });
            grid.AddColumn(new GridColumn {
                Alignment = Justify.Left
            });
            grid.AddRow("Foo", "Bar", "Baz");
            grid.AddRow("Qux", "Corgi", "Waldo");
            grid.AddRow("Grault", "Garply", "Fred");

            // When
            console.Render(grid);

            // Then
            return(Verifier.Verify(console.Output));
        }
Пример #2
0
        public void Should_Throw_If_Tree_Contains_Cycles()
        {
            // Given
            var console = new FakeConsole(width: 80);

            var child2 = new TreeNode(new Text("child 2"));
            var child3 = new TreeNode(new Text("child 3"));
            var child1 = new TreeNode(new Text("child 1"));

            child1.AddNodes(child2, child3);
            var root = new TreeNode(new Text("Branch Node"));

            root.AddNodes(child1);
            child2.AddNode(root);

            var tree = new Tree("root node");

            tree.AddNodes(root);

            // When
            var result = Record.Exception(() => console.Render(tree));

            // Then
            result.ShouldBeOfType <CircularTreeException>();
        }
Пример #3
0
        public Task Should_Render_Tree_With_Multiple_Roots_Correctly()
        {
            // Given
            var console        = new FakeConsole(width: 80);
            var nestedChildren =
                Enumerable.Range(0, 10)
                .Select(x => new TreeNode(new Text($"multiple \n line {x}")));
            var child2      = new TreeNode(new Text("child2"));
            var child2Child = new TreeNode(new Text("child2Child"));

            child2.AddNode(child2Child);
            child2Child.AddNode(new TreeNode(new Text("Child 2 child\n child")));
            var child3      = new TreeNode(new Text("child3"));
            var child3Child = new TreeNode(new Text("single leaf\n multiline"));

            child3Child.AddNode(new TreeNode(new Calendar(2020, 01)));
            child3.AddNode(child3Child);
            var children = new List <TreeNode> {
                new(new Text("child1"), nestedChildren), child2, child3
            };
            var root = new TreeNode(new Text("Root node"), children);
            var tree = new Tree().AddNode(root).AddNode(child2Child);

            // When
            console.Render(tree);

            // Then
            return(Verifier.Verify(console.Output));
        }
Пример #4
0
        public Task Should_Render_Tree_Correctly()
        {
            // Given
            var console = new FakeConsole(width: 80);

            var tree = new Tree(new Text("Root node")).Guide(TreeGuide.DoubleLine);

            var nestedChildren = Enumerable.Range(0, 10).Select(x => new Text($"multiple\nline {x}"));
            var child2         = new TreeNode(new Text("child2"));
            var child2Child    = new TreeNode(new Text("child2-1"));

            child2.AddNode(child2Child);
            child2Child.AddNode(new TreeNode(new Text("Child2-1-1\nchild")));
            var child3      = new TreeNode(new Text("child3"));
            var child3Child = new TreeNode(new Text("single leaf\nmultiline"));

            child3Child.AddNode(new TreeNode(new Calendar(2021, 01)));
            child3.AddNode(child3Child);

            tree.AddNode("child1").AddNodes(nestedChildren);
            tree.AddNode(child2);
            tree.AddNode(child3);
            tree.AddNode("child4");

            // When
            console.Render(tree);

            // Then
            return(Verifier.Verify(console.Output));
        }
Пример #5
0
        public Task Should_Render_Table_Nested_In_Panels_Correctly()
        {
            // A simple table
            var console = new FakeConsole(width: 80);
            var table   = new Table()
            {
                Border = TableBorder.Rounded
            };

            table.AddColumn("Foo");
            table.AddColumn("Bar");
            table.AddColumn(new TableColumn("Baz")
            {
                Alignment = Justify.Right
            });
            table.AddRow("Qux\nQuuuuuux", "[blue]Corgi[/]", "Waldo");
            table.AddRow("Grault", "Garply", "Fred");

            // Render a table in some panels.
            console.Render(new Panel(new Panel(table)
            {
                Border = BoxBorder.Ascii,
            }));

            // Then
            return(Verifier.Verify(console.Output));
        }
Пример #6
0
        public Task Should_Render_Table_With_Column_Justification_Correctly()
        {
            // Given
            var console = new FakeConsole(width: 80);
            var table   = new Table();

            table.AddColumn(new TableColumn("Foo")
            {
                Alignment = Justify.Left
            });
            table.AddColumn(new TableColumn("Bar")
            {
                Alignment = Justify.Right
            });
            table.AddColumn(new TableColumn("Baz")
            {
                Alignment = Justify.Center
            });
            table.AddRow("Qux", "Corgi", "Waldo");
            table.AddRow("Grault", "Garply", "Lorem ipsum dolor sit amet");

            // When
            console.Render(table);

            // Then
            return(Verifier.Verify(console.Output));
        }
Пример #7
0
        public Task Should_Render_Explicit_Grid_Column_Padding_Correctly()
        {
            // Given
            var console = new FakeConsole(width: 80);
            var grid    = new Grid();

            grid.AddColumn(new GridColumn {
                Padding = new Padding(3, 0, 0, 0)
            });
            grid.AddColumn(new GridColumn {
                Padding = new Padding(0, 0, 0, 0)
            });
            grid.AddColumn(new GridColumn {
                Padding = new Padding(0, 0, 3, 0)
            });
            grid.AddRow("Foo", "Bar", "Baz");
            grid.AddRow("Qux", "Corgi", "Waldo");
            grid.AddRow("Grault", "Garply", "Fred");

            // When
            console.Render(grid);

            // Then
            return(Verifier.Verify(console.Output));
        }
Пример #8
0
        public Task Should_Render_Columns_Correctly()
        {
            // Given
            var console = new FakeConsole(width: 61);
            var users   = new[]
            {
                new User {
                    Name = "Savannah Thompson", Country = "Australia"
                },
                new User {
                    Name = "Sophie Ramos", Country = "United States"
                },
                new User {
                    Name = "Katrin Goldberg", Country = "Germany"
                },
            };

            var cards = new List <Panel>();

            foreach (var user in users)
            {
                cards.Add(
                    new Panel($"[b]{user.Name}[/]\n[yellow]{user.Country}[/]")
                    .RoundedBorder().Expand());
            }

            // When
            console.Render(new Columns(cards));

            // Then
            return(Verifier.Verify(console.Output));
        }
Пример #9
0
        public string Render()
        {
            var console = new FakeConsole();
            var context = new RenderContext(Encoding.UTF8, false);

            console.Render(Column.Render(context, Task, TimeSpan.Zero));
            return(console.Output);
        }
Пример #10
0
        public Task Should_Render_With_Specified_Box()
        {
            // Given
            var console = new FakeConsole(width: 40);

            // When
            console.Render(new Rule("Hello World").DoubleBorder());

            // Then
            return(Verifier.Verify(console.Output));
        }
Пример #11
0
        public Task Should_Convert_Line_Breaks_In_Title_To_Spaces()
        {
            // Given
            var console = new FakeConsole(width: 40);

            // When
            console.Render(new Rule("Hello\nWorld\r\n!"));

            // Then
            return(Verifier.Verify(console.Output));
        }
Пример #12
0
        public Task Should_Render_Default_Rule_Without_Title()
        {
            // Given
            var console = new FakeConsole(width: 40);

            // When
            console.Render(new Rule());

            // Then
            return(Verifier.Verify(console.Output));
        }
Пример #13
0
        public Task Should_Truncate_Title()
        {
            // Given
            var console = new FakeConsole(width: 40);

            // When
            console.Render(new Rule("          Hello World    "));

            // Then
            return(Verifier.Verify(console.Output));
        }
Пример #14
0
        public Task Should_Render_Panel_With_Multiple_Lines()
        {
            // Given
            var console = new FakeConsole(width: 80);

            // When
            console.Render(new Panel(new Text("Hello World\nFoo Bar")));

            // Then
            return(Verifier.Verify(console.Output));
        }
Пример #15
0
        public Task Should_Render_Panel_Inside_Panel_Correctly()
        {
            // Given
            var console = new FakeConsole(width: 80);

            // When
            console.Render(new Panel(new Panel(new Text("Hello World"))));

            // Then
            return(Verifier.Verify(console.Output));
        }
Пример #16
0
        public Task Should_Render_Default_Rule_With_Title_Centered_By_Default()
        {
            // Given
            var console = new FakeConsole(width: 40);

            // When
            console.Render(new Rule("Hello World"));

            // Then
            return(Verifier.Verify(console.Output));
        }
Пример #17
0
        public Task Should_Render_Panel_With_Unicode_Correctly()
        {
            // Given
            var console = new FakeConsole(width: 80);

            // When
            console.Render(new Panel(new Text(" \n💩\n ")));

            // Then
            return(Verifier.Verify(console.Output));
        }
        public async Task Should_Render_Correctly()
        {
            // Given
            var console = new FakeConsole(width: 80);
            var chart   = Fixture.GetChart();

            // When
            console.Render(chart);

            // Then
            await Verifier.Verify(console.Output);
        }
Пример #19
0
        public void Should_Truncate_Too_Long_Title(int width, string input, string expected)
        {
            // Given
            var console = new FakeConsole(width);

            // When
            console.Render(new Rule(input));

            // Then
            console.Lines.Count.ShouldBe(1);
            console.Lines[0].ShouldBe(expected);
        }
Пример #20
0
        public void Should_Render_Unstyled_Text_As_Expected()
        {
            // Given
            var console = new FakeConsole(width: 80);
            var text    = new Text("Hello World");

            // When
            console.Render(text);

            // Then
            console.Output.ShouldBe("Hello World");
        }
Пример #21
0
        public void Should_Write_Line_Breaks(string input)
        {
            // Given
            var console = new FakeConsole(width: 5);
            var text    = new Text(input);

            // When
            console.Render(text);

            // Then
            console.Output.ShouldBe("Hello\n\nWorld\n\n");
        }
Пример #22
0
        public Task Should_Render_Tree_With_No_Child_Nodes_Correctly()
        {
            // Given
            var console = new FakeConsole(width: 80);
            var tree    = new Tree(new Text("Root node"));

            // When
            console.Render(tree);

            // Then
            return(Verifier.Verify(console.Output));
        }
Пример #23
0
            public Task Should_Render_As_Expected()
            {
                // Given
                var console = new FakeConsole();
                var table   = Fixture.GetTable().AsciiBorder();

                // When
                console.Render(table);

                // Then
                return(Verifier.Verify(console.Output));
            }
Пример #24
0
        public void Should_Render_Links_As_Expected(string input, string output)
        {
            // Given
            var console = new FakeConsole();
            var markup  = new Markup(input);

            // When
            console.Render(markup);

            // Then
            console.Output.ShouldBe(output);
        }
Пример #25
0
        public void Should_Escape_Markup_Blocks_As_Expected()
        {
            // Given
            var console = new FakeConsole();
            var markup  = new Markup("Hello [[ World ]] !");

            // When
            console.Render(markup);

            // Then
            console.Output.ShouldBe("Hello [ World ] !");
        }
Пример #26
0
        public async Task Should_Render_Wrapped_Text_Correctly()
        {
            // Given
            var console = new FakeConsole(width: 70);
            var text    = new FigletText(FigletFont.Default, "Spectre.Console");

            // When
            console.Render(text);

            // Then
            await Verifier.Verify(console.Output);
        }
Пример #27
0
            public Task Should_Render_Right_Aligned_Table_Columns_As_Expected()
            {
                // Given
                var console = new FakeConsole();
                var table   = Fixture.GetTable(header2: Justify.Right).MarkdownBorder();

                // When
                console.Render(table);

                // Then
                return(Verifier.Verify(console.Output));
            }
        public async Task Should_Render_Correctly_Without_Tag_Values()
        {
            // Given
            var console = new FakeConsole(width: 80);
            var chart   = Fixture.GetChart().Width(60).HideTagValues();

            // When
            console.Render(chart);

            // Then
            await Verifier.Verify(console.Output);
        }
        public async Task Should_Render_Correctly_With_Specific_Culture()
        {
            // Given
            var console = new FakeConsole(width: 80);
            var chart   = Fixture.GetChart().Width(60).Culture("sv-SE");

            // When
            console.Render(chart);

            // Then
            await Verifier.Verify(console.Output);
        }
Пример #30
0
            public Task Should_Render_As_Expected()
            {
                // Given
                var console = new FakeConsole();
                var panel   = Fixture.GetPanel().DoubleBorder();

                // When
                console.Render(panel);

                // Then
                return(Verifier.Verify(console.Output));
            }