@@ -6,6 +6,22 @@ $2space = ' ' * 2
66$4space = ' ' * 4
77$8space = ' ' * 8
88
9+ $stdProperties = @ (
10+ $8space
11+ " $ ( $8space ) Required? false"
12+ " $ ( $8space ) Position? 3"
13+ " $ ( $8space ) Default value"
14+ " $ ( $8space ) Accept pipeline input? false"
15+ " $ ( $8space ) Accept wildcard characters? false"
16+ )
17+ $stdDescription = @ (
18+ " $ ( $8space ) para one, line one."
19+ " $ ( $8space ) para one, line two."
20+ $8space
21+ " $ ( $8space ) para two."
22+ )
23+
24+
925function Stringify ([string []]$text , [switch ]$stripHtml )
1026{
1127 $result = $text -join ' ' -replace " `r " -replace " `n "
@@ -23,6 +39,28 @@ function SplitToArray([string]$text)
2339 $text -split " `r`n "
2440}
2541
42+ function GenerateText ([string ]$paramName , [string []]$description )
43+ {
44+ $text = , " -$paramName "
45+ if ($description ) {
46+ $description | % { $text += $_ }
47+ }
48+ $stdProperties | % { $text += $_ }
49+ $text
50+ }
51+
52+ function GetArrayIndex ([string []]$list , [string ]$target )
53+ {
54+ $matchIndex = -1
55+ for ($i = 0 ; $i -lt $list.Count ; $i ++ ) {
56+ if ($list [$i ] -match $target ) {
57+ $matchIndex = $i
58+ break
59+ }
60+ }
61+ $matchIndex
62+ }
63+
2664Describe ' Convert-HelpToHtmlTree' {
2765
2866 Context ' Body/links' {
@@ -348,11 +386,50 @@ $cmd\S+
348386 ' <br/></div>'
349387 ) -join ' ' ) -replace ' [$[+*?()\\.]' , ' \$&'
350388
351- It ' xxx ' {
389+ It ' correctly renders entire parameter section ' {
352390 $result = Stringify (ConvertTo-Body $stdSections $stdSectionOrder ' any' )
353391
354392 $result | Should Match $expected
355393 }
394+
395+ It ' Separates parameter name from properties with blank line' {
396+ $paramName = ' SomeParam'
397+ $stdSections.Parameters = GenerateText $paramName
398+
399+ $result = ConvertTo-Body $stdSections $stdSectionOrder ' any'
400+
401+ $paramResult = ($result | ? { $_ -match ' PARAMETERS' }) -split " `n "
402+ $i = GetArrayIndex $paramResult $paramName
403+ $paramResult [$i + 1 ] | Should Match ' <br/>'
404+ $paramResult [$i + 2 ] | Should Match ' <br/>'
405+ $paramResult [$i + 3 ] | Should Match ' Required'
406+ }
407+
408+ It ' Does not separate parameter name from description with blank line but includes a line break' {
409+ $paramName = ' SomeParam'
410+ $stdSections.Parameters = GenerateText $paramName $stdDescription
411+
412+ $result = ConvertTo-Body $stdSections $stdSectionOrder ' any'
413+
414+ $paramResult = ($result | ? { $_ -match ' PARAMETERS' }) -split " `n "
415+ $i = GetArrayIndex $paramResult $paramName
416+ $paramResult [$i + 1 ] | Should Match ' <br/>'
417+ $paramResult [$i + 2 ] | Should Match ($stdDescription [0 ] -replace $8space )
418+ }
419+
420+ It ' Separates description from properties with blank line' {
421+ $paramName = ' SomeParam'
422+ $stdSections.Parameters = GenerateText $paramName $stdDescription
423+
424+ $result = ConvertTo-Body $stdSections $stdSectionOrder ' any'
425+
426+ $paramResult = ($result | ? { $_ -match ' PARAMETERS' }) -split " `n "
427+ $descCount = $stdDescription.Count
428+ $i = GetArrayIndex $paramResult ($stdDescription [$descCount - 1 ] -replace $8space )
429+ $paramResult [$i + 1 ] | Should Match ' <br/>'
430+ $paramResult [$i + 2 ] | Should Match ' <br/>'
431+ $paramResult [$i + 3 ] | Should Match ' Required'
432+ }
356433 }
357434
358435 Context ' Indenting and line breaks' {
@@ -650,32 +727,6 @@ $cmd\S+
650727 }
651728
652729 Context ' Parameters' {
653- $8space = ' '
654- $stdProperties = @ (
655- $8space
656- " $ ( $8space ) Required? false"
657- " $ ( $8space ) Position? 3"
658- " $ ( $8space ) Default value"
659- " $ ( $8space ) Accept pipeline input? false"
660- " $ ( $8space ) Accept wildcard characters? false"
661- )
662- $stdDescription = @ (
663- " $ ( $8space ) para one, line one."
664- " $ ( $8space ) para one, line two."
665- $8space
666- " $ ( $8space ) para two."
667- )
668-
669- function GenerateText ([string ]$paramName , [string []]$description )
670- {
671- $text = , " -$paramName "
672- if ($description ) {
673- $description | % { $text += $_ }
674- }
675- $stdProperties | % { $text += $_ }
676- $text
677- }
678-
679730 It ' Emboldens parameter name by itself' {
680731 $paramName = ' SomeParam'
681732 $text = " -$paramName "
0 commit comments