-
Notifications
You must be signed in to change notification settings - Fork 6
/
PSMatcher.psm1
98 lines (83 loc) · 2.63 KB
/
PSMatcher.psm1
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
# $PSVersion = $PSVersionTable.PSVersion.Major
# switch ($PSVersion) {
# 5 {$target = "classic"}
# 6 {$target = "dotnetcore"}
# }
# $null = [System.Reflection.Assembly]::LoadFrom("$PSScriptRoot\$target\NMatcher.dll")
# $null = [System.Reflection.Assembly]::LoadFrom("$PSScriptRoot\$target\Newtonsoft.Json.dll")
# $null = [System.Reflection.Assembly]::LoadFrom("$PSScriptRoot\$target\Sprache.dll")
$null = [System.Reflection.Assembly]::LoadFrom("$PSScriptRoot\lib\NMatcher.dll")
$null = [System.Reflection.Assembly]::LoadFrom("$PSScriptRoot\lib\Newtonsoft.Json.dll")
$null = [System.Reflection.Assembly]::LoadFrom("$PSScriptRoot\lib\Sprache.dll")
function New-BoolCompatibleResult {
[CmdletBinding()]
[OutputType([bool])]
param(
[Parameter(
Mandatory,
ValueFromPipeline
)]
[NMatcher.Matching.Result]
$Result
)
Process {
$Result.Successful |
Add-Member -MemberType ScriptProperty -Name Successful -Value { $this.Result.Successful } -Force -PassThru |
Add-Member -MemberType ScriptProperty -Name ErrorMessage -Value { $this.Result.ErrorMessage } -Force -PassThru |
Add-Member -NotePropertyName Result -NotePropertyValue $result -TypeName NMatcher.Matching.Result -Force -PassThru
}
}
function Test-Json {
[CmdletBinding()]
[OutputType([bool])]
param(
[Parameter(
Mandatory,
ValueFromPipeline
)]
[Alias('Actual')]
[ValidateNotNullOrEmpty()]
$Value ,
[Parameter(
Mandatory
)]
[Alias('Test')]
[ValidateNotNullOrEmpty()]
$Reference
)
Begin {
$matcher = New-Object -TypeName NMatcher.Matcher
}
Process {
$matcher.MatchJson($Value, $Reference) | New-BoolCompatibleResult
}
}
function Test-XML {
[CmdletBinding()]
[OutputType([bool])]
param(
[Parameter(
Mandatory,
ValueFromPipeline
)]
[Alias('Actual')]
[ValidateNotNullOrEmpty()]
$Value ,
[Parameter(
Mandatory
)]
[Alias('Test')]
[ValidateNotNullOrEmpty()]
$Reference
)
Begin {
$matcher = New-Object -TypeName NMatcher.Matcher
}
Process {
$matcher.MatchXML($Value, $Reference) | New-BoolCompatibleResult
}
}
. $PSScriptRoot\PesterMatchJsonTemplate.ps1
. $PSScriptRoot\PesterMatchXMLTemplate.ps1
#Export-ModuleMember -Function Test-Json, Test-XML, PesterMatchJsonTemplate
Export-ModuleMember -Function Test-Json, Test-XML, PesterMatchJsonTemplate, PesterMatchXMLTemplate