File size: 1,350 Bytes
8c763fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

Describe 'Native Windows tilde expansion tests' -tags "CI" {
    BeforeAll {
        $originalDefaultParams = $PSDefaultParameterValues.Clone()
        $PSDefaultParameterValues["it:skip"] = -Not $IsWindows
    }

    AfterAll {
        $global:PSDefaultParameterValues = $originalDefaultParams
    }

    # Test ~ expansion
    It 'Tilde should be replaced by the filesystem provider home directory' {
        cmd /c echo ~ | Should -BeExactly ($ExecutionContext.SessionState.Provider.Get("FileSystem").Home)
    }
    # Test ~ expansion with a path fragment (e.g. ~/foo)
    It '~/foo should be replaced by the <filesystem provider home directory>/foo' {
        cmd /c echo ~/foo | Should -BeExactly "$($ExecutionContext.SessionState.Provider.Get("FileSystem").Home)/foo"
        cmd /c echo ~\foo | Should -BeExactly "$($ExecutionContext.SessionState.Provider.Get("FileSystem").Home)\foo"
    }

    It '~ should not be replaced when quoted' {
        cmd /c echo '~' | Should -BeExactly '~'
        cmd /c echo "~" | Should -BeExactly '~'
        cmd /c echo '~/foo' | Should -BeExactly '~/foo'
        cmd /c echo "~/foo" | Should -BeExactly '~/foo'
        cmd /c echo '~\foo' | Should -BeExactly '~\foo'
        cmd /c echo "~\foo" | Should -BeExactly '~\foo'
    }
}