Skip to content

Commit 0474672

Browse files
Distinguish non-specific tags in corpus events
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 5a89b99 commit 0474672

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

tests/Conformance.Tests.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,27 @@ Describe 'Released yaml-test-suite corpus accounting' {
228228
Should -Not -Be (ConvertTo-YamlSuiteReferenceSignature -Value $distinctKeyGraph)
229229
}
230230

231+
It 'distinguishes non-specific tags in canonical representation events' {
232+
$plain = Invoke-InYamlModule -ScriptBlock $readYamlSuiteRepresentation `
233+
-Arguments @('"value"')
234+
$nonSpecific = Invoke-InYamlModule -ScriptBlock $readYamlSuiteRepresentation `
235+
-Arguments @('! value')
236+
$plainEvents = ConvertTo-YamlSuiteActualEvent -Documents $plain.Value
237+
$nonSpecificEvents = ConvertTo-YamlSuiteActualEvent -Documents $nonSpecific.Value
238+
$oracleEvents = ConvertFrom-YamlSuiteEventText -Text @'
239+
+STR
240+
+DOC
241+
=VAL <!> :value
242+
-DOC
243+
-STR
244+
'@
245+
246+
(Compare-YamlSuiteCanonicalList -Left $plainEvents -Right $nonSpecificEvents) |
247+
Should -BeFalse
248+
$nonSpecificEvents | Should -Be $oracleEvents
249+
$nonSpecificEvents | Should -Contain '=VAL|nonSpecificTag=true|value=value'
250+
}
251+
231252
It 'detects altered ordered-map and alias semantics in out.yaml' {
232253
$mutatedSuitePath = Join-Path $TestDrive 'mutated-out-cases'
233254
$null = New-Item -Path $mutatedSuitePath -ItemType Directory -Force

tests/tools/Invoke-YamlTestSuite.ps1

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,11 @@ function ConvertFrom-YamlSuiteEventText {
602602
}
603603
$parts = [System.Collections.Generic.List[string]]::new()
604604
$parts.Add($prefix)
605-
if ($tag -and $tag -ne '!') { $parts.Add("tag=$tag") }
605+
if ($tag -eq '!') {
606+
$parts.Add('nonSpecificTag=true')
607+
} elseif ($tag) {
608+
$parts.Add("tag=$tag")
609+
}
606610
if ($anchorToken) { $parts.Add("anchor=$anchorToken") }
607611
if ($prefix -eq '=VAL') { $parts.Add("value=$value") }
608612
$canonical.Add(($parts -join '|'))
@@ -684,7 +688,11 @@ function ConvertTo-YamlSuiteActualEvent {
684688
if ($node.Kind -eq 'Scalar') {
685689
$parts = [System.Collections.Generic.List[string]]::new()
686690
$parts.Add('=VAL')
687-
if ($node.Tag -and $node.Tag -ne '!') { $parts.Add("tag=$($node.Tag)") }
691+
if ([string]::IsNullOrEmpty($node.Tag) -and $node.HasUnknownTag) {
692+
$parts.Add('nonSpecificTag=true')
693+
} elseif ($node.Tag) {
694+
$parts.Add("tag=$($node.Tag)")
695+
}
688696
if ($node.Anchor) {
689697
$parts.Add("anchor=$(
690698
Get-YamlSuiteAnchorToken -Key ('id:{0}' -f $node.Id) -AnchorMap $anchorMap `
@@ -701,7 +709,11 @@ function ConvertTo-YamlSuiteActualEvent {
701709
$startParts = [System.Collections.Generic.List[string]]::new()
702710
$startToken = if ($node.Kind -eq 'Sequence') { '+SEQ' } else { '+MAP' }
703711
$startParts.Add($startToken)
704-
if ($node.Tag -and $node.Tag -ne '!') { $startParts.Add("tag=$($node.Tag)") }
712+
if ([string]::IsNullOrEmpty($node.Tag) -and $node.HasUnknownTag) {
713+
$startParts.Add('nonSpecificTag=true')
714+
} elseif ($node.Tag) {
715+
$startParts.Add("tag=$($node.Tag)")
716+
}
705717
if ($node.Anchor) {
706718
$startParts.Add("anchor=$(
707719
Get-YamlSuiteAnchorToken -Key ('id:{0}' -f $node.Id) -AnchorMap $anchorMap `

0 commit comments

Comments
 (0)