Skip to content

Commit f546dca

Browse files
committed
Add tests
1 parent e86f64b commit f546dca

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/PowerShellEditorServices/Services/TextDocument/Handlers/CompletionHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ private static string GetTypeFilterText(string textToBeReplaced, string completi
455455
/// <param name="documentation">The remaining text after the type, if any</param>
456456
/// <param name="label">The label to check for in the documentation prefix</param>
457457
/// <returns>Whether or not the type was found.</returns>
458-
private static bool TryExtractType(string toolTipText, string label, out string type, out string documentation)
458+
internal static bool TryExtractType(string toolTipText, string label, out string type, out string documentation)
459459
{
460460
MatchCollection matches = s_typeRegex.Matches(toolTipText);
461461
type = string.Empty;

test/PowerShellEditorServices.Test/Language/CompletionHandlerTests.cs

+23
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,28 @@ public async Task CompletesFilePath()
126126
Assert.Equal(actual.TextEdit.TextEdit with { NewText = "" }, CompleteFilePath.ExpectedEdit);
127127
Assert.All(results, r => Assert.True(r.Kind is CompletionItemKind.File or CompletionItemKind.Folder));
128128
}
129+
130+
// TODO: These should be an integration tests at a higher level if/when https://github.com/PowerShell/PowerShell/pull/25108 is merged. As of today, we can't actually test this in the PS engine currently.
131+
[Fact]
132+
public void CanExtractTypeAndDescriptionFromTooltip()
133+
{
134+
string expectedType = "[string]";
135+
string expectedDescription = "Test String";
136+
string paramName = "TestParam";
137+
string testHelp = $"{expectedType} {paramName} - {expectedDescription}";
138+
Assert.True(PsesCompletionHandler.TryExtractType(testHelp, paramName, out string type, out string description));
139+
Assert.Equal(expectedType, type);
140+
Assert.Equal(expectedDescription, description);
141+
}
142+
143+
[Fact]
144+
public void CanExtractTypeFromTooltip()
145+
{
146+
string expectedType = "[string]";
147+
string testHelp = $"{expectedType}";
148+
Assert.True(PsesCompletionHandler.TryExtractType(testHelp, string.Empty, out string type, out string description));
149+
Assert.Null(description);
150+
Assert.Equal(expectedType, type);
151+
}
129152
}
130153
}

0 commit comments

Comments
 (0)