Use production directive extraction in import tests

This commit is contained in:
2026-10-25 22:19:38 +00:00
parent 3122e2f32d
commit 6f6130fd12
3 changed files with 12 additions and 24 deletions

View File

@@ -179,26 +179,6 @@ func boolOr(explicit, application *bool, fallback bool) bool {
return fallback
}
// parseImportSpecificationDirective validates every declaration before callers select candidates.
func parseImportSpecificationDirective(node *document.Node, directivePath Path) ([]importDeclarationSpec, []Diagnostic) {
if node.Kind != document.Mapping {
return nil, []Diagnostic{nodeImportDiagnostic(CodeImportInvalid, directivePath, "configuration directive must be a mapping", node)}
}
var specs []importDeclarationSpec
var diagnostics []Diagnostic
for _, entry := range node.Mapping {
fieldPath := directivePath.Key(entry.Key)
if entry.Key != "imports" {
diagnostics = append(diagnostics, nodeImportDiagnostic(CodeImportInvalid, fieldPath, "configuration directive field is not recognized", entry.Value))
continue
}
parsed, issues := parseImportDeclarations(entry.Value, fieldPath)
specs = append(specs, parsed...)
diagnostics = append(diagnostics, issues...)
}
return specs, canonicalDiagnostics(diagnostics)
}
func parseImportDeclarations(node *document.Node, declarationPath Path) ([]importDeclarationSpec, []Diagnostic) {
if node == nil || node.Kind != document.Sequence {
return nil, []Diagnostic{nodeImportDiagnostic(CodeImportInvalid, declarationPath, "imports must be a sequence", node)}

View File

@@ -224,11 +224,11 @@ func parseImportSpecsYAML(t *testing.T, declarations string) ([]importDeclaratio
if len(diagnostics) != 0 {
return nil, diagnostics
}
index := documentEntryIndex(parsed.document.Mapping, directiveKey)
if index < 0 {
t.Fatal("missing root directive in test fixture")
extracted, diagnostics := extractRootDirectives(parsed.document, rootDirectiveContextSource)
if len(diagnostics) != 0 {
return nil, diagnostics
}
return parseImportSpecificationDirective(parsed.document.Mapping[index].Value, Keys(directiveKey))
return extracted.imports, nil
}
type countingImportSpecReader struct {