diff --git a/source/Private/ConvertTo-WikiSidebarLinkName.ps1 b/source/Private/ConvertTo-WikiSidebarLinkName.ps1 index e35115e..12bbd4e 100644 --- a/source/Private/ConvertTo-WikiSidebarLinkName.ps1 +++ b/source/Private/ConvertTo-WikiSidebarLinkName.ps1 @@ -17,7 +17,7 @@ Returns: "My Page Name" .EXAMPLE - PS C:\> "Unicode‐Hyphen" | ConvertTo-WikiSidebarLinkName + PS C:\> ('Unicode{0}Hyphen' -f [System.Char]::ConvertFromUtf32(0x2011)) | ConvertTo-WikiSidebarLinkName Returns: "Unicode-Hyphen" @@ -47,7 +47,7 @@ function ConvertTo-WikiSidebarLinkName $convertedName = $Name -replace '-', ' ' # Replace Unicode hyphen (U+2010) with a standard hyphen - $convertedName = $convertedName -replace [System.Char]::ConvertFromUtf32(0x2010), '-' + $convertedName = $convertedName -replace [System.Char]::ConvertFromUtf32(0x2011), '-' return $convertedName } diff --git a/source/tasks/Clean_WikiContent_For_GitHub_Publish.build.ps1 b/source/tasks/Clean_WikiContent_For_GitHub_Publish.build.ps1 index 622e9c8..ed6cd55 100644 --- a/source/tasks/Clean_WikiContent_For_GitHub_Publish.build.ps1 +++ b/source/tasks/Clean_WikiContent_For_GitHub_Publish.build.ps1 @@ -106,7 +106,7 @@ Task Clean_WikiContent_For_GitHub_Publish { $hasTopHeader = $content -match '(?m)^#\s+([^\r\n]+)' - $baseNameWithoutNonBreakingHyphen = $_.BaseName -replace [System.Char]::ConvertFromUtf32(0x2010), '-' + $baseNameWithoutNonBreakingHyphen = $_.BaseName -replace [System.Char]::ConvertFromUtf32(0x2011), '-' if ($hasTopHeader -and $Matches[1] -eq $baseNameWithoutNonBreakingHyphen) { diff --git a/source/tasks/Prepare_Markdown_FileNames_For_GitHub_Publish.build.ps1 b/source/tasks/Prepare_Markdown_FileNames_For_GitHub_Publish.build.ps1 index 2f54d5b..6123c89 100644 --- a/source/tasks/Prepare_Markdown_FileNames_For_GitHub_Publish.build.ps1 +++ b/source/tasks/Prepare_Markdown_FileNames_For_GitHub_Publish.build.ps1 @@ -109,7 +109,7 @@ Task Prepare_Markdown_FileNames_For_GitHub_Publish { $markdownFiles | Where-Object -Property 'Name' -Match '-' | ForEach-Object -Process { - $newName = $_.Name -replace '-', [System.Char]::ConvertFromUtf32(0x2010) + $newName = $_.Name -replace '-', [System.Char]::ConvertFromUtf32(0x2011) Write-Build -Color DarkGray -Text ('Renaming: {0} -> {1}' -f $_.Name, $newName) diff --git a/tests/unit/private/ConvertTo-WikiSidebarLinkName.Tests.ps1 b/tests/unit/private/ConvertTo-WikiSidebarLinkName.Tests.ps1 new file mode 100644 index 0000000..18a6305 --- /dev/null +++ b/tests/unit/private/ConvertTo-WikiSidebarLinkName.Tests.ps1 @@ -0,0 +1,57 @@ +#region HEADER +$script:projectPath = "$PSScriptRoot\..\..\.." | Convert-Path +$script:projectName = (Get-ChildItem -Path "$script:projectPath\*\*.psd1" | Where-Object -FilterScript { + ($_.Directory.Name -match 'source|src' -or $_.Directory.Name -eq $_.BaseName) -and + $(try + { + Test-ModuleManifest -Path $_.FullName -ErrorAction Stop + } + catch + { + $false + }) + }).BaseName + +$script:moduleName = Get-Module -Name $script:projectName -ListAvailable | Select-Object -First 1 +Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue' + +Import-Module $script:moduleName -Force -ErrorAction 'Stop' +#endregion HEADER + +InModuleScope $script:moduleName { + Describe 'ConvertTo-WikiSidebarLinkName' { + Context 'When converting a simple hyphenated name' { + It 'Should replace hyphens with spaces' { + $result = ConvertTo-WikiSidebarLinkName -Name 'My-Page-Name' + $result | Should -Be 'My Page Name' + } + } + + Context 'When converting a name with Unicode hyphens' { + It 'Should replace Unicode hyphens with standard hyphens' { + $result = ConvertTo-WikiSidebarLinkName -Name 'Unicode‑Hyphen' # Note: The hyphen here is a Unicode hyphen (U+2010) + $result | Should -Be 'Unicode-Hyphen' + } + } + + Context 'When the input is piped' { + It 'Should process the piped input correctly' { + 'Piped-Input' | ConvertTo-WikiSidebarLinkName | Should -Be 'Piped Input' + } + } + + Context 'When the input contains multiple types of hyphens' { + It 'Should replace all hyphens appropriately' { + $result = ConvertTo-WikiSidebarLinkName -Name 'Multiple‑Hyphens-Here' # Contains both Unicode and standard hyphens + $result | Should -Be 'Multiple-Hyphens Here' + } + } + + Context 'When the input does not contain hyphens' { + It 'Should return the input unchanged' { + $result = ConvertTo-WikiSidebarLinkName -Name 'NoHyphensHere' + $result | Should -Be 'NoHyphensHere' + } + } + } +} diff --git a/tests/unit/public/New-GitHubWikiSidebar.Tests.ps1 b/tests/unit/public/New-GitHubWikiSidebar.Tests.ps1 index f39c5a0..125f222 100644 --- a/tests/unit/public/New-GitHubWikiSidebar.Tests.ps1 +++ b/tests/unit/public/New-GitHubWikiSidebar.Tests.ps1 @@ -41,7 +41,7 @@ Category: Help topics # RandomHelpTopic '@ - Set-Content -Path "$($TestDrive.FullName)/WikiContent/Get-Something.md" -Value @' + Set-Content -Path "$($TestDrive.FullName)/WikiContent/Get‑Something.md" -Value @' --- Type: Command Category: Commands