Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions tests/EncDotNet.UnitTests/AmlDataSetCorpusTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}\"");
}
Expand Down Expand Up @@ -113,6 +116,13 @@ private static int Count(IReadOnlyList<S57AttributeValue> attributes, S57ObjectC
return attributes.Count;
}

/// <summary>
/// Gets whether a file is an exchange set catalogue (<c>CATALOG.031</c>), which has a cell-like
/// extension but isn't a cell.
/// </summary>
private static bool IsExchangeSetCatalogue(string path) =>
Path.GetFileNameWithoutExtension(path).Equals("CATALOG", StringComparison.OrdinalIgnoreCase);

/// <summary>Matches the extension of a base cell (<c>.000</c>) or an update cell (<c>.001</c> and up).</summary>
[GeneratedRegex(@"^\.\d{3}$")]
private static partial Regex CellExtension();
Expand Down
Loading