File size: 4,229 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
Describe 'Line endings' -Tags "CI" {
    BeforeAll {
        $lf = "`n"
        $cr = "`r"
        $crlf="`r`n"
        $dq = "`""
        $sq = "'"
        $hereDB = "@`""
        $hereDE = "`"@"
        $hereSB = "@'"
        $hereSE = "'@"
        }

    $testData = @(
        @{
            Name = 'CR in single quotes here-string';
            NewLine = $cr
            Begin = $hereSB+$cr;
            End = $cr + $hereSE
        },
        @{
            Name = 'LF in single quotes here-string';
            NewLine = $lf
            Begin = $hereSB+$lf;
            End = $lf + $hereSE
        },
        @{
            Name = 'CRLF in single quotes here-string';
            NewLine = $cr+$lf
            Begin = $hereSB+$cr+$lf;
            End = $cr+$lf + $hereSE
        },
        @{
            Name = 'CR in double quotes here string';
            Begin = $hereDB + $cr;
            NewLine = $cr
            End = $cr + $hereDE
        },
        @{
            Name = 'LF in double quotes here string';
            Begin = $hereDB + $lf;
            NewLine = $lf
            End = $lf + $hereDE
        },
        @{
            Name = 'CRLF in double quotes here string';
            Begin = $hereDB + $cr + $lf;
            NewLine = $cr + $lf
            End = $cr + $lf + $hereDE
        },
        @{
            Name = 'CR in double quotes here string';
            Begin = $hereDB + $cr;
            NewLine = $cr
            End = $cr + $hereDE
        },
        @{
            Name = 'Lf in double quotes here string';
            Begin = $hereDB + $lf;
            NewLine = $lf
            End = $lf + $hereDE
        },
        @{
            Name = 'CRLF in double quotes here string';
            Begin = $hereDB + $cr + $lf;
            NewLine = $cr + $lf
            End = $cr + $lf + $hereDE
        },
        @{
            Name = 'CR in single quotes string';
            Begin = $sq;
            NewLine = $cr
            End =  $sq
        },
        @{
            Name = 'LF in single quotes string';
            Begin = $sq;
            NewLine = $lf
            End =  $sq
        },
        @{
            Name = 'CRLF in single quotes string';
            Begin = $sq;
            NewLine = $cr + $lf
            End =  $sq
        },
        @{
            Name = 'CR in double quotes string';
            Begin = $dq;
            NewLine = $cr
            End =  $dq
        },
        @{
            Name = 'LF in double quotes string';
            Begin = $dq;
            NewLine = $lf
            End =  $dq
        },
        @{
            Name = 'CRLF in double quotes string';
            Begin = $dq;
            NewLine = $cr + $lf
            End =  $dq
        }
    )

    It '<Name> in expression' -TestCases:$testData {
        param([string]$Name, $Begin, $End, $NewLine)
        # build the content string
        $expected = "This$($newline)is$($newline)a$($newline)multi$($newline)line$($newline)string"

        # wrap the content in the specified begin and end quoting characters.
        $content = "$($Begin)$($expected)$($End)"
        $actual = Invoke-Expression $content

        # $actual should be the content string ($expected) without the begin and end quoting characters.
        $actual | Should -BeExactly $expected
    }

    It '<Name> in ps file' -TestCases:$testData {
        param([string]$Name, $Begin, $End)

        $fileName = $Name.Replace(' ', '') + '.ps1'

        # build the content string
        $expected = "This$($newline)is$($newline)a$($newline)multi$($newline)line$($newline)string"

        # wrap the content in the specified begin and end quoting characters.
        $content = "$($Begin)$($expected)$($End)"
        # BUG: Set-Content is failing on linux if the file does not exit.
        $null = New-Item -Path TESTDRIVE:$fileName -Force
        $content | Set-Content -NoNewline -Encoding ascii -Path TESTDRIVE:\$fileName
        $actual = &( "TESTDRIVE:\$fileName")

        # $actual should be the content string ($expected) without the begin and end quoting characters.
        $actual | Should -BeExactly $expected
    }
}

$test = @"
"@