diff --git a/src/Spectre.Console/Widgets/TextPath.cs b/src/Spectre.Console/Widgets/TextPath.cs
index db5eafc7e..fafafb7b1 100644
--- a/src/Spectre.Console/Widgets/TextPath.cs
+++ b/src/Spectre.Console/Widgets/TextPath.cs
@@ -74,7 +74,7 @@ public Measurement Measure(RenderOptions options, int maxWidth)
return new Measurement(
Math.Min(length, maxWidth),
- Math.Max(length, maxWidth));
+ Math.Min(length, maxWidth));
}
///
@@ -119,9 +119,6 @@ public IEnumerable Render(RenderOptions options, int maxWidth)
// Align the result
Aligner.Align(parts, Justification, maxWidth);
- // Insert a line break
- parts.Add(Segment.LineBreak);
-
return parts;
}
@@ -134,7 +131,7 @@ private string[] Fit(RenderOptions options, int maxWidth)
}
// Will it fit as is?
- if (_parts.Sum(p => Cell.GetCellLength(p)) + (_parts.Length - 1) < maxWidth)
+ if (_parts.Sum(Cell.GetCellLength) + (_parts.Length - 1) <= maxWidth)
{
return _parts;
}
@@ -159,7 +156,7 @@ private string[] Fit(RenderOptions options, int maxWidth)
var queueWidth =
rootLength // Root (if rooted)
+ ellipsisLength // Ellipsis
- + queue.Sum(p => Cell.GetCellLength(p)) // Middle
+ + queue.Sum(Cell.GetCellLength) // Middle
+ Cell.GetCellLength(_parts.Last()) // Last
+ queue.Count + separatorCount; // Separators
diff --git a/test/Spectre.Console.Tests/Expectations/Widgets/TextPath/GH-1307.Output.verified.txt b/test/Spectre.Console.Tests/Expectations/Widgets/TextPath/GH-1307.Output.verified.txt
new file mode 100644
index 000000000..06cfb5f27
--- /dev/null
+++ b/test/Spectre.Console.Tests/Expectations/Widgets/TextPath/GH-1307.Output.verified.txt
@@ -0,0 +1,3 @@
+┌─────┐ ┌─────┐
+│ Baz │ │ Qux │
+└─────┘ └─────┘
diff --git a/test/Spectre.Console.Tests/Unit/Widgets/TextPathTests.cs b/test/Spectre.Console.Tests/Unit/Widgets/TextPathTests.cs
index d7e5513c7..0dda74206 100644
--- a/test/Spectre.Console.Tests/Unit/Widgets/TextPathTests.cs
+++ b/test/Spectre.Console.Tests/Unit/Widgets/TextPathTests.cs
@@ -1,5 +1,7 @@
namespace Spectre.Console.Tests.Unit;
+[UsesVerify]
+[ExpectationPath("Widgets/TextPath")]
public sealed class TextPathTests
{
[Theory]
@@ -14,8 +16,7 @@ public void Should_Use_Last_Segments_If_Less_Than_Three(int width, string input,
console.Write(new TextPath(input));
// Then
- console.Output.TrimEnd()
- .ShouldBe(expected);
+ console.Output.ShouldBe(expected);
}
[Theory]
@@ -31,8 +32,7 @@ public void Should_Render_Full_Path_If_Possible(string input, string expected)
console.Write(new TextPath(input));
// Then
- console.Output.TrimEnd()
- .ShouldBe(expected);
+ console.Output.ShouldBe(expected);
}
[Theory]
@@ -48,53 +48,50 @@ public void Should_Pop_Segments_From_Left(int width, string input, string expect
console.Write(new TextPath(input));
// Then
- console.Output.TrimEnd()
- .ShouldBe(expected);
+ console.Output.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)
+ [Fact]
+ public void Should_Right_Align_Correctly()
{
// Given
- var console = new TestConsole().Width(80);
+ var console = new TestConsole().Width(40);
// When
- console.Write(new TextPath(input));
+ console.Write(new TextPath("C:/My documents/Bar/Baz.txt").RightJustified());
// Then
- console.Output.ShouldEndWith("\n");
+ console.Output.ShouldBe(" C:/My documents/Bar/Baz.txt");
}
[Fact]
- public void Should_Right_Align_Correctly()
+ public void Should_Center_Align_Correctly()
{
// Given
var console = new TestConsole().Width(40);
// When
- console.Write(new TextPath("C:/My documents/Bar/Baz.txt").RightJustified());
+ 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]
- public void Should_Center_Align_Correctly()
+ [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 TextPath("C:/My documents/Bar/Baz.txt").Centered());
+ console.Write(
+ new Columns(
+ new Panel(new Text("Baz")),
+ new Panel(new TextPath("Qux"))));
// Then
- console.Output.TrimEnd('\n')
- .ShouldBe(" C:/My documents/Bar/Baz.txt ");
+ return Verifier.Verify(console.Output);
}
}
diff --git a/test/Spectre.Console.Tests/Utilities/GitHubIssueAttribute.cs b/test/Spectre.Console.Tests/Utilities/GitHubIssueAttribute.cs
new file mode 100644
index 000000000..d7d30a7c6
--- /dev/null
+++ b/test/Spectre.Console.Tests/Utilities/GitHubIssueAttribute.cs
@@ -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;
+ }
+}
\ No newline at end of file