Skip to content

Commit

Permalink
Add test case for previous issue
Browse files Browse the repository at this point in the history
  • Loading branch information
slang25 committed Dec 24, 2023
1 parent 89d212a commit 34892e2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
21 changes: 19 additions & 2 deletions test/Spectre.Console.Tests/Unit/HighlightTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace Namespace;

public class HighlightTests
{
private readonly Style _highlightStyle = new Style(foreground: Color.Default, background: Color.Yellow, Decoration.Bold);

[Fact]
public void Should_Return_Same_Value_When_SearchText_Is_Empty()
{
Expand All @@ -25,7 +27,7 @@ public void Should_Highlight_Matched_Text()
// Given
var value = "Sample text with test word";
var searchText = "test";
var highlightStyle = new Style(foreground: Color.Default, background: Color.Yellow, Decoration.Bold);
var highlightStyle = _highlightStyle;

// When
var result = value.Highlight(searchText, highlightStyle);
Expand All @@ -40,7 +42,22 @@ public void Should_Not_Match_Text_Across_Tokens()
// Given
var value = "[red]Sample text[/] with test word";
var searchText = "text with";
var highlightStyle = new Style(foreground: Color.Default, background: Color.Yellow, Decoration.Bold);
var highlightStyle = _highlightStyle;

// When
var result = value.Highlight(searchText, highlightStyle);

// Then
result.ShouldBe(value);
}

[Fact]
public void Should_Not_Match_Text_Outside_Of_Text_Tokens()
{
// Given
var value = "[red]Sample text with test word[/]";
var searchText = "red";
var highlightStyle = _highlightStyle;

// When
var result = value.Highlight(searchText, highlightStyle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public void Should_Highlight_Search_Term()
prompt.Show(console);

// Then
var consoleOutput = console.Output;
consoleOutput.ShouldContain($"{ESC}[38;5;12m> Item {ESC}[0m{ESC}[1;38;5;12;48;5;11m1{ESC}[0m");
console.Output.ShouldContain($"{ESC}[38;5;12m> Item {ESC}[0m{ESC}[1;38;5;12;48;5;11m1{ESC}[0m");
}
}

0 comments on commit 34892e2

Please sign in to comment.