Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
Join-String.Tests.ps1128 linesDownload Raw Back to Microsoft.PowerShell.Utility
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3 4Describe "Join-String" -Tags "CI" {5 6    BeforeAll {7        $testObject = Get-ChildItem8    }9 10    It "Should be called using the InputObject without error with no other switches" {11        { Join-String -InputObject $testObject } | Should -Not -Throw12    }13 14    It "'Input | Join-String' should be equal to 'Join-String -InputObject Input'" {15        $result1 = $testObject | Join-String16        $result2 = Join-String -InputObject $testObject17        $result1 | Should -BeExactly $result218    }19 20    It "Should return a single string" {21        $actual = $testObject | Join-String22 23        $actual.Count | Should -Be 124        $actual | Should -BeOfType System.String25    }26 27    It "Should join property values with default separator" {28        $expected = $testObject.Name -join $OFS29        $actual = $testObject | Join-String -Property Name30        $actual | Should -BeExactly $expected31    }32 33    It "Should join property values positionally with default separator" {34        $expected = $testObject.Name -join $OFS35        $actual = $testObject | Join-String Name36        $actual | Should -BeExactly $expected37    }38 39    It "Should join property values with custom Separator" {40        $expected = $testObject.Name -join "; "41        $actual = $testObject | Join-String -Property Name -Separator "; "42        $actual | Should -BeExactly $expected43    }44 45    It "Should join property values SingleQuoted" {46        $expected = ($testObject.Name).ForEach{"'$_'"} -join "; "47        $actual = $testObject | Join-String -Property Name -Separator "; " -SingleQuote48        $actual | Should -BeExactly $expected49    }50 51    It "Should join property values DoubleQuoted" {52        $expected = ($testObject.Name).ForEach{"""$_"""} -join "; "53        $actual = $testObject | Join-String -Property Name -Separator "; " -DoubleQuote54        $actual | Should -BeExactly $expected55    }56 57    It "Should join property values Formatted" {58        $expected = ($testObject.Name).ForEach{"[$_]"} -join "; "59        $actual = $testObject | Join-String -Property Name -Separator "; " -Format "[{0}]"60        $actual | Should -BeExactly $expected61    }62 63    It "Should join numeric values Formatted" {64        $testValues = 1.2, 3.4, 5.665        $expected = $testValues.Foreach{"{0:N2}" -f $_} -join "; "66        $actual = $testValues | Join-String -Separator "; " -Format "{0:N2}"67        $actual | Should -BeExactly $expected68    }69 70    It "Should join script block results with default separator" {71        $sb = {$_.Name + $_.Length}72        $expected = ($testObject | ForEach-Object $sb) -join $OFS73        $actual = $testObject | Join-String -Property $sb74        $actual | Should -BeExactly $expected75    }76 77    It "Should join script block results with custom separator" {78        $sb = {$_.Name + $_.Length}79        $expected = ($testObject | ForEach-Object $sb) -join "; "80        $actual = $testObject | Join-String -Property $sb -Separator "; "81        $actual | Should -BeExactly $expected82    }83 84    It "Should join script block results SingleQuoted" {85        $sb = {$_.Name + $_.Length}86        $expected = ($testObject | ForEach-Object $sb).ForEach{"'$_'"} -join $OFS87        $actual = $testObject | Join-String -Property $sb -SingleQuote88        $actual | Should -BeExactly $expected89    }90    It "Should join script block results DoubleQuoted" {91        $sb = {$_.Name + $_.Length}92        $expected = ($testObject | ForEach-Object $sb).ForEach{"""$_"""} -join $OFS93        $actual = $testObject | Join-String -Property $sb -DoubleQuote94        $actual | Should -BeExactly $expected95    }96 97    It "Should join script block results with Format and separator" {98        $sb = {$_.Name + $_.Length}99        $expected = ($testObject | ForEach-Object $sb).ForEach{"[{0}]" -f $_} -join "; "100        $actual = $testObject | Join-String -Property $sb -Separator "; " -Format "[{0}]"101        $actual | Should -BeExactly $expected102    }103 104    It "Should Handle OutputPrefix and OutputSuffix" {105        $OFS = ','106        $expected = "A 1,2,3 B"107        $actual = 1..3 | Join-String -OutputPrefix "A " -OutputSuffix " B"108        $actual | Should -BeExactly $expected109    }110 111    It "Should handle null separator" {112        $expected = -join 'hello'.tochararray()113        $actual = "hello" | Join-String -separator $null114        $actual | Should -BeExactly $expected115    }116 117    It "Should tabcomplete InputObject properties" {118        $cmd = '[io.fileinfo]::new("c:\temp") | Join-String -Property '119        $res = TabExpansion2 $cmd $cmd.length120        $completionTexts = $res.CompletionMatches.CompletionText121        $Properties = [io.fileinfo]::new($PSScriptRoot).psobject.properties.Name122        foreach ($n in $Properties) {123            $n -in $completionTexts | Should -BeTrue124        }125    }126 127}128