-
Notifications
You must be signed in to change notification settings - Fork 4
/
Find-String.Tests.ps1
64 lines (50 loc) · 2.29 KB
/
Find-String.Tests.ps1
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
BeforeAll {
Import-Module $PSScriptRoot/Find-String
}
Describe "Find-String" {
Context "Write-Host Out-ColorMatchInfo" {
It "MatchInfo Context and Colors" {
InModuleScope Find-String {
Mock Write-Host { }
Get-ChildItem -Path TestData | select-string test | Out-ColorMatchInfo
Should -Invoke Write-Host -ParameterFilter {
$object -match "test.log" -and $ForegroundColor -eq "Green"
}
Should -Invoke Write-Host -ParameterFilter {
$object -eq "2:" -and $noNewLine
}
Should -Invoke Write-Host -ParameterFilter {
$object -eq "this is a " -and $noNewLine
}
Should -Invoke Write-Host -Times 2 -ParameterFilter {
$object -eq "test" -and $ForegroundColor -eq "Black" -and $backgroundColor -eq "Yellow" -and $noNewLine
}
Should -Invoke Write-Host -ParameterFilter {
$object -eq "--"
}
Should -Invoke Write-Host -ParameterFilter {
$object -eq "3:" -and $noNewLine
}
Should -Invoke Write-Host -ParameterFilter {
$object -eq "this is another "
}
}
}
It "Shouldn't Call Write-Host if PipeOutput is Used" {
$results = Get-ChildItem -Path TestData | select-string test | Out-ColorMatchInfo -pipeOutput
$results.Length | Should -Be 2
$matchInfoResult = $results[0] -split '\r?\n'
$textOutput = $results[1] -split '\r?\n'
$matchInfoResult[0] | Should -Be ""
$matchInfoResult[1] | Should -Match "test.log"
$matchInfoResult[2] | Should -Match "2:this is a test"
$matchInfoResult[3] | Should -Be ""
$textOutput[0] | Should -Be ""
$textOutput[1] | Should -Match "test.log"
$textOutput[2] | Should -Be "2:this is a test"
$textOutput[3] | Should -Be "--"
$textOutput[4] | Should -Be "3:this is another test"
$textOutput[5] | Should -Be ""
}
}
}