Skip to content

Commit 0c2fcc1

Browse files
Distinguish ordered maps in conformance
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 995a6b9 commit 0c2fcc1

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

tests/Conformance.Tests.ps1

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ Describe 'Released yaml-test-suite corpus accounting' {
167167
$firstOrder.Add('b', 2)
168168
$secondOrder.Add('b', 2)
169169
$secondOrder.Add('a', 1)
170+
$ordinarySameOrder = [System.Collections.Specialized.OrderedDictionary]::new()
171+
$ordinarySameOrder.Add('a', 1)
172+
$ordinarySameOrder.Add('b', 2)
170173
(ConvertTo-YamlSuiteCanonicalValue -Value $firstOrder) |
171174
Should -Be (ConvertTo-YamlSuiteCanonicalValue -Value $secondOrder)
172175

@@ -181,6 +184,12 @@ Describe 'Released yaml-test-suite corpus accounting' {
181184
ConvertTo-YamlSuiteCanonicalValue -Value $secondOrder `
182185
-OrderedMappings $orderedMappings
183186
)
187+
(ConvertTo-YamlSuiteCanonicalValue -Value $firstOrder `
188+
-OrderedMappings $orderedMappings) |
189+
Should -Not -Be (
190+
ConvertTo-YamlSuiteCanonicalValue -Value $ordinarySameOrder `
191+
-OrderedMappings $orderedMappings
192+
)
184193

185194
$firstNestedKey = [System.Collections.Specialized.OrderedDictionary]::new()
186195
$secondNestedKey = [System.Collections.Specialized.OrderedDictionary]::new()
@@ -272,6 +281,30 @@ ship-to:
272281
$ordinaryResult.OutYamlResult | Should -Be 'Pass'
273282
}
274283

284+
It 'detects explicit ordered-map tag loss across representation surfaces' {
285+
$tagLossSuitePath = Join-Path $TestDrive 'ordered-map-tag-loss'
286+
$tagLossCasePath = Join-Path $tagLossSuitePath 'omap-tag-loss'
287+
$null = New-Item -Path $tagLossCasePath -ItemType Directory -Force
288+
"!!omap`n- a: 1`n- b: 2" |
289+
Set-Content -LiteralPath (Join-Path $tagLossCasePath 'in.yaml') `
290+
-Encoding utf8NoBOM
291+
foreach ($fixture in @('out.yaml', 'emit.yaml')) {
292+
"a: 1`nb: 2" |
293+
Set-Content -LiteralPath (Join-Path $tagLossCasePath $fixture) `
294+
-Encoding utf8NoBOM
295+
}
296+
297+
$tagLossResult = & $runnerPath -Path $tagLossSuitePath `
298+
-CompareOutYaml -CompareEmitYaml -CompareSelfRoundTrip
299+
300+
$tagLossResult.OutYamlResult | Should -Be 'Fail'
301+
$tagLossResult.OutYamlReason | Should -Be 'OutYamlConstructionMismatch'
302+
$tagLossResult.EmitYamlResult | Should -Be 'Fail'
303+
$tagLossResult.EmitYamlReason | Should -Be 'EmitYamlRepresentationMismatch'
304+
$tagLossResult.SelfRoundTripResult | Should -Be 'PolicyDifference'
305+
$tagLossResult.SelfRoundTripReason | Should -Be 'LegacyOrderedMapProjection'
306+
}
307+
275308
It 'accounts for out.yaml representation comparisons' {
276309
@($suiteResults | Where-Object OutYamlResult -EQ 'Pass').Count | Should -Be 241
277310
@($suiteResults | Where-Object OutYamlResult -EQ 'PolicyDifference').Count |

tests/tools/Invoke-YamlTestSuite.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ function ConvertTo-YamlSuiteCanonicalValue {
199199
if ($SortMappings -or -not $isOrdered) {
200200
$entries.Sort([System.StringComparer]::Ordinal)
201201
}
202-
return 'map:{0}:{{{1}}}' -f $entries.Count, ($entries -join '|')
202+
$mappingKind = if ($isOrdered) { 'omap' } else { 'map' }
203+
return '{0}:{1}:{{{2}}}' -f $mappingKind, $entries.Count, ($entries -join '|')
203204
}
204205
if ($Value -is [System.Collections.IEnumerable] -and $Value -isnot [string]) {
205206
$items = [System.Collections.Generic.List[string]]::new()

0 commit comments

Comments
 (0)