@@ -242,18 +242,123 @@ function ConvertTo-YamlSuiteReferenceSignature {
242242 return ($output -join ' ;' )
243243}
244244
245+ function Test-YamlSuiteBinaryByteArrayProjection {
246+ [OutputType ([bool ])]
247+ param (
248+ [Parameter (Mandatory )]
249+ [object []] $ExpectedValues ,
250+
251+ [Parameter (Mandatory )]
252+ [object []] $ActualValues
253+ )
254+
255+ if ($ExpectedValues.Count -ne 1 -or $ActualValues.Count -ne 1 ) {
256+ return $false
257+ }
258+ $expectedDocument = $ExpectedValues [0 ]
259+ $actualDocument = $ActualValues [0 ]
260+ if ($expectedDocument -isnot [System.Collections.IDictionary ] -or
261+ $actualDocument -isnot [System.Collections.IDictionary ] -or
262+ $expectedDocument.Count -ne 3 -or $actualDocument.Count -ne 3 ) {
263+ return $false
264+ }
265+
266+ foreach ($key in @ (' canonical' , ' generic' , ' description' )) {
267+ if (-not $expectedDocument.Contains ($key ) -or -not $actualDocument.Contains ($key )) {
268+ return $false
269+ }
270+ }
271+ if ($expectedDocument [' description' ] -isnot [string ] -or
272+ $actualDocument [' description' ] -isnot [string ] -or
273+ $actualDocument [' description' ] -cne $expectedDocument [' description' ]) {
274+ return $false
275+ }
276+
277+ foreach ($key in @ (' canonical' , ' generic' )) {
278+ if ($expectedDocument [$key ] -isnot [string ] -or
279+ $actualDocument [$key ] -isnot [byte []]) {
280+ return $false
281+ }
282+ $expectedBase64 = $expectedDocument [$key ] -replace ' \s' , ' '
283+ $expectedBytes = [System.Convert ]::FromBase64String($expectedBase64 )
284+ if (-not [System.Linq.Enumerable ]::SequenceEqual[byte ](
285+ $expectedBytes ,
286+ [byte []] $actualDocument [$key ]
287+ )) {
288+ return $false
289+ }
290+ }
291+ return $true
292+ }
293+
294+ function Test-YamlSuiteLegacyOrderedMapProjection {
295+ [OutputType ([bool ])]
296+ param (
297+ [Parameter (Mandatory )]
298+ [object []] $ExpectedValues ,
299+
300+ [Parameter (Mandatory )]
301+ [object []] $ActualValues
302+ )
303+
304+ if ($ExpectedValues.Count -ne 1 -or $ActualValues.Count -ne 1 -or
305+ $ExpectedValues [0 ] -is [System.Collections.IDictionary ] -or
306+ $ExpectedValues [0 ] -isnot [System.Collections.IEnumerable ] -or
307+ $ActualValues [0 ] -isnot [System.Collections.Specialized.OrderedDictionary ]) {
308+ return $false
309+ }
310+
311+ $expectedEntries = @ ($ExpectedValues [0 ])
312+ $actualDocument = $ActualValues [0 ]
313+ $actualKeys = @ ($actualDocument.Keys )
314+ if ($expectedEntries.Count -ne $actualDocument.Count ) {
315+ return $false
316+ }
317+ for ($index = 0 ; $index -lt $expectedEntries.Count ; $index ++ ) {
318+ $expectedEntry = $expectedEntries [$index ]
319+ if ($expectedEntry -isnot [System.Collections.IDictionary ] -or
320+ $expectedEntry.Count -ne 1 ) {
321+ return $false
322+ }
323+ $expectedKey = @ ($expectedEntry.Keys )[0 ]
324+ if ($expectedKey -isnot [string ] -or $actualKeys [$index ] -cne $expectedKey -or
325+ (ConvertTo-YamlSuiteCanonicalValue - Value $actualDocument [$expectedKey ]) -cne
326+ (ConvertTo-YamlSuiteCanonicalValue - Value $expectedEntry [$expectedKey ])) {
327+ return $false
328+ }
329+ }
330+ return $true
331+ }
332+
245333function Get-YamlSuiteJsonPolicyReason {
246334 [OutputType ([string ])]
247335 param (
248336 [Parameter (Mandatory )]
249- [string ] $Case
337+ [string ] $Case ,
338+
339+ [Parameter (Mandatory )]
340+ [object []] $ExpectedValues ,
341+
342+ [Parameter (Mandatory )]
343+ [object []] $ActualValues
250344 )
251345
252346 switch - CaseSensitive ($Case ) {
253- ' 565N' { return ' BinaryByteArrayProjection' }
254- ' J7PZ' { return ' LegacyOrderedMapProjection' }
347+ ' 565N' {
348+ if (Test-YamlSuiteBinaryByteArrayProjection - ExpectedValues $ExpectedValues `
349+ - ActualValues $ActualValues ) {
350+ return ' BinaryByteArrayProjection'
351+ }
352+ }
353+ ' J7PZ' {
354+ if (Test-YamlSuiteLegacyOrderedMapProjection - ExpectedValues $ExpectedValues `
355+ - ActualValues $ActualValues ) {
356+ return ' LegacyOrderedMapProjection'
357+ }
358+ }
255359 default { return ' ' }
256360 }
361+ return ' '
257362}
258363
259364function ConvertFrom-YamlSuiteEventText {
@@ -746,7 +851,9 @@ foreach ($inputFile in $inputFiles) {
746851 if ($projectedCanonical -ceq $expectedCanonical ) {
747852 $jsonResult = ' Pass'
748853 } else {
749- $reason = Get-YamlSuiteJsonPolicyReason - Case $casePath
854+ $reason = Get-YamlSuiteJsonPolicyReason - Case $casePath `
855+ - ExpectedValues ([object []] $expectedValues.ToArray ()) `
856+ - ActualValues ([object []] $projectedValues )
750857 if ($reason ) {
751858 $jsonResult = ' PolicyDifference'
752859 $jsonReason = $reason
0 commit comments