mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-12-27 19:25:47 +08:00
committed by
Patrik Svensson
parent
effdecb1d4
commit
8a01b93aca
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using Shouldly;
|
||||
using Spectre.Console.Composition;
|
||||
using Spectre.Console.Rendering;
|
||||
using Xunit;
|
||||
|
||||
namespace Spectre.Console.Tests.Unit
|
||||
|
||||
@@ -125,8 +125,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
|
||||
// When
|
||||
console.Render(
|
||||
new Panel(
|
||||
new Text("Hello World").WithAlignment(Justify.Right))
|
||||
new Panel(new Text("Hello World").RightAligned())
|
||||
{
|
||||
Expand = true,
|
||||
});
|
||||
@@ -146,8 +145,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
|
||||
// When
|
||||
console.Render(
|
||||
new Panel(
|
||||
new Text("Hello World").WithAlignment(Justify.Center))
|
||||
new Panel(new Text("Hello World").Centered())
|
||||
{
|
||||
Expand = true,
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Shouldly;
|
||||
using Spectre.Console.Composition;
|
||||
using Spectre.Console.Rendering;
|
||||
using Xunit;
|
||||
|
||||
namespace Spectre.Console.Tests.Unit
|
||||
|
||||
@@ -59,7 +59,21 @@ namespace Spectre.Console.Tests.Unit
|
||||
public sealed class TheAddRowMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Throw_If_Rows_Are_Null()
|
||||
public void Should_Throw_If_String_Rows_Are_Null()
|
||||
{
|
||||
// Given
|
||||
var table = new Table();
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => table.AddRow((string[])null));
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<ArgumentNullException>()
|
||||
.ParamName.ShouldBe("columns");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Throw_If_Renderable_Rows_Are_Null()
|
||||
{
|
||||
// Given
|
||||
var table = new Table();
|
||||
|
||||
@@ -1,87 +1,81 @@
|
||||
using System.Text;
|
||||
using Shouldly;
|
||||
using Spectre.Console.Composition;
|
||||
using Spectre.Console.Rendering;
|
||||
using Xunit;
|
||||
|
||||
namespace Spectre.Console.Tests.Unit
|
||||
{
|
||||
public sealed class TextTests
|
||||
{
|
||||
public sealed class Measuring
|
||||
[Fact]
|
||||
public void Should_Consider_The_Longest_Word_As_Minimum_Width()
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Return_The_Longest_Word_As_Minimum_Width()
|
||||
{
|
||||
var text = new Text("Foo Bar Baz\nQux\nLol mobile");
|
||||
var text = new Text("Foo Bar Baz\nQux\nLol mobile");
|
||||
|
||||
var result = text.Measure(new RenderContext(Encoding.Unicode, false), 80);
|
||||
var result = ((IRenderable)text).Measure(new RenderContext(Encoding.Unicode, false), 80);
|
||||
|
||||
result.Min.ShouldBe(6);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Return_The_Longest_Line_As_Maximum_Width()
|
||||
{
|
||||
var text = new Text("Foo Bar Baz\nQux\nLol mobile");
|
||||
|
||||
var result = text.Measure(new RenderContext(Encoding.Unicode, false), 80);
|
||||
|
||||
result.Max.ShouldBe(11);
|
||||
}
|
||||
result.Min.ShouldBe(6);
|
||||
}
|
||||
|
||||
public sealed class Rendering
|
||||
[Fact]
|
||||
public void Should_Consider_The_Longest_Line_As_Maximum_Width()
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Render_Unstyled_Text_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var fixture = new PlainConsole(width: 80);
|
||||
var text = new Text("Hello World");
|
||||
var text = new Text("Foo Bar Baz\nQux\nLol mobile");
|
||||
|
||||
// When
|
||||
fixture.Render(text);
|
||||
var result = ((IRenderable)text).Measure(new RenderContext(Encoding.Unicode, false), 80);
|
||||
|
||||
// Then
|
||||
fixture.Output
|
||||
.NormalizeLineEndings()
|
||||
.ShouldBe("Hello World");
|
||||
}
|
||||
result.Max.ShouldBe(11);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Hello\n\nWorld\n\n")]
|
||||
[InlineData("Hello\r\n\r\nWorld\r\n\r\n")]
|
||||
public void Should_Write_Line_Breaks(string input)
|
||||
{
|
||||
// Given
|
||||
var fixture = new PlainConsole(width: 5);
|
||||
var text = new Text(input);
|
||||
[Fact]
|
||||
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);
|
||||
// When
|
||||
fixture.Render(text);
|
||||
|
||||
// Then
|
||||
fixture.RawOutput.ShouldBe("Hello\n\nWorld\n\n");
|
||||
}
|
||||
// Then
|
||||
fixture.Output
|
||||
.NormalizeLineEndings()
|
||||
.ShouldBe("Hello World");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(5, "Hello World", "Hello\nWorld")]
|
||||
[InlineData(10, "Hello Sweet Nice World", "Hello \nSweet Nice\nWorld")]
|
||||
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);
|
||||
[Theory]
|
||||
[InlineData("Hello\n\nWorld\n\n")]
|
||||
[InlineData("Hello\r\n\r\nWorld\r\n\r\n")]
|
||||
public void Should_Write_Line_Breaks(string input)
|
||||
{
|
||||
// Given
|
||||
var fixture = new PlainConsole(width: 5);
|
||||
var text = new Text(input);
|
||||
|
||||
// When
|
||||
fixture.Render(text);
|
||||
// When
|
||||
fixture.Render(text);
|
||||
|
||||
// Then
|
||||
fixture.Output
|
||||
.NormalizeLineEndings()
|
||||
.ShouldBe(expected);
|
||||
}
|
||||
// Then
|
||||
fixture.RawOutput.ShouldBe("Hello\n\nWorld\n\n");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(5, "Hello World", "Hello\nWorld")]
|
||||
[InlineData(10, "Hello Sweet Nice World", "Hello \nSweet Nice\nWorld")]
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user