test: cover p-rec-annot line-number list planning

This commit is contained in:
codex
2026-08-07 08:42:34 +03:00
parent 431366c27c
commit 315d36a36a
2 changed files with 44 additions and 0 deletions
@@ -0,0 +1,19 @@
using System.Security.Cryptography;
using System.Text;
using PRecAnnot.Abstractions;
namespace PRecAnnot.Core;
public static class LineNumberListPlanner
{
public static LineNumberListApplyPreflight Build(AnnotationPoint position, double rotation, IEnumerable<LineNumberApplyPreflight> rows)
{
var ordered = rows.OrderBy(row => row.MarkerNumber).ToArray();
if (ordered.Length == 0) throw new ArgumentException("LINE_NUMBER_LIST_EMPTY", nameof(rows));
if (ordered.Any(row => string.IsNullOrWhiteSpace(row.StableId) || string.IsNullOrWhiteSpace(row.Text))) throw new ArgumentException("LINE_NUMBER_LIST_ROW_INVALID", nameof(rows));
if (ordered.Select(row => row.MarkerNumber).Distinct().Count() != ordered.Length) throw new ArgumentException("LINE_NUMBER_LIST_DUPLICATE_MARKER_NUMBER", nameof(rows));
var key = string.Join("|", ordered.Select(row => $"{row.MarkerNumber}:{row.StableId}"));
var digest = Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(key))).ToLowerInvariant();
return new($"ln-list:{digest}", position, rotation, ordered);
}
}