From f8469153e29eeda7e67026c0c56549dc20493bc0 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sat, 26 Oct 2024 13:39:31 +0200 Subject: [PATCH] `Clean_WikiContent_For_GitHub_Publish`: Fix parsing top level header --- CHANGELOG.md | 6 +++--- ...ean_WikiContent_For_GitHub_Publish.build.ps1 | 5 +++-- ...ean_WikiContent_For_GitHub_Publish.Tests.ps1 | 17 +++++++++++++++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b05913..8eb152e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,9 +22,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 defaults to `$true`. - `Clean_WikiContent_For_GitHub_Publish` - This task will remove the top level header from any markdown file where the top level header equals the - filename (converting Unicode hyphen to ASCII hyphen before comparison). - It can be controlled by parameter `RemoveTopLevelHeader` in the task, which - defaults to `$true`. + filename. The task will convert standard hyphens to spaces and Unicode + hyphens to standard hyphens before comparison. The task can be controlled + by parameter `RemoveTopLevelHeader` in the task, which defaults to `$true`. ### Changed diff --git a/source/tasks/Clean_WikiContent_For_GitHub_Publish.build.ps1 b/source/tasks/Clean_WikiContent_For_GitHub_Publish.build.ps1 index ddd6cc4..fa5fca2 100644 --- a/source/tasks/Clean_WikiContent_For_GitHub_Publish.build.ps1 +++ b/source/tasks/Clean_WikiContent_For_GitHub_Publish.build.ps1 @@ -113,9 +113,10 @@ Task Clean_WikiContent_For_GitHub_Publish { $hasTopHeader = $content -match '(?m)^#\s+([^\r\n]+)' - $baseNameWithoutNonBreakingHyphen = $_.BaseName -replace [System.Char]::ConvertFromUtf32(0x2011), '-' + $convertedBaseName = $_.BaseName -replace '-', ' ' + $convertedBaseName = $convertedBaseName -replace [System.Char]::ConvertFromUtf32(0x2011), '-' - if ($hasTopHeader -and $Matches[1] -eq $baseNameWithoutNonBreakingHyphen) + if ($hasTopHeader -and $Matches[1] -eq $convertedBaseName) { Write-Build -Color DarkGray -Text ('Top level header is the same as the filename. Removing top level header from: {0}' -f $_.Name) diff --git a/tests/unit/tasks/Clean_WikiContent_For_GitHub_Publish.Tests.ps1 b/tests/unit/tasks/Clean_WikiContent_For_GitHub_Publish.Tests.ps1 index 5b7ee54..11cf5a1 100644 --- a/tests/unit/tasks/Clean_WikiContent_For_GitHub_Publish.Tests.ps1 +++ b/tests/unit/tasks/Clean_WikiContent_For_GitHub_Publish.Tests.ps1 @@ -35,9 +35,18 @@ Describe 'Clean_WikiContent_For_GitHub_Publish' { New-Item -Path "$($TestDrive.FullName)/WikiContent" -ItemType 'Directory' -Force | Out-Null - Set-Content -Path "$($TestDrive.FullName)/WikiContent/Get-Something.md" -Value 'Mock markdown file 1' + # Will not be modified + Set-Content -Path "$($TestDrive.FullName)/WikiContent/Get-Something.md" -Value '# Get-Something`nMock markdown file 1' - Set-Content -Path "$($TestDrive.FullName)/WikiContent/home.md" -Value 'Mock markdown file 1' + # Will be modified + Set-Content -Path "$($TestDrive.FullName)/WikiContent/Credential-overview.md" -Value "# Credential overview`nMock markdown file 3" + + # Will not be modified + Set-Content -Path "$($TestDrive.FullName)/WikiContent/Home.md" -Value "# My Module Name`nMock markdown file 4" + + Mock -CommandName Set-Content -MockWith { + Write-Verbose -Message ('Setting content of: {0}' -f $Path) -Verbose + } } It 'Should export the build script alias' { @@ -67,5 +76,9 @@ Describe 'Clean_WikiContent_For_GitHub_Publish' { Invoke-Build -Task $buildTaskName -File $script:buildScript.Definition @taskParameters } | Should -Not -Throw + + Assert-MockCalled -CommandName Set-Content -ParameterFilter { + $Path -eq "$($TestDrive.FullName)/WikiContent/Credential-overview.md" + } -Exactly -Times 1 -Scope It } }