Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
Out-String.Tests.ps166 linesDownload Raw Back to Microsoft.PowerShell.Utility
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "Out-String DRT Unit Tests" -Tags "CI" {4 5    It "check display of properties with names containing wildcard characters" {6        $results = New-Object psobject | Add-Member -PassThru noteproperty 'name with square brackets: [0]' 'myvalue' | Out-String7        $results.Length | Should -BeGreaterThan 18        $results | Should -BeOfType System.String9        $results.Contains("myvalue") | Should -BeTrue10        $results.Contains("name with square brackets: [0]") | Should -BeTrue11    }12 13}14 15Describe "Out-String" -Tags "CI" {16 17    BeforeAll {18        $nl = [Environment]::NewLine19    }20 21    It "Should accumulate the strings and returns them as a single string" {22        $testArray = "a", " b"23 24        $testArray | Out-String | Should -BeExactly "a$nl b$nl"25        ,$($testArray | Out-String) | Should -BeOfType System.String26    }27 28    It "Should be able to return an array of strings using the stream switch" {29        $testInput = "a", "b"30 31        ,$($testInput | Out-String) | Should -BeOfType System.String32        ,$($testInput | Out-String -Stream) | Should -BeOfType System.Array33    }34 35    It "Should send all objects through a pipeline when not using the stream switch" {36	$testInput = "a", "b"37	$streamoutputlength = $($testInput | Out-String -Stream).Length38	$nonstreamoutputlength = $($testInput | Out-String).Length39 40	$nonstreamoutputlength | Should -BeGreaterThan $streamoutputlength41    }42 43    It "Should send a single object through a pipeline when the stream switch is used" {44	$testInput = "a", "b"45	$streamoutputlength = $($testInput | Out-String -Stream).Length46	$nonstreamoutputlength = $($testInput | Out-String).Length47 48	$streamoutputlength | Should -BeLessThan $nonstreamoutputlength49    }50 51    It "Should not print a newline when the nonewline switch is used" {52        $testArray = "a", "b"53        $testArray | Out-String -NoNewLine | Should -BeExactly "ab"54    }55 56    It "Should preserve embedded newline when the nonewline switch is used" {57        $testArray = "a$nl", "b"58        $testArray | Out-String -NoNewLine | Should -BeExactly "a${nl}b"59    }60 61    It "Should throw error when NoNewLine and Stream are used together" {62        $testArray = "a", "b"63        { $testArray | Out-String -NoNewLine -Stream } | Should -Throw -ErrorId  "AmbiguousParameterSet,Microsoft.PowerShell.Commands.OutStringCommand"64    }65}66