MegaBites-AI/Windows-powershell
0308
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3 4Describe 'ConvertFrom-Markdown tests' -Tags 'CI' {5 6 BeforeAll {7 $esc = [char]0x1b8 9 $hostSupportsVT100 = $Host.UI.SupportsVirtualTerminal10 11 function GetExpectedString12 {13 [CmdletBinding()]14 param(15 [ValidateSet(16 "Header1", "Header2", "Header3", "Header4", "Header5", "Header6",17 "Code", "CodeBlock",18 "Link", "Image",19 "Bold", "Italics")]20 [Parameter()]21 [string] $ElementType,22 23 [string] $Text,24 25 [string] $CodeFormatString,26 27 [string] $CodeText,28 29 [bool] $VT100Support30 )31 32 # Force VT100Support to be false if the host does not support it.33 # This makes the expected string to be correct.34 $VT100Support = $VT100Support -and $hostSupportsVT10035 36 switch($elementType)37 {38 "Header1" { if($VT100Support) {"$esc[7m$text$esc[0m`n`n" } else {"$text`n`n"} }39 "Header2" { if($VT100Support) {"$esc[4;93m$text$esc[0m`n`n" } else {"$text`n`n"} }40 "Header3" { if($VT100Support) {"$esc[4;94m$text$esc[0m`n`n" } else {"$text`n`n"} }41 "Header4" { if($VT100Support) {"$esc[4;95m$text$esc[0m`n`n" } else {"$text`n`n"} }42 "Header5" { if($VT100Support) {"$esc[4;96m$text$esc[0m`n`n" } else {"$text`n`n"} }43 "Header6" { if($VT100Support) {"$esc[4;97m$text$esc[0m`n`n" } else {"$text`n`n"} }44 45 "Code" {46 if($VT100Support) {47 if($IsMacOS)48 {49 ($CodeFormatString -f "$esc[107;95m$CodeText$esc[0m") + "`n`n"50 }51 else52 {53 ($CodeFormatString -f "$esc[48;2;155;155;155;38;2;30;30;30m$CodeText$esc[0m") + "`n`n"54 }55 }56 else {57 $CodeFormatString -f "$CodeText" + "`n`n"58 }59 }60 "CodeBlock" {61 $expectedString = @()62 $CodeText -split "`n" | ForEach-Object {63 if($VT100Support) {64 if($IsMacOS) {65 $expectedString += "$esc[107;95m$_$esc[500@$esc[0m"66 }67 else {68 $expectedString += "$esc[48;2;155;155;155;38;2;30;30;30m$_$esc[500@$esc[0m"69 }70 71 }72 else {73 $expectedString += $_74 }75 }76 $returnString = $expectedString -join "`n"77 "$returnString`n`n"78 }79 80 "Link" { if($VT100Support) {"$esc[4;38;5;117m`"$text`"$esc[0m`n" } else { "`"$text`"`n" } }81 "Image" { if($VT100Support) { "$esc[33m[$text]$esc[0m`n" } else { "[$text]`n" } }82 "Bold" { if($VT100Support) { "$esc[1m$text$esc[0m`n" } else { "$text`n" } }83 "Italics" { if($VT100Support) { "$esc[36m$text$esc[0m`n" } else { "$text`n" } }84 }85 }86 87 function GetExpectedHTML88 {89 [CmdletBinding()]90 param(91 [ValidateSet(92 "Header1", "Header2", "Header3", "Header4", "Header5", "Header6",93 "Code", "CodeBlock",94 "Link", "Image",95 "Bold", "Italics")]96 [Parameter()]97 [string] $ElementType,98 99 [string] $Text,100 101 [string] $Url,102 103 [string] $CodeFormatString,104 105 [string] $CodeText106 )107 108 $id = $Text.Replace(" ","-").ToLowerInvariant()109 110 switch($elementType)111 {112 "Header1" { "<h1 id=`"$id`">$text</h1>`n" }113 "Header2" { "<h2 id=`"$id`">$text</h2>`n" }114 "Header3" { "<h3 id=`"$id`">$text</h3>`n" }115 "Header4" { "<h4 id=`"$id`">$text</h4>`n" }116 "Header5" { "<h5 id=`"$id`">$text</h5>`n" }117 "Header6" { "<h6 id=`"$id`">$text</h6>`n" }118 119 "Code" { "<p>" + ($CodeFormatString -f "<code>$CodeText</code>") + "</p>`n" }120 "CodeBlock" { "<pre><code>$CodeText`n</code></pre>`n" }121 122 "Link" { "<p><a href=`"$Url`">$text</a></p>`n" }123 "Image" { "<p><img src=`"$url`" alt=`"$text`" /></p>`n" }124 "Bold" { "<p><strong>$text</strong></p>`n" }125 "Italics" { "<p><em>$text</em></p>`n" }126 }127 }128 }129 130 Context 'Basic tests' {131 BeforeAll {132 $mdFile = New-Item -Path $TestDrive/input.md -Value "Some **test string** to write in a file" -Force133 $mdLiteralPath = New-Item -Path $TestDrive/LiteralPath.md -Value "Some **test string** to write in a file" -Force134 $expectedStringFromFile = if ($hostSupportsVT100) {135 "Some $esc[1mtest string$esc[0m to write in a file`n`n"136 } else {137 "Some test string to write in a file`n`n"138 }139 140 $codeBlock = @'141```142bool function()143{144}145```146'@147 148 $codeBlockText = @"149bool function()`n{`n}150"@151 152 $TestCases = @(153 @{ element = 'Header1'; InputMD = '# Header 1'; Text = 'Header 1'; VT100 = $true }154 @{ element = 'Header2'; InputMD = '## Header 2'; Text = 'Header 2'; VT100 = $true }155 @{ element = 'Header3'; InputMD = '### Header 3'; Text = 'Header 3'; VT100 = $true }156 @{ element = 'Header4'; InputMD = '#### Header 4'; Text = 'Header 4'; VT100 = $true }157 @{ element = 'Header5'; InputMD = '##### Header 5'; Text = 'Header 5'; VT100 = $true }158 @{ element = 'Header6'; InputMD = '###### Header 6'; Text = 'Header 6'; VT100 = $true }159 @{ element = 'Code'; InputMD = 'This is a `code` sample'; CodeFormatString = 'This is a {0} sample'; CodeText = 'code'; VT100 = $true}160 @{ element = 'CodeBlock'; InputMD = $codeBlock; CodeText = $codeBlockText; VT100 = $true }161 @{ element = 'Link'; InputMD = '[GitHub](https://www.github.com)'; Text = 'GitHub'; Url = 'https://www.github.com'; VT100 = $true}162 @{ element = 'Image'; InputMD = ''; Text = 'alt-text'; Url = 'https://bing.com/ps.svg'; VT100 = $true}163 @{ element = 'Bold'; InputMD = '**bold text**'; Text = 'bold text'; VT100 = $true}164 @{ element = 'Italics'; InputMD = '*italics text*'; Text = 'italics text'; VT100 = $true }165 166 @{ element = 'Header1'; InputMD = '# Header 1'; Text = 'Header 1'; VT100 = $false }167 @{ element = 'Header2'; InputMD = '## Header 2'; Text = 'Header 2'; VT100 = $false }168 @{ element = 'Header3'; InputMD = '### Header 3'; Text = 'Header 3'; VT100 = $false }169 @{ element = 'Header4'; InputMD = '#### Header 4'; Text = 'Header 4'; VT100 = $false }170 @{ element = 'Header5'; InputMD = '##### Header 5'; Text = 'Header 5'; VT100 = $false }171 @{ element = 'Header6'; InputMD = '###### Header 6'; Text = 'Header 6'; VT100 = $false }172 @{ element = 'Code'; InputMD = 'This is a `code` sample'; CodeFormatString = 'This is a {0} sample'; CodeText = 'code'; VT100 = $false}173 @{ element = 'CodeBlock'; InputMD = $codeBlock; CodeText = $codeBlockText ; VT100 = $false}174 @{ element = 'Link'; InputMD = '[GitHub](https://www.github.com)'; Text = 'GitHub'; Url = 'https://www.github.com'; VT100 = $false}175 @{ element = 'Image'; InputMD = ''; Text = 'alt-text'; Url = 'https://bing.com/ps.svg'; VT100 = $false}176 @{ element = 'Bold'; InputMD = '**bold text**'; Text = 'bold text' ; VT100 = $false}177 @{ element = 'Italics'; InputMD = '*italics text*'; Text = 'italics text' ; VT100 = $false}178 )179 }180 181 It 'Can convert element : <element> to vt100 using pipeline input - VT100 : <VT100>' -TestCases $TestCases {182 param($element, $inputMD, $text, $codeFormatString, $codeText, $VT100)183 184 try185 {186 if(-not $VT100)187 {188 $options = Get-MarkdownOption189 $options.EnableVT100Encoding = $false190 $options | Set-MarkdownOption191 }192 193 $output = $inputMD | ConvertFrom-Markdown -AsVT100EncodedString194 }195 finally196 {197 $options = Get-MarkdownOption198 $options.EnableVT100Encoding = $true199 $options | Set-MarkdownOption200 }201 202 if($element -like 'Header?' -or203 $element -eq 'Link' -or204 $element -eq 'Image' -or205 $element -eq 'Bold' -or206 $element -eq 'Italics')207 {208 $expectedString = GetExpectedString -ElementType $element -Text $text -VT100Support $VT100209 }210 elseif($element -eq 'Code')211 {212 $expectedString = GetExpectedString -ElementType $element -CodeFormatString $codeFormatString -CodeText $codeText -VT100Support $VT100213 }214 elseif($element -eq 'CodeBlock')215 {216 $expectedString = GetExpectedString -ElementType $element -CodeText $codeText -VT100Support $VT100217 }218 219 $output.VT100EncodedString | Should -BeExactly $expectedString220 }221 222 It 'Can convert element : <element> to HTML using pipeline input' -TestCases $TestCases {223 param($element, $inputMD, $text, $codeFormatString, $codeText, $url)224 225 $output = $inputMD | ConvertFrom-Markdown226 227 if($element -like 'Header?' -or228 $element -eq 'Bold' -or229 $element -eq 'Italics')230 {231 $expectedString = GetExpectedHTML -ElementType $element -Text $text232 }233 elseif($element -eq 'Code')234 {235 $expectedString = GetExpectedHTML -ElementType $element -CodeFormatString $codeFormatString -CodeText $codeText236 }237 elseif($element -eq 'CodeBlock')238 {239 $expectedString = GetExpectedHTML -ElementType $element -CodeText $codeText240 }241 elseif ($element -eq 'Link')242 {243 $expectedString = GetExpectedHTML -ElementType $element -Text $text -Url $url244 }245 elseif ($element -eq 'Image')246 {247 $expectedString = GetExpectedHTML -ElementType $element -Text $text -Url $url248 }249 250 $output.Html | Should -BeExactly $expectedString251 }252 253 It 'Can convert input from a file path to vt100 encoded string' {254 $output = ConvertFrom-Markdown -Path $mdFile.FullName -AsVT100EncodedString255 $output.VT100EncodedString | Should -BeExactly $expectedStringFromFile256 }257 258 It 'Can convert input from a fileinfo object to vt100 encoded string' {259 $ouputFromFileInfo = $mdFile | ConvertFrom-Markdown -AsVT100EncodedString260 $ouputFromFileInfo.VT100EncodedString | Should -BeExactly $expectedStringFromFile261 }262 263 It 'Can convert input from a literal path to vt100 encoded string' {264 $output = ConvertFrom-Markdown -Path $mdLiteralPath -AsVT100EncodedString265 $output.VT100EncodedString | Should -BeExactly $expectedStringFromFile266 }267 268 It 'Can accept Path as positional parameter' {269 $output = ConvertFrom-Markdown $mdFile.FullName -AsVT100EncodedString270 $output.VT100EncodedString | Should -BeExactly $expectedStringFromFile271 }272 }273 274 Context "ConvertFrom-Markdown error cases" {275 It "Gets an error if path is not FileSystem provider path" {276 { ConvertFrom-Markdown -Path Env:\PSModulePath -ErrorAction Stop } | Should -Throw -ErrorId 'OnlyFileSystemPathsSupported,Microsoft.PowerShell.Commands.ConvertFromMarkdownCommand'277 }278 279 It "Gets an error if path does not exist" {280 { ConvertFrom-Markdown -Path DoestnotExist -ErrorAction Stop } | Should -Throw -ErrorId 'FileNotFound,Microsoft.PowerShell.Commands.ConvertFromMarkdownCommand'281 }282 283 It "Gets an error if input object type is not correct" {284 { ConvertFrom-Markdown -InputObject 1 -ErrorAction Stop } | Should -Throw -ErrorId 'InvalidInputObject,Microsoft.PowerShell.Commands.ConvertFromMarkdownCommand'285 }286 287 It "Gets an error if input file does not exist" {288 { [System.IO.FileInfo]::new("IDoNoExist") | ConvertFrom-Markdown -ErrorAction Stop } | Should -Throw -ErrorId 'FileNotFound,Microsoft.PowerShell.Commands.ConvertFromMarkdownCommand'289 }290 }291 292 Context "ConvertFrom-Markdown empty or null content tests" {293 BeforeAll {294 $codeBlock = @'295```CSharp296```297'@298 299 $testCases = @(300 @{Type = "CodeBlock"; Markdown = "$codeBlock"; ExpectedOutput = ''}301 @{Type = "Header1"; Markdown = "# "; ExpectedOutput = ''}302 @{Type = "Header2"; Markdown = "## "; ExpectedOutput = ''}303 @{Type = "Header3"; Markdown = "### "; ExpectedOutput = ''}304 @{Type = "Header4"; Markdown = "#### "; ExpectedOutput = ''}305 @{Type = "Header5"; Markdown = "##### "; ExpectedOutput = ''}306 @{Type = "Header6"; Markdown = "###### "; ExpectedOutput = ''}307 @{Type = "Image"; Markdown = "'![]()'"; ExpectedOutput = if ($hostSupportsVT100) {"'$esc[33m[Image]$esc[0m'"} else {"'[Image]'"}}308 @{Type = "Link"; Markdown = "'[]()'"; ExpectedOutput = if ($hostSupportsVT100) {"'$esc[4;38;5;117m`"`"$esc[0m'"} else {"'`"`"'"}}309 )310 }311 312 It "No error if thrown when empty content is provided for mardown element : <Type>" -TestCases $testCases {313 param($Type, $Markdown, $ExpectedOutput)314 315 $resultObj = ConvertFrom-Markdown -InputObject $Markdown -AsVT100EncodedString316 $resultObj.VT100EncodedString.Trim() | Should -BeExactly $ExpectedOutput317 }318 }319 320 Context "Get/Set-MarkdownOption tests" {321 322 BeforeAll {323 $esc = [char]0x1b324 }325 326 BeforeEach {327 $originalOptions = Get-MarkdownOption328 }329 330 AfterEach {331 Set-MarkdownOption -InputObject $originalOptions332 }333 334 It "Verify default values for MarkdownOptions" {335 $options = Get-MarkdownOption336 337 $options.AsEscapeSequence("Header1") | Should -BeExactly "$esc[7m[7m$esc[0m"338 $options.AsEscapeSequence("Header2") | Should -BeExactly "$esc[4;93m[4;93m$esc[0m"339 $options.AsEscapeSequence("Header3") | Should -BeExactly "$esc[4;94m[4;94m$esc[0m"340 $options.AsEscapeSequence("Header4") | Should -BeExactly "$esc[4;95m[4;95m$esc[0m"341 $options.AsEscapeSequence("Header5") | Should -BeExactly "$esc[4;96m[4;96m$esc[0m"342 $options.AsEscapeSequence("Header6") | Should -BeExactly "$esc[4;97m[4;97m$esc[0m"343 344 if($IsMacOS)345 {346 $options.AsEscapeSequence("Code") | Should -BeExactly "$esc[107;95m[107;95m$esc[0m"347 }348 else349 {350 $options.AsEscapeSequence("Code") | Should -BeExactly "$esc[48;2;155;155;155;38;2;30;30;30m[48;2;155;155;155;38;2;30;30;30m$esc[0m"351 }352 353 $options.AsEscapeSequence("Link") | Should -BeExactly "$esc[4;38;5;117m[4;38;5;117m$esc[0m"354 $options.AsEscapeSequence("Image") | Should -BeExactly "$esc[33m[33m$esc[0m"355 $options.AsEscapeSequence("EmphasisBold") | Should -BeExactly "$esc[1m[1m$esc[0m"356 $options.AsEscapeSequence("EmphasisItalics") | Should -BeExactly "$esc[36m[36m$esc[0m"357 }358 359 It "Verify Set-MarkdownOption can get options" {360 Set-MarkdownOption `361 -Header1Color "[4;1m" `362 -Header2Color "[93m" `363 -Header3Color "[94m" `364 -Header4Color "[95m" `365 -Header5Color "[96m" `366 -Header6Color "[97m" `367 -ImageAltTextForegroundColor "[34m" `368 -LinkForegroundColor "[4;38;5;88m" `369 -ItalicsForegroundColor "[35m" `370 -BoldForegroundColor "[32m"371 372 $newOptions = Get-MarkdownOption373 374 $newOptions.AsEscapeSequence("Header1") | Should -BeExactly "$esc[4;1m[4;1m$esc[0m"375 $newOptions.AsEscapeSequence("Header2") | Should -BeExactly "$esc[93m[93m$esc[0m"376 $newOptions.AsEscapeSequence("Header3") | Should -BeExactly "$esc[94m[94m$esc[0m"377 $newOptions.AsEscapeSequence("Header4") | Should -BeExactly "$esc[95m[95m$esc[0m"378 $newOptions.AsEscapeSequence("Header5") | Should -BeExactly "$esc[96m[96m$esc[0m"379 $newOptions.AsEscapeSequence("Header6") | Should -BeExactly "$esc[97m[97m$esc[0m"380 381 if($IsMacOS)382 {383 $newOptions.AsEscapeSequence("Code") | Should -BeExactly "$esc[107;95m[107;95m$esc[0m"384 }385 else386 {387 $newOptions.AsEscapeSequence("Code") | Should -BeExactly "$esc[48;2;155;155;155;38;2;30;30;30m[48;2;155;155;155;38;2;30;30;30m$esc[0m"388 }389 390 $newOptions.AsEscapeSequence("Link") | Should -BeExactly "$esc[4;38;5;88m[4;38;5;88m$esc[0m"391 $newOptions.AsEscapeSequence("Image") | Should -BeExactly "$esc[34m[34m$esc[0m"392 $newOptions.AsEscapeSequence("EmphasisBold") | Should -BeExactly "$esc[32m[32m$esc[0m"393 $newOptions.AsEscapeSequence("EmphasisItalics") | Should -BeExactly "$esc[35m[35m$esc[0m"394 }395 396 It "Verify defaults for light theme" {397 Set-MarkdownOption -Theme Light398 $options = Get-MarkdownOption399 400 $options.AsEscapeSequence("Header1") | Should -BeExactly "$esc[7m[7m$esc[0m"401 $options.AsEscapeSequence("Header2") | Should -BeExactly "$esc[4;33m[4;33m$esc[0m"402 $options.AsEscapeSequence("Header3") | Should -BeExactly "$esc[4;34m[4;34m$esc[0m"403 $options.AsEscapeSequence("Header4") | Should -BeExactly "$esc[4;35m[4;35m$esc[0m"404 $options.AsEscapeSequence("Header5") | Should -BeExactly "$esc[4;36m[4;36m$esc[0m"405 $options.AsEscapeSequence("Header6") | Should -BeExactly "$esc[4;30m[4;30m$esc[0m"406 407 if($IsMacOS)408 {409 $options.AsEscapeSequence("Code") | Should -BeExactly "$esc[107;95m[107;95m$esc[0m"410 }411 else412 {413 $options.AsEscapeSequence("Code") | Should -BeExactly "$esc[48;2;155;155;155;38;2;30;30;30m[48;2;155;155;155;38;2;30;30;30m$esc[0m"414 }415 416 $options.AsEscapeSequence("Link") | Should -BeExactly "$esc[4;38;5;117m[4;38;5;117m$esc[0m"417 $options.AsEscapeSequence("Image") | Should -BeExactly "$esc[33m[33m$esc[0m"418 $options.AsEscapeSequence("EmphasisBold") | Should -BeExactly "$esc[1m[1m$esc[0m"419 $options.AsEscapeSequence("EmphasisItalics") | Should -BeExactly "$esc[36m[36m$esc[0m"420 }421 422 It "Options should be string without escape sequences" {423 $options = Get-MarkdownOption424 425 $options.Header1 | Should -BeExactly "[7m"426 $options.Header2 | Should -BeExactly "[4;93m"427 $options.Header3 | Should -BeExactly "[4;94m"428 $options.Header4 | Should -BeExactly "[4;95m"429 $options.Header5 | Should -BeExactly "[4;96m"430 $options.Header6 | Should -BeExactly "[4;97m"431 432 if($IsMacOS)433 {434 $options.Code | Should -BeExactly "[107;95m"435 }436 else437 {438 $options.Code | Should -BeExactly "[48;2;155;155;155;38;2;30;30;30m"439 }440 441 442 $options.Link | Should -BeExactly "[4;38;5;117m"443 $options.Image | Should -BeExactly "[33m"444 $options.EmphasisBold | Should -BeExactly "[1m"445 $options.EmphasisItalics | Should -BeExactly "[36m"446 }447 }448 449 Context "Show-Markdown tests" {450 BeforeEach {451 [System.Management.Automation.Internal.InternalTestHooks]::SetTestHook("ShowMarkdownOutputBypass", $true)452 }453 454 AfterEach {455 [System.Management.Automation.Internal.InternalTestHooks]::SetTestHook("ShowMarkdownOutputBypass", $false)456 }457 458 It "Can show VT100 converted from markdown" {459 $text = "Bold"460 $mdText = "**$text**"461 $expectedString = GetExpectedString -ElementType 'Bold' -Text $text -VT100Support $true462 463 $result = $mdText | ConvertFrom-Markdown -AsVT100EncodedString | Show-Markdown464 $result | Should -BeExactly $expectedString465 }466 467 It "Can show HTML converted from markdown" {468 $text = "Bold"469 $mdText = "**$text**"470 $expectedString = GetExpectedHTML -ElementType 'Bold' -Text $text471 472 $result = $mdText | ConvertFrom-Markdown | Show-Markdown -UseBrowser473 $result | Should -BeExactly $expectedString474 }475 476 It "Markdown files work with cmdlet: <pathParam>" -TestCases @(477 @{ pathParam = "Path" }478 @{ pathParam = "LiteralPath" }479 ) {480 param($pathParam)481 482 $text = "Header"483 $mdText = "# $text"484 $expectedString = GetExpectedString -ElementType Header1 -Text $text -VT100Support $true485 $mdFile = Join-Path $TestDrive "test.md"486 Set-Content -Path $mdFile -Value $mdText487 488 $params = @{ $pathParam = $mdFile }489 $result = Show-Markdown @params490 $result | Should -BeExactly $expectedString491 }492 493 It "Can show markdown piped directly to cmdlet" {494 $text = "Header"495 $mdText = "# $text"496 $expectedString = GetExpectedString -ElementType Header1 -Text $text -VT100Support $true497 498 $result = $mdText | Show-Markdown499 $result | Should -BeExactly $expectedString500 }501 502 It "Can show markdown piped directly to cmdlet as HTML" {503 $text = "Header"504 $mdText = "# $text"505 $expectedString = GetExpectedHTML -ElementType Header1 -Text $text506 507 $result = $mdText | Show-Markdown -UseBrowser508 $result | Should -BeExactly $expectedString509 }510 511 It "Gets an error if the input object is missing the <propertyname> property." -TestCases @(512 @{ propertyname = 'Html' }513 @{ propertyname = 'VT100EncodedString' }514 ) {515 param($propertyname)516 517 $markdownInfo = [Microsoft.PowerShell.MarkdownRender.MarkdownInfo]::new()518 519 if($propertyname -eq 'VT100EncodedString')520 {521 { Show-Markdown -InputObject $markdownInfo -ErrorAction Stop } | Should -Throw -ErrorId 'VT100EncodedStringIsNullOrEmpty,Microsoft.PowerShell.Commands.ShowMarkdownCommand'522 }523 else524 {525 { Show-Markdown -UseBrowser -InputObject $markdownInfo -ErrorAction Stop } | Should -Throw -ErrorId 'HtmlIsNullOrEmpty,Microsoft.PowerShell.Commands.ShowMarkdownCommand'526 }527 }528 }529 530 Context "Hosted PowerShell scenario" {531 532 It 'ConvertFrom-Markdown gets expected output when run in hosted powershell' {533 534 try {535 $pool = [runspacefactory]::CreateRunspacePool(1, 2, $Host)536 $pool.Open()537 538 $ps = [powershell]::Create()539 $ps.RunspacePool = $pool540 $ps.AddScript({541 $output = '# test' | ConvertFrom-Markdown542 $output.Html.trim()543 })544 545 $output = $ps.Invoke()546 547 $output | Should -BeExactly '<h1 id="test">test</h1>'548 } finally {549 $ps.Dispose()550 }551 }552 553 It 'Get-MarkdownOption gets default values when run in hosted powershell' {554 555 try {556 $ps = [powershell]::Create()557 $ps.AddScript( {558 Get-MarkdownOption -ErrorAction Stop559 })560 561 $options = $ps.Invoke()562 563 $options | Should -Not -BeNullOrEmpty564 $options.Header1 | Should -BeExactly "[7m"565 $options.Header2 | Should -BeExactly "[4;93m"566 $options.Header3 | Should -BeExactly "[4;94m"567 $options.Header4 | Should -BeExactly "[4;95m"568 $options.Header5 | Should -BeExactly "[4;96m"569 $options.Header6 | Should -BeExactly "[4;97m"570 571 if ($IsMacOS) {572 $options.Code | Should -BeExactly "[107;95m"573 } else {574 $options.Code | Should -BeExactly "[48;2;155;155;155;38;2;30;30;30m"575 }576 577 $options.Link | Should -BeExactly "[4;38;5;117m"578 $options.Image | Should -BeExactly "[33m"579 $options.EmphasisBold | Should -BeExactly "[1m"580 $options.EmphasisItalics | Should -BeExactly "[36m"581 }582 finally {583 $ps.Dispose()584 }585 }586 587 It 'Set-MarkdownOption sets values when run in hosted powershell' {588 589 try {590 $ps = [powershell]::Create()591 $ps.AddScript( {592 Set-MarkdownOption -Header1Color '[93m' -ErrorAction Stop -PassThru593 })594 595 $options = $ps.Invoke()596 597 $options | Should -Not -BeNullOrEmpty598 $options.Header1 | Should -BeExactly "[93m"599 $options.Header2 | Should -BeExactly "[4;93m"600 $options.Header3 | Should -BeExactly "[4;94m"601 $options.Header4 | Should -BeExactly "[4;95m"602 $options.Header5 | Should -BeExactly "[4;96m"603 $options.Header6 | Should -BeExactly "[4;97m"604 605 if ($IsMacOS) {606 $options.Code | Should -BeExactly "[107;95m"607 } else {608 $options.Code | Should -BeExactly "[48;2;155;155;155;38;2;30;30;30m"609 }610 611 $options.Link | Should -BeExactly "[4;38;5;117m"612 $options.Image | Should -BeExactly "[33m"613 $options.EmphasisBold | Should -BeExactly "[1m"614 $options.EmphasisItalics | Should -BeExactly "[36m"615 }616 finally {617 $ps.Dispose()618 }619 }620 }621}622 