Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fixed link not dispalyed in markup in Style.cs and added unit test cases #1750

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Spectre.Console/Style.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ public string ToMarkup()
builder.Add("on " + Background.ToMarkup());
}

if (Link?.ToString() != null)
{
builder.Add($"link={Link.ToString()}");
}

return string.Join(" ", builder);
}

Expand Down
26 changes: 26 additions & 0 deletions src/Tests/Spectre.Console.Tests/Unit/StyleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,5 +405,31 @@ public void Should_Return_Expected_Markup_For_Style_With_Only_Background_Color()
// Then
result.ShouldBe("default on green");
}

[Fact]
public void Should_Return_Expected_Markup_For_Style_With_Only_Link()
{
// Given
var style = new Style(link:"https://spectreconsole.net/");

// When
var result = style.ToMarkup();

// Then
result.ShouldBe("link=https://spectreconsole.net/");
}

[Fact]
public void Should_Return_Expected_Markup_For_Style_With_Background_And_Link()
{
// Given
var style = new Style(background: Color.Blue, link: "https://spectreconsole.net/");

// When
var result = style.ToMarkup();

// Then
result.ShouldBe("default on blue link=https://spectreconsole.net/");
}
}
}