mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-11-04 02:25:28 +08:00 
			
		
		
		
	Add support for styling segments
This commit is contained in:
		
				
					committed by
					
						
						Phil Scott
					
				
			
			
				
	
			
			
			
						parent
						
							921d595269
						
					
				
				
					commit
					5e41a2f505
				
			@@ -0,0 +1,7 @@
 | 
			
		||||
<ProjectConfiguration>
 | 
			
		||||
  <Settings>
 | 
			
		||||
    <IgnoredTests>
 | 
			
		||||
      <AllTestsSelector />
 | 
			
		||||
    </IgnoredTests>
 | 
			
		||||
  </Settings>
 | 
			
		||||
</ProjectConfiguration>
 | 
			
		||||
@@ -0,0 +1,7 @@
 | 
			
		||||
<ProjectConfiguration>
 | 
			
		||||
  <Settings>
 | 
			
		||||
    <IgnoredTests>
 | 
			
		||||
      <AllTestsSelector />
 | 
			
		||||
    </IgnoredTests>
 | 
			
		||||
  </Settings>
 | 
			
		||||
</ProjectConfiguration>
 | 
			
		||||
@@ -2,32 +2,6 @@ namespace Spectre.Console.Tests.Unit;
 | 
			
		||||
 | 
			
		||||
public sealed class TextPathTests
 | 
			
		||||
{
 | 
			
		||||
    [Fact]
 | 
			
		||||
    public void Should_Render_Full_Path_If_Possible()
 | 
			
		||||
    {
 | 
			
		||||
        // Given
 | 
			
		||||
        var console = new TestConsole().Width(40);
 | 
			
		||||
 | 
			
		||||
        // When
 | 
			
		||||
        console.Write(new TextPath("C:/Foo/Bar/Baz.txt"));
 | 
			
		||||
 | 
			
		||||
        // Then
 | 
			
		||||
        console.Output.ShouldBe("C:/Foo/Bar/Baz.txt");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [Fact]
 | 
			
		||||
    public void Should_Pop_Segments_From_Left()
 | 
			
		||||
    {
 | 
			
		||||
        // Given
 | 
			
		||||
        var console = new TestConsole().Width(17);
 | 
			
		||||
 | 
			
		||||
        // When
 | 
			
		||||
        console.Write(new TextPath("C:/My documents/Bar/Baz.txt"));
 | 
			
		||||
 | 
			
		||||
        // Then
 | 
			
		||||
        console.Output.ShouldBe("C:/…/Bar/Baz.txt");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [Theory]
 | 
			
		||||
    [InlineData(8, "1234567890", "…4567890")]
 | 
			
		||||
    [InlineData(9, "1234567890", "…34567890")]
 | 
			
		||||
@@ -40,6 +14,56 @@ public sealed class TextPathTests
 | 
			
		||||
        console.Write(new TextPath(input));
 | 
			
		||||
 | 
			
		||||
        // Then
 | 
			
		||||
        console.Output.ShouldBe(expected);
 | 
			
		||||
        console.Output.TrimEnd().ShouldBe(expected);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [Theory]
 | 
			
		||||
    [InlineData("C:/Foo/Bar/Baz.txt", "C:/Foo/Bar/Baz.txt")]
 | 
			
		||||
    [InlineData("/Foo/Bar/Baz.txt", "/Foo/Bar/Baz.txt")]
 | 
			
		||||
    [InlineData("Foo/Bar/Baz.txt", "Foo/Bar/Baz.txt")]
 | 
			
		||||
    public void Should_Render_Full_Path_If_Possible(string input, string expected)
 | 
			
		||||
    {
 | 
			
		||||
        // Given
 | 
			
		||||
        var console = new TestConsole().Width(40);
 | 
			
		||||
 | 
			
		||||
        // When
 | 
			
		||||
        console.Write(new TextPath(input));
 | 
			
		||||
 | 
			
		||||
        // Then
 | 
			
		||||
        console.Output.TrimEnd().ShouldBe(expected);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [Theory]
 | 
			
		||||
    [InlineData(17, "C:/My documents/Bar/Baz.txt", "C:/…/Bar/Baz.txt")]
 | 
			
		||||
    [InlineData(15, "/My documents/Bar/Baz.txt", "/…/Bar/Baz.txt")]
 | 
			
		||||
    [InlineData(14, "My documents/Bar/Baz.txt", "…/Bar/Baz.txt")]
 | 
			
		||||
    public void Should_Pop_Segments_From_Left(int width, string input, string expected)
 | 
			
		||||
    {
 | 
			
		||||
        // Given
 | 
			
		||||
        var console = new TestConsole().Width(width);
 | 
			
		||||
 | 
			
		||||
        // When
 | 
			
		||||
        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");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user