Skip to content
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

added support for ordered hashtables #17

Merged
merged 3 commits into from
Nov 20, 2019
Merged
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
34 changes: 33 additions & 1 deletion Modules/MarkdownPS/New-MDTable.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ $VerbosePreference="SilentlyContinue"
$newLine=[System.Environment]::NewLine
Describe "New-MDTable" {
It "-Object is null" {
{New-MDTable -Object $null} | Should Throw "because it is null."
Invoke-Command -ScriptBlock {TRY{New-MDTable -Object $null} CATCH{Return $_.FullyQualifiedErrorId}} | Should Be "ParameterArgumentValidationErrorNullNotAllowed,New-MDTable"
}
}
Describe "New-MDTable without columns" {
Expand Down Expand Up @@ -45,6 +45,38 @@ Describe "New-MDTable with columns" {
}
}

Describe "New-MDTable with ordered hashtable and without columns" {
$object=[PSCustomObject]@{
Name = "This should be the first value"
ZProperty = "This should be in the middle"
AnotherProperty = "This should be the last value"
}
It "-NoNewLine not specified" {
$expected=4
((New-MDTable -Object $object) -split [System.Environment]::NewLine).Length | Should Be $expected
(($object | New-MDTable) -split [System.Environment]::NewLine).Length | Should Be $expected
((@($object, $object) | New-MDTable) -split [System.Environment]::NewLine).Length | Should Be ($expected+1)
}
It "-NoNewLine not specified" {
$expected=3
((New-MDTable -Object $object -NoNewLine) -split [System.Environment]::NewLine).Length | Should Be $expected
(($object | New-MDTable -NoNewLine) -split [System.Environment]::NewLine).Length | Should Be $expected
((@($object, $object) | New-MDTable -NoNewLine) -split [System.Environment]::NewLine).Length | Should Be ($expected+1)
}
It "Header should be in correct order" {
$HeaderRegex = "^\|\s([\w\d]+)\s*\|\s([\w\d]+)\s*\|\s([\w\d]+)\s*\|$"
$expectedHeader = ($object.PsObject.Members | Where-Object {$_.MemberType -eq "NoteProperty"})[0..2].Name
(((New-MDTable -Object $object) -split [System.Environment]::NewLine)[0]) -match $HeaderRegex
$Matches[1..3] | Should Be $expectedHeader

((($object | New-MDTable) -split [System.Environment]::NewLine)[0]) -match $HeaderRegex
$Matches[1..3] | Should Be $expectedHeader

(((@($object, $object) | New-MDTable) -split [System.Environment]::NewLine)[0]) -match $HeaderRegex
$Matches[1..3] | Should Be $expectedHeader
}
}

Describe "New-MDTable with ordered columns" {
$object=Get-Command New-MDTable
$columns=[ordered]@{
Expand Down
2 changes: 1 addition & 1 deletion Modules/MarkdownPS/New-MDTable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function New-MDTable {
}
if(-not $Columns)
{
$Columns=@{}
$Columns=[ordered]@{}
ForEach($item in $Object)
{
$item.PSObject.Properties | %{
Expand Down