Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
Split-Path.Tests.ps1129 linesDownload Raw Back to Microsoft.PowerShell.Management
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "Split-Path" -Tags "CI" {4 5    It "Should return a string object when invoked" {6        try {7            Push-Location TestDrive:8            $result = Split-Path .9            $result | Should -BeOfType String10 11            $result = Split-Path . -Leaf12            $result | Should -BeOfType String13 14            $result = Split-Path . -Resolve15            $result | Should -BeOfType String16        }17        finally {18            Pop-Location19        }20    }21 22    It "Should return the name of the drive when the qualifier switch is used" {23	Split-Path -Qualifier env:     | Should -Be "env:"24	Split-Path -Qualifier env:PATH | Should -Be "env:"25    }26 27    It "Should error when using the qualifier switch and no qualifier in the path" {28        { Split-Path -Qualifier -ErrorAction Stop /Users } | Should -Throw29	{ Split-Path -Qualifier -ErrorAction Stop abcdef } | Should -Throw30    }31 32    It "Should error given positional parameter #2" {33	    { Split-Path env: $NULL } | Should -Throw  -ErrorId 'PositionalParameterNotFound,Microsoft.PowerShell.Commands.SplitPathCommand'34    }35 36    It "Should return the path when the noqualifier switch is used" {37	Split-Path env:PATH -NoQualifier | Should -BeExactly "PATH"38    }39 40    It "Should return the base name when the leaf switch is used" {41	Split-Path -Leaf /usr/bin                  | Should -BeExactly "bin"42	Split-Path -Leaf fs:/usr/local/bin         | Should -BeExactly "bin"43	Split-Path -Leaf usr/bin                   | Should -BeExactly "bin"44	Split-Path -Leaf ./bin                     | Should -BeExactly "bin"45	Split-Path -Leaf bin                       | Should -BeExactly "bin"46	Split-Path -Leaf "C:\Temp\Folder1"         | Should -BeExactly "Folder1"47	Split-Path -Leaf "C:\Temp"                 | Should -BeExactly "Temp"48	Split-Path -Leaf "\\server1\share1\folder" | Should -BeExactly "folder"49	Split-Path -Leaf "\\server1\share1"        | Should -BeExactly "share1"50    }51 52    It "Should be able to accept regular expression input and output an array for multiple objects" {53        $testDir = $TestDrive54        $testFile1     = "testfile1.ps1"55        $testFile2     = "testfile2.ps1"56        $testFilePath1 = Join-Path -Path $testDir -ChildPath $testFile157        $testFilePath2 = Join-Path -Path $testDir -ChildPath $testFile258 59        New-Item -ItemType file -Path $testFilePath1, $testFilePath2 -Force60 61        Test-Path $testFilePath1 | Should -BeTrue62        Test-Path $testFilePath2 | Should -BeTrue63 64        $actual = ( Split-Path (Join-Path -Path $testDir -ChildPath "testfile*.ps1") -Leaf -Resolve ) | Sort-Object65        $actual.Count                   | Should -Be 266        $actual[0]                      | Should -BeExactly $testFile167        $actual[1]                      | Should -BeExactly $testFile268        ,$actual                        | Should -BeOfType System.Array69    }70 71    It "Should be able to tell if a given path is an absolute path" {72	Split-Path -IsAbsolute fs:/usr/bin | Should -BeTrue73	Split-Path -IsAbsolute ..          | Should -BeFalse74	Split-Path -IsAbsolute /usr/..     | Should -Be (!$IsWindows)75	Split-Path -IsAbsolute fs:/usr/../ | Should -BeTrue76	Split-Path -IsAbsolute ../         | Should -BeFalse77	Split-Path -IsAbsolute .           | Should -BeFalse78	Split-Path -IsAbsolute ~/          | Should -BeFalse79	Split-Path -IsAbsolute ~/..        | Should -BeFalse80	Split-Path -IsAbsolute ~/../..     | Should -BeFalse81    }82 83    It "Should support piping" {84        "usr/bin" | Split-Path | Should -Be "usr"85    }86 87    It "Should return the path up to the parent of the directory when Parent switch is used" {88        $dirSep = [string]([System.IO.Path]::DirectorySeparatorChar)89	Split-Path -Parent "fs:/usr/bin"             | Should -BeExactly "fs:${dirSep}usr"90	Split-Path -Parent "/usr/bin"                | Should -BeExactly "${dirSep}usr"91	Split-Path -Parent "/usr/local/bin"          | Should -BeExactly "${dirSep}usr${dirSep}local"92	Split-Path -Parent "usr/local/bin"           | Should -BeExactly "usr${dirSep}local"93	Split-Path -Parent "C:\Temp\Folder1"         | Should -BeExactly "C:${dirSep}Temp"94	Split-Path -Parent "C:\Temp"                 | Should -BeExactly "C:${dirSep}"95	Split-Path -Parent "\\server1\share1\folder" | Should -BeExactly "${dirSep}${dirSep}server1${dirSep}share1"96	Split-Path -Parent "\\server1\share1"        | Should -BeExactly "${dirSep}${dirSep}server1"97    }98 99    It 'Does not split a drive letter' {100        Split-Path -Path 'C:\' | Should -BeNullOrEmpty101    }102 103    It "Should handle explicit -Qualifier:`$false parameter value correctly" {104        # When -Qualifier:$false is specified, it should behave like -Parent (default)105        # For env:PATH, the parent is empty string106        $result = Split-Path -Path "env:PATH" -Qualifier:$false107        $result | Should -BeNullOrEmpty108    }109 110    It "Should handle explicit -NoQualifier:`$false parameter value correctly" {111        # When -NoQualifier:$false is specified, it should behave like -Parent (default)112        # For env:PATH with no qualifier, we expect empty string (parent of PATH in env drive)113        $result = Split-Path -Path "env:PATH" -NoQualifier:$false114        $result | Should -BeNullOrEmpty115    }116 117    It "Should handle explicit -Leaf:`$false parameter value correctly" {118        # When -Leaf:$false is specified, it should behave like -Parent (default)119        $dirSep = [string]([System.IO.Path]::DirectorySeparatorChar)120        Split-Path -Path "/usr/bin" -Leaf:$false | Should -BeExactly "${dirSep}usr"121    }122 123    It "Should handle explicit -IsAbsolute:`$false parameter value correctly" {124        # When -IsAbsolute:$false is specified, it should behave like -Parent (default)125        $dirSep = [string]([System.IO.Path]::DirectorySeparatorChar)126        Split-Path -Path "fs:/usr/bin" -IsAbsolute:$false | Should -BeExactly "fs:${dirSep}usr"127    }128}129