public void Should_Throw_If_Closing_Tag_Is_Not_Properly_Escaped(string input) { // Given var console = new PlainConsole(); // When var result = Record.Exception(() => new Markup(input)); // Then result.ShouldNotBeNull(); result.ShouldBeOfType <InvalidOperationException>(); result.Message.ShouldBe("Encountered unescaped ']' token at position 16"); }
public void Should_Render_Panel_2() { // Given var console = new PlainConsole(width: 80); // When console.Render(new Markup("[b]Hello World[/]\n[yellow]Hello World[/]")); // Then console.Lines.Count.ShouldBe(2); console.Lines[0].ShouldBe("Hello World"); console.Lines[1].ShouldBe("Hello World"); }
public async Task Should_Render_Right_Aligned_Text_Correctly() { // Given var console = new PlainConsole(width: 120); var text = new FigletText(FigletFont.Default, "Spectre.Console") .Alignment(Justify.Right); // When console.Render(text); // Then await Verifier.Verify(console.Output); }
public async Task Should_Load_Font_From_Stream() { // Given var console = new PlainConsole(width: 180); var font = FigletFont.Load(ResourceReader.LoadResourceStream("Spectre.Console.Tests/Data/starwars.flf")); var text = new FigletText(font, "Patrik was here"); // When console.Render(text); // Then await Verifier.Verify(console.Output); }
public void Should_Not_Draw_Tables_That_Are_Impossible_To_Draw() { // Given var console = new PlainConsole(width: 25); var first = new Table().Border(TableBorder.Rounded).BorderColor(Color.Red); first.AddColumn(new TableColumn("[u]PS1[/]").Centered()); first.AddColumn(new TableColumn("[u]PS2[/]")); first.AddColumn(new TableColumn("[u]PS3[/]")); first.AddRow("Hello", "[red]World[/]", string.Empty); first.AddRow("[blue]Bonjour[/]", "[white]le[/]", "[red]monde![/]"); first.AddRow("[blue]Hej[/]", "[yellow]Världen[/]", string.Empty); var second = new Table().Border(TableBorder.Square).BorderColor(Color.Green); second.AddColumn(new TableColumn("[u]Foo[/]")); second.AddColumn(new TableColumn("[u]Bar[/]")); second.AddColumn(new TableColumn("[u]Baz[/]")); second.AddRow("Hello", "[red]World[/]", string.Empty); second.AddRow(first, new Text("Whaaat"), new Text("Lolz")); second.AddRow("[blue]Hej[/]", "[yellow]Världen[/]", string.Empty); var table = new Table().Border(TableBorder.Rounded); table.AddColumn(new TableColumn(new Panel("[u]ABC[/]").BorderColor(Color.Red))); table.AddColumn(new TableColumn(new Panel("[u]DEF[/]").BorderColor(Color.Green))); table.AddColumn(new TableColumn(new Panel("[u]GHI[/]").BorderColor(Color.Blue))); table.AddRow(new Text("Hello").Centered(), new Markup("[red]World[/]"), Text.Empty); table.AddRow(second, new Text("Whaat"), new Text("Lol").RightAligned()); table.AddRow(new Markup("[blue]Hej[/]"), new Markup("[yellow]Världen[/]"), Text.Empty); // When console.Render(table); // Then console.Lines.Count.ShouldBe(12); console.Lines[00].ShouldBe("╭───────┬───────┬───────╮"); console.Lines[01].ShouldBe("│ ┌───┐ │ ┌───┐ │ ┌───┐ │"); console.Lines[02].ShouldBe("│ │ A │ │ │ D │ │ │ G │ │"); console.Lines[03].ShouldBe("│ │ B │ │ │ E │ │ │ H │ │"); console.Lines[04].ShouldBe("│ │ C │ │ │ F │ │ │ I │ │"); console.Lines[05].ShouldBe("│ └───┘ │ └───┘ │ └───┘ │"); console.Lines[06].ShouldBe("├───────┼───────┼───────┤"); console.Lines[07].ShouldBe("│ Hello │ World │ │"); console.Lines[08].ShouldBe("│ … │ Whaat │ Lol │"); console.Lines[09].ShouldBe("│ Hej │ Värld │ │"); console.Lines[10].ShouldBe("│ │ en │ │"); console.Lines[11].ShouldBe("╰───────┴───────┴───────╯"); }
public void Should_Render_Unstyled_Text_As_Expected() { // Given var fixture = new PlainConsole(width: 80); var text = new Text("Hello World"); // When fixture.Render(text); // Then fixture.Output .NormalizeLineEndings() .ShouldBe("Hello World"); }
public Task Should_Expand_Panel_If_Enabled() { // Given var console = new PlainConsole(width: 80); // When console.Render(new Panel(new Text("Hello World")) { Expand = true, }); // Then return(Verifier.Verify(console.Output)); }
public void Should_Inject_Renderable_Before_Writing_To_Console() { // Given var console = new PlainConsole(); console.Pipeline.Attach(new HelloRenderHook()); // When console.Render(new Text("World")); // Then console.Lines[0].ShouldBe("Hello"); console.Lines[1].ShouldBe("World"); }
public Task Should_Return_Validation_Error_If_Value_Cannot_Be_Converted() { // Given var console = new PlainConsole(); console.Input.PushText("ninety-nine"); console.Input.PushText("99"); // When console.Prompt(new TextPrompt <int>("Age?")); // Then return(Verifier.Verify(console.Lines)); }
public Task Should_Render_Panel_With_Padding() { // Given var console = new PlainConsole(width: 80); // When console.Render(new Panel(new Text("Hello World")) { Padding = new Padding(3, 1, 5, 2), }); // Then return(Verifier.Verify(console.Output)); }
public void Should_Render_Panel() { // Given var console = new PlainConsole(width: 80); // When console.Render(new Panel(new Text("Hello World"))); // Then console.Lines.Count.ShouldBe(3); console.Lines[0].ShouldBe("┌─────────────┐"); console.Lines[1].ShouldBe("│ Hello World │"); console.Lines[2].ShouldBe("└─────────────┘"); }
public Task Should_Render_Default_Rule_With_Title_Right_Aligned() { // Given var console = new PlainConsole(width: 40); // When console.Render(new Rule("Hello World") { Alignment = Justify.Right, }); // Then return(Verifier.Verify(console.Output)); }
public void Should_Split_Unstyled_Text_To_New_Lines_If_Width_Exceeds_Console_Width( int width, string input, string expected) { // Given var fixture = new PlainConsole(width); var text = new Text(input); // When fixture.Render(text); // Then fixture.Output .NormalizeLineEndings() .ShouldBe(expected); }
public void Should_Overflow_Text_Correctly(Overflow overflow, string expected) { // Given var fixture = new PlainConsole(14); var text = new Text("foo pneumonoultramicroscopicsilicovolcanoconiosis bar qux") .SetOverflow(overflow); // When fixture.Render(text); // Then fixture.Output .NormalizeLineEndings() .ShouldBe(expected); }
public Task Should_Render_Calendar_Correctly() { // Given var console = new PlainConsole(width: 80); var calendar = new Calendar(2020, 10) .AddCalendarEvent(new DateTime(2020, 9, 1)) .AddCalendarEvent(new DateTime(2020, 10, 3)) .AddCalendarEvent(new DateTime(2020, 10, 12)); // When console.Render(calendar); // Then return(Verifier.Verify(console.Output)); }
public void Should_Render_As_Expected() { // Given var console = new PlainConsole(); var panel = Fixture.GetPanel().DoubleBorder(); // When console.Render(panel); // Then console.Lines.Count.ShouldBe(3); console.Lines[0].ShouldBe("╔═Greeting════╗"); console.Lines[1].ShouldBe("║ Hello World ║"); console.Lines[2].ShouldBe("╚═════════════╝"); }
public Task Should_Collapse_Header_If_It_Will_Not_Fit() { // Given var console = new PlainConsole(width: 10); // When console.Render(new Panel("Hello World") { Header = new PanelHeader("Greeting"), Expand = true, }); // Then return(Verifier.Verify(console.Output)); }
public void Should_Render_As_Expected() { // Given var console = new PlainConsole(); var panel = Fixture.GetPanel().SquareBorder(); // When console.Render(panel); // Then console.Lines.Count.ShouldBe(3); console.Lines[0].ShouldBe("┌─Greeting────┐"); console.Lines[1].ShouldBe("│ Hello World │"); console.Lines[2].ShouldBe("└─────────────┘"); }
public void Should_Render_As_Expected() { // Given var console = new PlainConsole(); var panel = Fixture.GetPanel().AsciiBorder(); // When console.Render(panel); // Then console.Lines.Count.ShouldBe(3); console.Lines[0].ShouldBe("+-Greeting----+"); console.Lines[1].ShouldBe("| Hello World |"); console.Lines[2].ShouldBe("+-------------+"); }
public void Should_Render_Default_Rule_With_Title_Right_Aligned() { // Given var console = new PlainConsole(width: 40); // When console.Render(new Rule("Hello World") { Alignment = Justify.Right, }); // Then console.Lines.Count.ShouldBe(1); console.Lines[0].ShouldBe("───────────────────────── Hello World ──"); }
public void Should_Render_As_Expected() { // Given var console = new PlainConsole(); var panel = Fixture.GetPanel().HeavyBorder(); // When console.Render(panel); // Then console.Lines.Count.ShouldBe(3); console.Lines[0].ShouldBe("┏━Greeting━━━━┓"); console.Lines[1].ShouldBe("┃ Hello World ┃"); console.Lines[2].ShouldBe("┗━━━━━━━━━━━━━┛"); }
public void Should_Render_As_Expected() { // Given var console = new PlainConsole(); var table = Fixture.GetTable().NoBorder(); // When console.Render(table); // Then console.Lines.Count.ShouldBe(3); console.Lines[0].ShouldBe("Header 1 Header 2"); console.Lines[1].ShouldBe("Cell Cell "); console.Lines[2].ShouldBe("Cell Cell "); }
public void Should_Render_Panel_With_Multiple_Lines() { // Given var console = new PlainConsole(width: 80); // When console.Render(new Panel(new Text("Hello World\nFoo Bar"))); // Then console.Lines.Count.ShouldBe(4); console.Lines[0].ShouldBe("┌─────────────┐"); console.Lines[1].ShouldBe("│ Hello World │"); console.Lines[2].ShouldBe("│ Foo Bar │"); console.Lines[3].ShouldBe("└─────────────┘"); }
public Task Should_Render_Panel_With_Centered_Header() { // Given var console = new PlainConsole(width: 80); // When console.Render(new Panel("Hello World") { Header = new PanelHeader("Greeting").Centered(), Expand = true, }); // Then return(Verifier.Verify(console.Output)); }
public Task Should_Center_Child_Correctly() { // Given var console = new PlainConsole(width: 25); // When console.Render( new Panel(new Text("Hello World").Centered()) { Expand = true, }); // Then return(Verifier.Verify(console.Output)); }
public void Should_Write_Exception() { // Given var console = new PlainConsole(width: 1024); var dex = GetException(() => TestExceptions.MethodThatThrows(null)); // When var result = console.WriteExceptionAndGetLines(dex); // Then result.Length.ShouldBe(4); result[0].ShouldBe("System.InvalidOperationException: Throwing!"); result[1].ShouldBe(" at Spectre.Console.Tests.Data.TestExceptions.MethodThatThrows(Nullable`1 number) in /xyz/Exceptions.cs:nn"); result[2].ShouldBe(" at Spectre.Console.Tests.Unit.ExceptionTests.<>c.<Should_Write_Exception>b__0_0() in /xyz/ExceptionTests.cs:nn"); result[3].ShouldBe(" at Spectre.Console.Tests.Unit.ExceptionTests.GetException(Action action) in /xyz/ExceptionTests.cs:nn"); }
public void Should_Render_Panel_Inside_Panel_Correctly() { // Given var console = new PlainConsole(width: 80); // When console.Render(new Panel(new Panel(new Text("Hello World")))); // Then console.Lines.Count.ShouldBe(5); console.Lines[0].ShouldBe("┌─────────────────┐"); console.Lines[1].ShouldBe("│ ┌─────────────┐ │"); console.Lines[2].ShouldBe("│ │ Hello World │ │"); console.Lines[3].ShouldBe("│ └─────────────┘ │"); console.Lines[4].ShouldBe("└─────────────────┘"); }
public void Should_Render_Panel_With_Unicode_Correctly() { // Given var console = new PlainConsole(width: 80); // When console.Render(new Panel(new Text(" \n💩\n "))); // Then console.Lines.Count.ShouldBe(5); console.Lines[0].ShouldBe("┌────┐"); console.Lines[1].ShouldBe("│ │"); console.Lines[2].ShouldBe("│ 💩 │"); console.Lines[3].ShouldBe("│ │"); console.Lines[4].ShouldBe("└────┘"); }
public void Should_Write_Exception_With_Shortened_Methods() { // Given var console = new PlainConsole(width: 1024); var dex = GetException(() => TestExceptions.MethodThatThrows(null)); // When var result = console.WriteExceptionAndGetLines(dex, ExceptionFormats.ShortenMethods); // Then result.Length.ShouldBe(4); result[0].ShouldBe("System.InvalidOperationException: Throwing!"); result[1].ShouldBe(" at MethodThatThrows(Nullable`1 number) in /xyz/Exceptions.cs:nn"); result[2].ShouldBe(" at <Should_Write_Exception_With_Shortened_Methods>b__2_0() in /xyz/ExceptionTests.cs:nn"); result[3].ShouldBe(" at GetException(Action action) in /xyz/ExceptionTests.cs:nn"); }
public Task Should_Render_Table_With_Multiple_Rows_In_Cell_Correctly() { // Given var console = new PlainConsole(width: 80); var table = new Table(); table.AddColumns("Foo", "Bar", "Baz"); table.AddRow("Qux\nQuuux", "Corgi", "Waldo"); table.AddRow("Grault", "Garply", "Fred"); // When console.Render(table); // Then return(Verifier.Verify(console.Output)); }