Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Turtle.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ $commandsPath = Join-Path $PSScriptRoot Commands
. $file.FullName
}

if ($global:OFS -ne ' ') {
Write-Warning "Turtle requires `$OFS to be a single space for SVG serialization. Setting `$global:OFS to ' '."
$global:OFS = ' '
}

$myModule = $MyInvocation.MyCommand.ScriptBlock.Module
$ExecutionContext.SessionState.PSVariable.Set($myModule.Name, $myModule)
$myModule.pstypenames.insert(0, $myModule.Name)
Expand Down
27 changes: 27 additions & 0 deletions Turtle.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,32 @@ describe Turtle {
}
}
}

context 'Turtle OFS compatibility' {
it 'Warns and sets global OFS when imported with a custom global OFS' {
$originalOFS = $global:OFS
try {
Remove-Module Turtle -ErrorAction Ignore
$global:OFS = '|||'

$importOutput = & {
Import-Module (Join-Path $PSScriptRoot 'Turtle.psd1') -Force
} 3>&1
$importWarnings = @($importOutput | Where-Object { $_ -is [Management.Automation.WarningRecord] })

($importWarnings.Message -join "`n") | Should -Match 'Setting \$global:OFS'
$global:OFS | Should -Be ' '

$svg = (turtle square 10).SVG.OuterXml
$svg | Should -Not -Match '\|\|\|'
$svg | Should -Match 'viewBox=.0 0 '
}
finally {
$global:OFS = $originalOFS
Remove-Module Turtle -ErrorAction Ignore
Import-Module (Join-Path $PSScriptRoot 'Turtle.psd1') -Force | Out-Null
}
}
}
}