diff --git a/tests/EncDotNet.UnitTests/AmlDataSetCorpusTests.cs b/tests/EncDotNet.UnitTests/AmlDataSetCorpusTests.cs index 3c52b5b..4566762 100644 --- a/tests/EncDotNet.UnitTests/AmlDataSetCorpusTests.cs +++ b/tests/EncDotNet.UnitTests/AmlDataSetCorpusTests.cs @@ -27,7 +27,7 @@ public void RealCells_AreAmlAndEveryCodeResolvesInTheirCatalogue() int cells = 0, features = 0, values = 0; var paths = Directory.EnumerateFiles(root, "*.*", SearchOption.AllDirectories) - .Where(p => CellExtension().IsMatch(Path.GetExtension(p))) + .Where(p => CellExtension().IsMatch(Path.GetExtension(p)) && !IsExchangeSetCatalogue(p)) .Order(StringComparer.Ordinal); foreach (var path in paths) @@ -53,8 +53,11 @@ public void RealCells_AreAmlAndEveryCodeResolvesInTheirCatalogue() failures.Add($"{cell}: product {dataSet.Product.Kind} has no AML product"); } + // COMT is free text in S-57. The published AML cells write AML metadata there as + // key=value pairs, but copies re-encoded by other tools can carry a plain comment, + // which isn't metadata. Only a comment written as pairs must parse. var comment = dataSet.Identification.Comment; - if (!string.IsNullOrWhiteSpace(comment) && dataSet.Metadata is null) + if (comment is not null && comment.Contains('=', StringComparison.Ordinal) && dataSet.Metadata is null) { failures.Add($"{cell}: COMT isn't AML metadata: \"{comment}\""); } @@ -113,6 +116,13 @@ private static int Count(IReadOnlyList attributes, S57ObjectC return attributes.Count; } + /// + /// Gets whether a file is an exchange set catalogue (CATALOG.031), which has a cell-like + /// extension but isn't a cell. + /// + private static bool IsExchangeSetCatalogue(string path) => + Path.GetFileNameWithoutExtension(path).Equals("CATALOG", StringComparison.OrdinalIgnoreCase); + /// Matches the extension of a base cell (.000) or an update cell (.001 and up). [GeneratedRegex(@"^\.\d{3}$")] private static partial Regex CellExtension();