Skip to content

Commit 2d388d0

Browse files
Separate YAML conformance semantics
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 6a9d2c5 commit 2d388d0

2 files changed

Lines changed: 239 additions & 93 deletions

File tree

tests/Conformance.Tests.ps1

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,32 @@ Describe 'Released yaml-test-suite corpus accounting' {
168168
$secondOrder.Add('b', 2)
169169
$secondOrder.Add('a', 1)
170170
(ConvertTo-YamlSuiteCanonicalValue -Value $firstOrder) |
171-
Should -Not -Be (ConvertTo-YamlSuiteCanonicalValue -Value $secondOrder)
171+
Should -Be (ConvertTo-YamlSuiteCanonicalValue -Value $secondOrder)
172+
173+
$orderedMappings = [System.Collections.Generic.HashSet[object]]::new(
174+
[System.Collections.Generic.ReferenceEqualityComparer]::Instance
175+
)
176+
[void] $orderedMappings.Add($firstOrder)
177+
[void] $orderedMappings.Add($secondOrder)
178+
(ConvertTo-YamlSuiteCanonicalValue -Value $firstOrder `
179+
-OrderedMappings $orderedMappings) |
180+
Should -Not -Be (
181+
ConvertTo-YamlSuiteCanonicalValue -Value $secondOrder `
182+
-OrderedMappings $orderedMappings
183+
)
184+
185+
$firstNestedKey = [System.Collections.Specialized.OrderedDictionary]::new()
186+
$secondNestedKey = [System.Collections.Specialized.OrderedDictionary]::new()
187+
$firstNestedKey.Add($firstOrder, 'value')
188+
$secondNestedKey.Add($secondOrder, 'value')
189+
(ConvertTo-YamlSuiteCanonicalValue -Value $firstNestedKey) |
190+
Should -Be (ConvertTo-YamlSuiteCanonicalValue -Value $secondNestedKey)
191+
(ConvertTo-YamlSuiteCanonicalValue -Value $firstNestedKey `
192+
-OrderedMappings $orderedMappings) |
193+
Should -Not -Be (
194+
ConvertTo-YamlSuiteCanonicalValue -Value $secondNestedKey `
195+
-OrderedMappings $orderedMappings
196+
)
172197

173198
(ConvertTo-YamlSuiteCanonicalValue -Value ([uri] 'https://example.com/one')) |
174199
Should -Not -Be (
@@ -233,6 +258,20 @@ ship-to:
233258
Should -Be @('OutYamlConstructionMismatch', 'OutYamlReferenceMismatch')
234259
}
235260

261+
It 'ignores source order for ordinary mapping out.yaml comparisons' {
262+
$ordinarySuitePath = Join-Path $TestDrive 'ordinary-mapping-order'
263+
$ordinaryCasePath = Join-Path $ordinarySuitePath 'ordinary-map'
264+
$null = New-Item -Path $ordinaryCasePath -ItemType Directory -Force
265+
"a: 1`nb: 2" | Set-Content -LiteralPath (Join-Path $ordinaryCasePath 'in.yaml') `
266+
-Encoding utf8NoBOM
267+
"b: 2`na: 1" | Set-Content -LiteralPath (Join-Path $ordinaryCasePath 'out.yaml') `
268+
-Encoding utf8NoBOM
269+
270+
$ordinaryResult = & $runnerPath -Path $ordinarySuitePath -CompareOutYaml
271+
272+
$ordinaryResult.OutYamlResult | Should -Be 'Pass'
273+
}
274+
236275
It 'accounts for out.yaml representation comparisons' {
237276
@($suiteResults | Where-Object OutYamlResult -EQ 'Pass').Count | Should -Be 241
238277
@($suiteResults | Where-Object OutYamlResult -EQ 'PolicyDifference').Count |
@@ -295,11 +334,27 @@ ship-to:
295334
Should -Be @('EmitYamlRepresentationMismatch')
296335
}
297336

337+
It 'does not run module emission while validating official fixtures' {
338+
$independentSuitePath = Join-Path $TestDrive 'independent-emit-fixture'
339+
$independentCasePath = Join-Path $independentSuitePath 'deep-fixture'
340+
$null = New-Item -Path $independentCasePath -ItemType Directory -Force
341+
$deepYaml = ('[' * 101) + 'value' + (']' * 101)
342+
$deepYaml | Set-Content -LiteralPath (Join-Path $independentCasePath 'in.yaml') `
343+
-Encoding utf8NoBOM -NoNewline
344+
$deepYaml | Set-Content -LiteralPath (Join-Path $independentCasePath 'emit.yaml') `
345+
-Encoding utf8NoBOM -NoNewline
346+
347+
$independentResult = & $runnerPath -Path $independentSuitePath -CompareEmitYaml
348+
349+
$independentResult.EmitYamlResult | Should -Be 'Pass'
350+
$independentResult.SelfRoundTripResult | Should -Be 'NotApplicable'
351+
}
352+
298353
It 'accounts honestly for general module self-round-trips' {
299354
@($suiteResults | Where-Object SelfRoundTripResult -EQ 'Pass').Count |
300-
Should -Be 306
355+
Should -Be 305
301356
@($suiteResults | Where-Object SelfRoundTripResult -EQ 'PolicyDifference').Count |
302-
Should -Be 2
357+
Should -Be 3
303358
@($suiteResults | Where-Object SelfRoundTripResult -EQ 'Fail').Count |
304359
Should -Be 0
305360
@($suiteResults | Where-Object SelfRoundTripResult -EQ 'NotApplicable').Count |
@@ -309,9 +364,12 @@ ship-to:
309364
Where-Object SelfRoundTripResult -EQ 'PolicyDifference' |
310365
Sort-Object Case
311366
)
312-
@($policyResults.Case) | Should -Be @('2JQS', 'X38W')
313-
@($policyResults.SelfRoundTripReason | Select-Object -Unique) |
314-
Should -Be @('RepresentationMappingKeyUniqueness')
367+
@($policyResults.Case) | Should -Be @('2JQS', 'J7PZ', 'X38W')
368+
@($policyResults.SelfRoundTripReason) | Should -Be @(
369+
'RepresentationMappingKeyUniqueness',
370+
'LegacyOrderedMapProjection',
371+
'RepresentationMappingKeyUniqueness'
372+
)
315373
}
316374

317375
It 'keeps the previously failing multi-document JSON cases green' {

0 commit comments

Comments
 (0)