mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-11-04 02:25:28 +08:00 
			
		
		
		
	Fixes TextPath rendering bugs (#1308)
* Do not emit line break when rendering * Don't be greedy when measuring. * Fix a condition that decides if the path fits in the allotted space. Closes #1307
This commit is contained in:
		@@ -0,0 +1,3 @@
 | 
			
		||||
┌─────┐              ┌─────┐            
 | 
			
		||||
│ Baz │              │ Qux │            
 | 
			
		||||
└─────┘              └─────┘            
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
namespace Spectre.Console.Tests.Unit;
 | 
			
		||||
 | 
			
		||||
[UsesVerify]
 | 
			
		||||
[ExpectationPath("Widgets/TextPath")]
 | 
			
		||||
public sealed class TextPathTests
 | 
			
		||||
{
 | 
			
		||||
    [Theory]
 | 
			
		||||
@@ -14,8 +16,7 @@ public sealed class TextPathTests
 | 
			
		||||
        console.Write(new TextPath(input));
 | 
			
		||||
 | 
			
		||||
        // Then
 | 
			
		||||
        console.Output.TrimEnd()
 | 
			
		||||
            .ShouldBe(expected);
 | 
			
		||||
        console.Output.ShouldBe(expected);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [Theory]
 | 
			
		||||
@@ -31,8 +32,7 @@ public sealed class TextPathTests
 | 
			
		||||
        console.Write(new TextPath(input));
 | 
			
		||||
 | 
			
		||||
        // Then
 | 
			
		||||
        console.Output.TrimEnd()
 | 
			
		||||
            .ShouldBe(expected);
 | 
			
		||||
        console.Output.ShouldBe(expected);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [Theory]
 | 
			
		||||
@@ -48,26 +48,7 @@ public sealed class TextPathTests
 | 
			
		||||
        console.Write(new TextPath(input));
 | 
			
		||||
 | 
			
		||||
        // Then
 | 
			
		||||
        console.Output.TrimEnd()
 | 
			
		||||
            .ShouldBe(expected);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [Theory]
 | 
			
		||||
    [InlineData("C:/My documents/Bar/Baz.txt")]
 | 
			
		||||
    [InlineData("/My documents/Bar/Baz.txt")]
 | 
			
		||||
    [InlineData("My documents/Bar/Baz.txt")]
 | 
			
		||||
    [InlineData("Bar/Baz.txt")]
 | 
			
		||||
    [InlineData("Baz.txt")]
 | 
			
		||||
    public void Should_Insert_Line_Break_At_End_Of_Path(string input)
 | 
			
		||||
    {
 | 
			
		||||
        // Given
 | 
			
		||||
        var console = new TestConsole().Width(80);
 | 
			
		||||
 | 
			
		||||
        // When
 | 
			
		||||
        console.Write(new TextPath(input));
 | 
			
		||||
 | 
			
		||||
        // Then
 | 
			
		||||
        console.Output.ShouldEndWith("\n");
 | 
			
		||||
        console.Output.ShouldBe(expected);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [Fact]
 | 
			
		||||
@@ -80,8 +61,7 @@ public sealed class TextPathTests
 | 
			
		||||
        console.Write(new TextPath("C:/My documents/Bar/Baz.txt").RightJustified());
 | 
			
		||||
 | 
			
		||||
        // Then
 | 
			
		||||
        console.Output.TrimEnd('\n')
 | 
			
		||||
            .ShouldBe("             C:/My documents/Bar/Baz.txt");
 | 
			
		||||
        console.Output.ShouldBe("             C:/My documents/Bar/Baz.txt");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [Fact]
 | 
			
		||||
@@ -94,7 +74,24 @@ public sealed class TextPathTests
 | 
			
		||||
        console.Write(new TextPath("C:/My documents/Bar/Baz.txt").Centered());
 | 
			
		||||
 | 
			
		||||
        // Then
 | 
			
		||||
        console.Output.TrimEnd('\n')
 | 
			
		||||
            .ShouldBe("      C:/My documents/Bar/Baz.txt       ");
 | 
			
		||||
        console.Output.ShouldBe("      C:/My documents/Bar/Baz.txt       ");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [Fact]
 | 
			
		||||
    [Expectation("GH-1307")]
 | 
			
		||||
    [GitHubIssue("https://github.com/spectreconsole/spectre.console/issues/1307")]
 | 
			
		||||
    public Task Should_Behave_As_Expected_When_Rendering_Inside_Panel_Columns()
 | 
			
		||||
    {
 | 
			
		||||
        // Given
 | 
			
		||||
        var console = new TestConsole().Width(40);
 | 
			
		||||
 | 
			
		||||
        // When
 | 
			
		||||
        console.Write(
 | 
			
		||||
            new Columns(
 | 
			
		||||
                new Panel(new Text("Baz")),
 | 
			
		||||
                new Panel(new TextPath("Qux"))));
 | 
			
		||||
 | 
			
		||||
        // Then
 | 
			
		||||
        return Verifier.Verify(console.Output);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										12
									
								
								test/Spectre.Console.Tests/Utilities/GitHubIssueAttribute.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								test/Spectre.Console.Tests/Utilities/GitHubIssueAttribute.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
			
		||||
namespace Spectre.Console.Tests;
 | 
			
		||||
 | 
			
		||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
 | 
			
		||||
public sealed class GitHubIssueAttribute : Attribute
 | 
			
		||||
{
 | 
			
		||||
    public string Url { get; }
 | 
			
		||||
 | 
			
		||||
    public GitHubIssueAttribute(string url)
 | 
			
		||||
    {
 | 
			
		||||
        Url = url;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user