-
Notifications
You must be signed in to change notification settings - Fork 237
Fix #827 Pester TestName w/expandable str returns nothing #851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,8 +32,7 @@ IEnumerable<SymbolReference> IDocumentSymbolProvider.ProvideDocumentSymbols( | |
|
||
return commandAsts.OfType<CommandAst>() | ||
.Where(IsPesterCommand) | ||
.Select(ast => ConvertPesterAstToSymbolReference(scriptFile, ast)) | ||
.Where(pesterSymbol => pesterSymbol?.TestName != null); | ||
.Select(ast => ConvertPesterAstToSymbolReference(scriptFile, ast)); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -105,20 +104,21 @@ private static PesterSymbolReference ConvertPesterAstToSymbolReference(ScriptFil | |
// Check for an explicit "-Name" parameter | ||
if (currentCommandElement is CommandParameterAst parameterAst) | ||
{ | ||
// Found -Name parameter, move to next element which is the argument for -TestName | ||
i++; | ||
if (parameterAst.ParameterName == "Name" && i < pesterCommandAst.CommandElements.Count) | ||
|
||
if (!alreadySawName && TryGetTestNameArgument(pesterCommandAst.CommandElements[i], out testName)) | ||
{ | ||
testName = alreadySawName ? null : (pesterCommandAst.CommandElements[i] as StringConstantExpressionAst)?.Value; | ||
alreadySawName = true; | ||
} | ||
|
||
continue; | ||
} | ||
|
||
// Otherwise, if an argument is given with no parameter, we assume it's the name | ||
// If we've already seen a name, we set the name to null | ||
if (pesterCommandAst.CommandElements[i] is StringConstantExpressionAst testNameStrAst) | ||
if (!alreadySawName && TryGetTestNameArgument(pesterCommandAst.CommandElements[i], out testName)) | ||
{ | ||
testName = alreadySawName ? null : testNameStrAst.Value; | ||
alreadySawName = true; | ||
} | ||
} | ||
|
@@ -131,6 +131,23 @@ private static PesterSymbolReference ConvertPesterAstToSymbolReference(ScriptFil | |
pesterCommandAst.Extent | ||
); | ||
} | ||
|
||
private static bool TryGetTestNameArgument(CommandElementAst commandElementAst, out string testName) | ||
{ | ||
testName = null; | ||
|
||
if (commandElementAst is StringConstantExpressionAst testNameStrAst) | ||
{ | ||
testName = testNameStrAst.Value; | ||
return true; | ||
} | ||
else if (commandElementAst is ExpandableStringExpressionAst) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be a pattern match too since it just tests type overloads. But I'm easy either way :) |
||
{ | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
|
||
/// <summary> | ||
|
Uh oh!
There was an error while loading. Please reload this page.