2018-02-13 09:23:53 -08:00
|
|
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
|
# Licensed under the MIT License.
|
2016-07-25 14:01:41 -07:00
|
|
|
Describe "Out-String DRT Unit Tests" -Tags "CI" {
|
2016-04-14 00:17:02 -07:00
|
|
|
|
2016-06-29 14:23:15 -07:00
|
|
|
It "check display of properties with names containing wildcard characters" {
|
2016-04-14 00:17:02 -07:00
|
|
|
$results = new-object psobject | add-member -passthru noteproperty 'name with square brackets: [0]' 'myvalue' | out-string
|
|
|
|
|
$results.Length | Should BeGreaterThan 1
|
2017-02-16 04:40:51 +04:00
|
|
|
$results | Should BeOfType "System.String"
|
2016-04-14 00:17:02 -07:00
|
|
|
$results.Contains("myvalue") | Should Be $true
|
|
|
|
|
$results.Contains("name with square brackets: [0]") | Should Be $true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-25 14:01:41 -07:00
|
|
|
Describe "Out-String" -Tags "CI" {
|
2017-02-16 04:40:51 +04:00
|
|
|
|
|
|
|
|
BeforeAll {
|
|
|
|
|
$nl = [Environment]::NewLine
|
|
|
|
|
}
|
2016-03-04 14:48:30 -08:00
|
|
|
|
|
|
|
|
It "Should accumulate the strings and returns them as a single string" {
|
2017-02-16 04:40:51 +04:00
|
|
|
$testArray = "a", " b"
|
2016-03-04 14:48:30 -08:00
|
|
|
|
2017-02-16 04:40:51 +04:00
|
|
|
$testArray | Out-String | Should Be "a$nl b$nl"
|
|
|
|
|
,$($testArray | Out-String) | Should BeOfType "System.String"
|
2016-03-04 14:48:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should be able to return an array of strings using the stream switch" {
|
2017-02-16 04:40:51 +04:00
|
|
|
$testInput = "a", "b"
|
2016-03-04 14:48:30 -08:00
|
|
|
|
2017-02-16 04:40:51 +04:00
|
|
|
,$($testInput | Out-String) | Should BeOfType "System.String"
|
|
|
|
|
,$($testInput | Out-String -Stream) | Should BeOfType "System.Array"
|
2016-03-04 14:48:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should send all objects through a pipeline when not using the stream switch" {
|
2016-03-04 14:52:27 -08:00
|
|
|
$testInput = "a", "b"
|
|
|
|
|
$streamoutputlength = $($testInput | Out-String -Stream).Length
|
|
|
|
|
$nonstreamoutputlength = $($testInput | Out-String).Length
|
2016-03-04 14:48:30 -08:00
|
|
|
|
2016-03-04 14:52:27 -08:00
|
|
|
$nonstreamoutputlength| Should BeGreaterThan $streamoutputlength
|
2016-03-04 14:48:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should send a single object through a pipeline when the stream switch is used" {
|
2016-03-04 14:52:27 -08:00
|
|
|
$testInput = "a", "b"
|
|
|
|
|
$streamoutputlength = $($testInput | Out-String -Stream).Length
|
|
|
|
|
$nonstreamoutputlength = $($testInput | Out-String).Length
|
2016-03-04 14:48:30 -08:00
|
|
|
|
2016-03-04 14:52:27 -08:00
|
|
|
$streamoutputlength | Should BeLessThan $nonstreamoutputlength
|
2016-03-04 14:48:30 -08:00
|
|
|
}
|
2017-10-11 19:14:57 +05:30
|
|
|
|
|
|
|
|
It "Should not print a newline when the nonewline switch is used" {
|
|
|
|
|
$testArray = "a", "b"
|
|
|
|
|
$testArray | Out-String -NoNewLine | Should Be "ab"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should preserve embedded newline when the nonewline switch is used" {
|
|
|
|
|
$testArray = "a$nl", "b"
|
|
|
|
|
$testArray | Out-String -NoNewLine | Should Be "a${nl}b"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should throw error when NoNewLine and Stream are used together" {
|
|
|
|
|
$testArray = "a", "b"
|
|
|
|
|
{ $testArray | Out-String -NoNewLine -Stream }| ShouldBeErrorId "AmbiguousParameterSet,Microsoft.PowerShell.Commands.OutStringCommand"
|
|
|
|
|
}
|
2016-03-04 14:48:30 -08:00
|
|
|
}
|