mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
* Capitalize 'Should' command and fix whitespace ```powershell $_ -ireplace '\s?\|\s?should\b',' | Should' ``` * Capitalise and apply hyphen to 'Not' parameter ```powershell $_ -ireplace '(\| Should) not\b','$1 -Not' ``` * Capitalise and apply hyphen to 'Be' parameter ```powershell $_ -ireplace '(\| Should(?: -Not)?) -?be\b','$1 -Be' ``` * Capitalise and apply hyphen to 'BeExactly' parameter $_ -ireplace '(\| Should(?: -Not)?) -?beexactly\b','$1 -BeExactly' * Capitalise and apply hyphen to 'BeGreaterThan' parameter ```powershell $_ -ireplace '(\| Should(?: -Not)?) -?begreaterthan\b','$1 -BeGreaterThan' ``` * Use 'BeTrue' parameter ```powershell $_ -ireplace '(\| Should(?: -Not)?) -Be\s\$?true\b','$1 -BeTrue' ``` * Use 'BeFalse' parameter ```powershell $_ -ireplace '(\| Should(?: -Not)?) -Be\s\$?false\b','$1 -BeFalse' ``` * Capitalise and apply hyphen to 'Match' parameter ```powershell $_ -ireplace '(\| Should(?: -Not)?)\s-?match\b','$1 -Match' ``` * Capitalise and apply hyphen to 'Throw' parameter ```powershell $_ -ireplace '(\| Should(?: -Not)?)\s-?throw\b','$1 -Throw' ``` * Capitalise and apply hyphen to 'BeNullOrEmpty' parameter ```powershell $_ -ireplace '(\| Should(?: -Not)?)\s-?benullorempty\b','$1 -BeNullOrEmpty' ``` * Capitalise 'Because' parameter ```powershell $_ -ireplace '\s-because\b',' -Because' ``` * Fix 'BeNullOrEmpty'
66 lines
2.4 KiB
PowerShell
66 lines
2.4 KiB
PowerShell
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
# Licensed under the MIT License.
|
|
Describe "Out-String DRT Unit Tests" -Tags "CI" {
|
|
|
|
It "check display of properties with names containing wildcard characters" {
|
|
$results = new-object psobject | add-member -passthru noteproperty 'name with square brackets: [0]' 'myvalue' | out-string
|
|
$results.Length | Should -BeGreaterThan 1
|
|
$results | Should -BeOfType "System.String"
|
|
$results.Contains("myvalue") | Should -BeTrue
|
|
$results.Contains("name with square brackets: [0]") | Should -BeTrue
|
|
}
|
|
|
|
}
|
|
|
|
Describe "Out-String" -Tags "CI" {
|
|
|
|
BeforeAll {
|
|
$nl = [Environment]::NewLine
|
|
}
|
|
|
|
It "Should accumulate the strings and returns them as a single string" {
|
|
$testArray = "a", " b"
|
|
|
|
$testArray | Out-String | Should -BeExactly "a$nl b$nl"
|
|
,$($testArray | Out-String) | Should -BeOfType "System.String"
|
|
}
|
|
|
|
It "Should be able to return an array of strings using the stream switch" {
|
|
$testInput = "a", "b"
|
|
|
|
,$($testInput | Out-String) | Should -BeOfType "System.String"
|
|
,$($testInput | Out-String -Stream) | Should -BeOfType "System.Array"
|
|
}
|
|
|
|
It "Should send all objects through a pipeline when not using the stream switch" {
|
|
$testInput = "a", "b"
|
|
$streamoutputlength = $($testInput | Out-String -Stream).Length
|
|
$nonstreamoutputlength = $($testInput | Out-String).Length
|
|
|
|
$nonstreamoutputlength | Should -BeGreaterThan $streamoutputlength
|
|
}
|
|
|
|
It "Should send a single object through a pipeline when the stream switch is used" {
|
|
$testInput = "a", "b"
|
|
$streamoutputlength = $($testInput | Out-String -Stream).Length
|
|
$nonstreamoutputlength = $($testInput | Out-String).Length
|
|
|
|
$streamoutputlength | Should -BeLessThan $nonstreamoutputlength
|
|
}
|
|
|
|
It "Should not print a newline when the nonewline switch is used" {
|
|
$testArray = "a", "b"
|
|
$testArray | Out-String -NoNewLine | Should -BeExactly "ab"
|
|
}
|
|
|
|
It "Should preserve embedded newline when the nonewline switch is used" {
|
|
$testArray = "a$nl", "b"
|
|
$testArray | Out-String -NoNewLine | Should -BeExactly "a${nl}b"
|
|
}
|
|
|
|
It "Should throw error when NoNewLine and Stream are used together" {
|
|
$testArray = "a", "b"
|
|
{ $testArray | Out-String -NoNewLine -Stream } | Should -Throw -ErrorId "AmbiguousParameterSet,Microsoft.PowerShell.Commands.OutStringCommand"
|
|
}
|
|
}
|