Skip to content
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
2 changes: 1 addition & 1 deletion src/MamlWriter/DataType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class DataType
/// <summary>
/// The data-type name.
/// </summary>
[XmlElement("name", Namespace = Constants.XmlNamespace.Dev, Order = 0)]
[XmlElement("name", Namespace = Constants.XmlNamespace.MAML, Order = 0)]
public string Name { get; set; } = string.Empty;

/// <summary>
Expand Down
80 changes: 48 additions & 32 deletions src/Transform/TransformMaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,48 @@ private string ReadNotes(XmlReader reader)
}
}

/// <summary>
/// Reads nodes in &lt;command:inputType&gt; or &lt;command:returnValue&gt;
/// and returns <see cref="InputOutput"/> object if possible.
/// </summary>
/// <param name="subTreeReader">Sub tree instance of <see cref="XmlReader"/>.</param>
private static InputOutput? ReadInputOutput(XmlReader subTreeReader)
{
string? typeName = null;
StringBuilder typeDescription = Constants.StringBuilderPool.Get();

try
{
while (subTreeReader.Read())
{
switch (subTreeReader.Name)
{
// Supports both `<maml:name>` and `<dev:name>`.
// `<dev:name>` is wrong namespace, but used in PlatyPS v1.0.1
case Constants.MamlNameTag:
case "dev:name":
typeName = subTreeReader.ReadElementContentAsString();
continue;
case Constants.MamlParaTag:
typeDescription.AppendLine(subTreeReader.ReadElementContentAsString().Trim())
.AppendLine();
continue;
}
}

if (typeName is not null)
{
return new InputOutput(typeName, typeDescription.ToString().Trim());
}

return null;
}
finally
{
Constants.StringBuilderPool.Return(typeDescription);
}
}

private List<InputOutput> ReadInput(XmlReader reader)
{
List<InputOutput> inputItem = new();
Expand All @@ -298,24 +340,11 @@ private List<InputOutput> ReadInput(XmlReader reader)
{
do
{
string? typeName = null;
string? typeDescription = null;

if (reader.ReadToFollowing(Constants.MamlNameTag))
{
typeName = reader.ReadElementContentAsString();
}

if (reader.ReadToFollowing(Constants.MamlParaTag))
var input = ReadInputOutput(reader.ReadSubtree());
if (input is not null)
{
typeDescription = reader.ReadElementContentAsString();
inputItem.Add(input);
}

if (typeName is not null && typeDescription is not null)
{
inputItem.Add(new InputOutput(typeName, typeDescription));
}

} while (reader.ReadToNextSibling(Constants.MamlCommandInputTypeTag));
}
}
Expand All @@ -333,24 +362,11 @@ private List<InputOutput> ReadOutput(XmlReader reader)
{
do
{
string? typeName = null;
string? typeDescription = null;

if (reader.ReadToFollowing(Constants.MamlNameTag))
{
typeName = reader.ReadElementContentAsString();
}

if (reader.ReadToFollowing(Constants.MamlParaTag))
var output = ReadInputOutput(reader.ReadSubtree());
if (output is not null)
{
typeDescription = reader.ReadElementContentAsString();
outputItem.Add(output);
}

if (typeName is not null && typeDescription is not null)
{
outputItem.Add(new InputOutput(typeName, typeDescription));
}

} while (reader.ReadToNextSibling(Constants.MamlCommandReturnValueTag));
}
}
Expand Down
27 changes: 26 additions & 1 deletion test/Pester/ImportMamlHelp.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,30 @@ Describe "Import-YamlHelp tests" {
$cmdlet.Metadata[$key] | Should -Be $Value
}
}

Context "Inputs/Outputs check" {
It "has the proper Inputs for the '<name>' cmdlet" -testcases @(
@{ name = 'Add-Member'; expectedValues = 'System.Management.Automation.PSObject' },
@{ name = 'Get-PSBreakpoint'; expectedValues = 'System.Int32', 'Microsoft.PowerShell.Commands.BreakpointType' }
) {
param ([string]$name, [string[]]$expectedValues)

$values = $importedCmds.Where({$_.Title -eq $name}).Inputs.Typename
$values | Should -BeExactly $expectedValues
}

It "has the proper Outputs for the '<name>' cmdlet" -testcases @(
@{ name = 'Add-Member'; expectedValues = 'None', 'System.Object' },
@{ name = 'Get-PSBreakpoint'; expectedValues = 'System.Management.Automation.CommandBreakpoint',
'System.Management.Automation.LineBreakpoint',
'System.Management.Automation.VariableBreakpoint',
'System.Management.Automation.Breakpoint' }
) {
param ([string]$name, [string[]]$expectedValues)

$values = $importedCmds.Where({$_.Title -eq $name}).Outputs.Typename
$values | Should -BeExactly $expectedValues
}
}
}
}
}