93 lines
2.8 KiB
PowerShell
93 lines
2.8 KiB
PowerShell
|
. $PSScriptRoot\..\..\Load-PesterModules.ps1
|
|||
|
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|||
|
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.tests\.', '.'
|
|||
|
$functionPath = Join-Path -Path $here -ChildPath $sut
|
|||
|
Write-Host "Overriding SUT: $functionPath"
|
|||
|
Import-Module $functionPath -Force
|
|||
|
$moduleForMock = ""
|
|||
|
|
|||
|
Describe "ConvertTo-SafeTeamCityMessage" {
|
|||
|
|
|||
|
Context "When Provided With Non-Newline Characters" {
|
|||
|
It "Should Properly Sanitize |" {
|
|||
|
$testString = "I have a | pipe"
|
|||
|
|
|||
|
$resultString = ConvertTo-SafeTeamCityMessage $testString
|
|||
|
|
|||
|
$resultString | Should -Match "\|\|"
|
|||
|
}
|
|||
|
|
|||
|
It "Should Properly Sanitize '" {
|
|||
|
$testString = "I have an ' apostrophe"
|
|||
|
|
|||
|
$resultString = ConvertTo-SafeTeamCityMessage $testString
|
|||
|
|
|||
|
$resultString | Should -Match "`|'"
|
|||
|
}
|
|||
|
|
|||
|
It "Should Properly Sanitize ’" {
|
|||
|
$testString = "I have a *fancy* ’ apostrophe"
|
|||
|
|
|||
|
$resultString = ConvertTo-SafeTeamCityMessage $testString
|
|||
|
|
|||
|
$resultString | Should -Match "`|’"
|
|||
|
}
|
|||
|
|
|||
|
It "Should Properly Sanitize [" {
|
|||
|
$testString = "I have a left [ bracket"
|
|||
|
|
|||
|
$resultString = ConvertTo-SafeTeamCityMessage $testString
|
|||
|
|
|||
|
# Powershell wants the ` for the |, regex wants the \ for the [... Rage.
|
|||
|
$resultString | Should -Match "`|\["
|
|||
|
}
|
|||
|
|
|||
|
It "Should Properly Sanitize ]" {
|
|||
|
$testString = "I have a right ] bracket"
|
|||
|
|
|||
|
$resultString = ConvertTo-SafeTeamCityMessage $testString
|
|||
|
|
|||
|
$resultString | Should -Match "`|]"
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
Context "When Provided With a Newline Charater" {
|
|||
|
It "Should Properly Sanitize ``n" {
|
|||
|
$testString = "I have an
|
|||
|
end line"
|
|||
|
|
|||
|
$resultString = ConvertTo-SafeTeamCityMessage $testString
|
|||
|
|
|||
|
$resultString | Should -Match "`\|n"
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
Context "When Provided With a Character Return Character" {
|
|||
|
It "Should Properly Sanitize ``r" {
|
|||
|
$testString = "I have a character `r return"
|
|||
|
|
|||
|
$resultString = ConvertTo-SafeTeamCityMessage $testString
|
|||
|
|
|||
|
$resultString | Should -Match "`\|r"
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
Context "When Provided With a String Which Doesn't Need Any Modification" {
|
|||
|
It "Should Make No Changes" {
|
|||
|
$testString = "I am a string with no special characters."
|
|||
|
|
|||
|
$resultString = ConvertTo-SafeTeamCityMessage $testString
|
|||
|
|
|||
|
$resultString | Should -eq $testString
|
|||
|
}
|
|||
|
}
|
|||
|
Context "When Provided With an empty string" {
|
|||
|
It "Should Return an Empty string" {
|
|||
|
$testString = ""
|
|||
|
|
|||
|
$resultString = ConvertTo-SafeTeamCityMessage $testString
|
|||
|
|
|||
|
$resultString | Should -eq $testString
|
|||
|
}
|
|||
|
}
|
|||
|
}
|