Functions/Assertions/BeLikeExactly.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
function PesterBeLikeExactly($ActualValue, $ExpectedValue, [switch] $Negate, [String] $Because)
{
    [bool] $succeeded = $ActualValue -clike $ExpectedValue
    if ($Negate) { $succeeded = -not $succeeded }

    if (-not $succeeded)
    {
        if ($Negate)
        {
            return New-Object psobject -Property @{
                Succeeded      = $false
                FailureMessage = "Expected case sensitive like wildcard {$ExpectedValue} to not match {$ActualValue},$(Format-Because $Because) but it did match."
            }
        }
        else
        {
            return New-Object psobject -Property @{
                Succeeded      = $false
                FailureMessage = "Expected case sensitive like wildcard {$ExpectedValue} to match {$ActualValue},$(Format-Because $Because) but it did not match."
            }
        }
    }

    return New-Object psobject -Property @{
        Succeeded      = $true
    }
}

Add-AssertionOperator -Name BeLikeExactly `
                      -Test  $function:PesterBeLikeExactly

function PesterBeLikeExactlyFailureMessage() { }
function NotPesterBeLikeExactlyFailureMessage() { }