Skip to content

Commit

Permalink
Fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju committed Oct 20, 2024
1 parent 24c3d5d commit f70ea98
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 5 deletions.
4 changes: 2 additions & 2 deletions source/Private/ConvertTo-WikiSidebarLinkName.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Returns: "My Page Name"
.EXAMPLE
PS C:\> "UnicodeHyphen" | ConvertTo-WikiSidebarLinkName
PS C:\> ('Unicode{0}Hyphen' -f [System.Char]::ConvertFromUtf32(0x2011)) | ConvertTo-WikiSidebarLinkName
Returns: "Unicode-Hyphen"
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Task Clean_WikiContent_For_GitHub_Publish {

$hasTopHeader = $content -match '(?m)^#\s+([^\r\n]+)'

Check warning on line 107 in source/tasks/Clean_WikiContent_For_GitHub_Publish.build.ps1

View check run for this annotation

Codecov / codecov/patch

source/tasks/Clean_WikiContent_For_GitHub_Publish.build.ps1#L107

Added line #L107 was not covered by tests

$baseNameWithoutNonBreakingHyphen = $_.BaseName -replace [System.Char]::ConvertFromUtf32(0x2010), '-'
$baseNameWithoutNonBreakingHyphen = $_.BaseName -replace [System.Char]::ConvertFromUtf32(0x2011), '-'

Check warning on line 109 in source/tasks/Clean_WikiContent_For_GitHub_Publish.build.ps1

View check run for this annotation

Codecov / codecov/patch

source/tasks/Clean_WikiContent_For_GitHub_Publish.build.ps1#L109

Added line #L109 was not covered by tests

if ($hasTopHeader -and $Matches[1] -eq $baseNameWithoutNonBreakingHyphen)

Check warning on line 111 in source/tasks/Clean_WikiContent_For_GitHub_Publish.build.ps1

View check run for this annotation

Codecov / codecov/patch

source/tasks/Clean_WikiContent_For_GitHub_Publish.build.ps1#L111

Added line #L111 was not covered by tests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 112 in source/tasks/Prepare_Markdown_FileNames_For_GitHub_Publish.build.ps1

View check run for this annotation

Codecov / codecov/patch

source/tasks/Prepare_Markdown_FileNames_For_GitHub_Publish.build.ps1#L109-L112

Added lines #L109 - L112 were not covered by tests

Write-Build -Color DarkGray -Text ('Renaming: {0} -> {1}' -f $_.Name, $newName)

Check warning on line 114 in source/tasks/Prepare_Markdown_FileNames_For_GitHub_Publish.build.ps1

View check run for this annotation

Codecov / codecov/patch

source/tasks/Prepare_Markdown_FileNames_For_GitHub_Publish.build.ps1#L114

Added line #L114 was not covered by tests

Expand Down
57 changes: 57 additions & 0 deletions tests/unit/private/ConvertTo-WikiSidebarLinkName.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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'
}
}
}
}
2 changes: 1 addition & 1 deletion tests/unit/public/New-GitHubWikiSidebar.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Category: Help topics
# RandomHelpTopic
'@

Set-Content -Path "$($TestDrive.FullName)/WikiContent/Get-Something.md" -Value @'
Set-Content -Path "$($TestDrive.FullName)/WikiContent/GetSomething.md" -Value @'
---
Type: Command
Category: Commands
Expand Down

0 comments on commit f70ea98

Please sign in to comment.