2020-03-24 11:08:37 -07:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
2018-02-13 09:23:53 -08:00
|
|
|
# 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" {
|
2020-05-07 13:00:30 +01:00
|
|
|
$results = New-Object psobject | Add-Member -PassThru noteproperty 'name with square brackets: [0]' 'myvalue' | Out-String
|
2018-03-23 10:26:23 -07:00
|
|
|
$results.Length | Should -BeGreaterThan 1
|
2020-01-24 19:00:37 +00:00
|
|
|
$results | Should -BeOfType System.String
|
2018-03-23 10:26:23 -07:00
|
|
|
$results.Contains("myvalue") | Should -BeTrue
|
|
|
|
|
$results.Contains("name with square brackets: [0]") | Should -BeTrue
|
2016-04-14 00:17:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2018-03-23 10:26:23 -07:00
|
|
|
$testArray | Out-String | Should -BeExactly "a$nl b$nl"
|
2020-01-24 19:00:37 +00:00
|
|
|
,$($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
|
|
|
|
2020-01-24 19:00:37 +00: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
|
|
|
|
2020-01-11 15:41:59 +00: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
|
|
|
|
2018-03-23 10:26:23 -07: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"
|
2018-03-23 10:26:23 -07:00
|
|
|
$testArray | Out-String -NoNewLine | Should -BeExactly "ab"
|
2017-10-11 19:14:57 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should preserve embedded newline when the nonewline switch is used" {
|
|
|
|
|
$testArray = "a$nl", "b"
|
2018-03-23 10:26:23 -07:00
|
|
|
$testArray | Out-String -NoNewLine | Should -BeExactly "a${nl}b"
|
2017-10-11 19:14:57 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should throw error when NoNewLine and Stream are used together" {
|
|
|
|
|
$testArray = "a", "b"
|
2018-05-17 14:42:04 -07:00
|
|
|
{ $testArray | Out-String -NoNewLine -Stream } | Should -Throw -ErrorId "AmbiguousParameterSet,Microsoft.PowerShell.Commands.OutStringCommand"
|
2017-10-11 19:14:57 +05:30
|
|
|
}
|
2016-03-04 14:48:30 -08:00
|
|
|
}
|