Snapshot for release 2026.10.19.1 (internal fa7a8f6)
This commit is contained in:
parent
605ec6f0e6
commit
44074df011
110 changed files with 8017 additions and 291 deletions
|
|
@ -22,6 +22,9 @@ internal static class Program
|
|||
One("Your location is: 0xA9B40019 [84.000 7.100 42.005] 0.0 0.0 0.0 1.0 = 42.1N, 33.6E", 42.1, 33.6, "42.1N, 33.6E");
|
||||
One("drudges at 42N 33E", 42, 33, "42.0N, 33.0E");
|
||||
One("0.0N, 101.9W", 0, -101.9, "0.0N, 101.9W");
|
||||
// Pasted the way players often type them (lowercase, no space): RynthChat makes these links.
|
||||
One("82.3n,34.2e", 82.3, 34.2, "82.3N, 34.2E");
|
||||
One("Bob says, \"meet at 82.3n, 34.2e\"", 82.3, 34.2, "82.3N, 34.2E");
|
||||
|
||||
// Two in one line, in order.
|
||||
var two = ChatCoords.Find("from 42.1N, 33.6E to 21.5S, 1.8W");
|
||||
|
|
@ -42,10 +45,103 @@ internal static class Program
|
|||
None("");
|
||||
None(null);
|
||||
|
||||
PreCheck();
|
||||
LinkSpans();
|
||||
|
||||
Console.WriteLine(_failed == 0 && _checks > 0 ? $"PASS ({_checks} checks)" : $"FAIL ({_failed} of {_checks})");
|
||||
return _failed == 0 && _checks > 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
/// <summary>The cheap pre-check ChatFace runs before the regex must never skip a line Find would link.</summary>
|
||||
private static void PreCheck()
|
||||
{
|
||||
foreach (string t in new[] { "42.1N, 33.6E", "42N 33E", "33.6E 42.1N", "at 42.1 N, 33.6 E now", "82.3n,34.2e", "0.5S, 101.2W", "x1 n 2e" })
|
||||
Check(ChatCoords.MayHaveCoords(t), $"pre-check lets \"{t}\" through");
|
||||
foreach (string t in new[] { "", "hello world", "no digits here N E", "N5", "12 N (two spaces)", "forty two north" })
|
||||
Check(!ChatCoords.MayHaveCoords(t), $"pre-check skips \"{t}\"");
|
||||
|
||||
// Soundness: over random lines built from coordinate-ish pieces, Find never finds a pair the pre-check skipped.
|
||||
var rng = new Random(20261019);
|
||||
string[] pieces = { "42.1", "33.6", "N", "S", "E", "W", "n", "e", " ", ", ", " ", "x", " ", "/", "101.9", "7.5", "5", "120" };
|
||||
int found = 0;
|
||||
for (int k = 0; k < 60000; k++)
|
||||
{
|
||||
var sb = new System.Text.StringBuilder();
|
||||
for (int n = rng.Next(1, 9); n > 0; n--) sb.Append(pieces[rng.Next(pieces.Length)]);
|
||||
string line = sb.ToString();
|
||||
if (ChatCoords.Find(line).Count > 0)
|
||||
{
|
||||
found++;
|
||||
if (!ChatCoords.MayHaveCoords(line)) Check(false, $"pre-check skipped \"{line}\", which holds a coordinate");
|
||||
}
|
||||
}
|
||||
Check(found > 100, $"the random lines held coordinates to test with ({found})");
|
||||
Check(true, "pre-check never skipped a line with a coordinate");
|
||||
}
|
||||
|
||||
private const uint LinkCol = 0xFF5ECFE0;
|
||||
|
||||
/// <summary>The coordinate links laid over a rule's highlight spans.</summary>
|
||||
private static void LinkSpans()
|
||||
{
|
||||
// No coordinates: the highlights come back as they were.
|
||||
var plain = new[] { new ChatSpan(2, 3, 0xFF112233), new ChatSpan(8, 2, 0xFF445566) };
|
||||
Same(ChatCoords.LinkSpans(plain, new List<ChatCoord>(), LinkCol), plain, "no coordinates: highlights unchanged");
|
||||
Check(ChatCoords.LinkSpans(null, new List<ChatCoord>(), LinkCol).Length == 0, "no spans, no coordinates: nothing");
|
||||
|
||||
// A line with only a coordinate (no rule highlight): one link span over it.
|
||||
string text = "meet at 42.1N, 33.6E soon";
|
||||
var coords = ChatCoords.Find(text);
|
||||
var only = ChatCoords.LinkSpans(null, coords, LinkCol);
|
||||
Check(only.Length == 1 && only[0].Start == coords[0].Start && only[0].Length == coords[0].Length && only[0].Argb == LinkCol,
|
||||
"a coordinate alone becomes one link span");
|
||||
|
||||
// A highlight across the whole line is cut around the coordinate: before, link, after.
|
||||
var whole = new[] { new ChatSpan(0, text.Length, 0xFFAA0000) };
|
||||
var cut = ChatCoords.LinkSpans(whole, coords, LinkCol);
|
||||
Check(cut.Length == 3, $"a highlight over the coordinate is cut in two around it (got {cut.Length})");
|
||||
if (cut.Length == 3)
|
||||
{
|
||||
Check(cut[0].Start == 0 && cut[0].Length == coords[0].Start && cut[0].Argb == 0xFFAA0000, "the part before keeps the highlight");
|
||||
Check(cut[1].Start == coords[0].Start && cut[1].Length == coords[0].Length && cut[1].Argb == LinkCol, "the coordinate keeps the link colour");
|
||||
int end = coords[0].Start + coords[0].Length;
|
||||
Check(cut[2].Start == end && cut[2].Start + cut[2].Length == text.Length && cut[2].Argb == 0xFFAA0000, "the part after keeps the highlight");
|
||||
}
|
||||
|
||||
// A highlight that only covers part of the coordinate loses that part and keeps the rest.
|
||||
var half = new[] { new ChatSpan(coords[0].Start - 3, 8, 0xFF00AA00) }; // ends inside the coordinate
|
||||
var halfCut = ChatCoords.LinkSpans(half, coords, LinkCol);
|
||||
Check(halfCut.Length == 2 && halfCut[0].Argb == 0xFF00AA00 && halfCut[0].Length == 3 && halfCut[1].Argb == LinkCol,
|
||||
"a highlight ending inside the coordinate is cut at it");
|
||||
|
||||
// A highlight beside the coordinate (no overlap) is untouched; the result is sorted and never overlaps.
|
||||
var beside = new[] { new ChatSpan(0, 4, 0xFF0000AA), new ChatSpan(coords[0].Start + coords[0].Length + 1, 4, 0xFF0000BB) };
|
||||
var res = ChatCoords.LinkSpans(beside, coords, LinkCol);
|
||||
Check(res.Length == 3 && res[0].Argb == 0xFF0000AA && res[1].Argb == LinkCol && res[2].Argb == 0xFF0000BB, "highlights beside it stay, in order");
|
||||
NoOverlap(res, "beside");
|
||||
|
||||
// Two coordinates and several highlights: sorted, no overlap, every coordinate present exactly once.
|
||||
string two = "from 42.1N, 33.6E to 21.5S, 1.8W now";
|
||||
var cs = ChatCoords.Find(two);
|
||||
var hl = new[] { new ChatSpan(0, 9, 0xFF010101), new ChatSpan(10, 20, 0xFF020202) };
|
||||
var r2 = ChatCoords.LinkSpans(hl, cs, LinkCol);
|
||||
NoOverlap(r2, "two coordinates");
|
||||
Check(r2.Count(s => s.Argb == LinkCol) == 2, "both coordinates are links");
|
||||
foreach (ChatCoord c in cs)
|
||||
Check(r2.Any(s => s.Start == c.Start && s.Length == c.Length && s.Argb == LinkCol), $"link span for {c.Text}");
|
||||
}
|
||||
|
||||
private static void NoOverlap(ChatSpan[] spans, string what)
|
||||
{
|
||||
bool ok = true;
|
||||
for (int i = 1; i < spans.Length; i++)
|
||||
if (spans[i].Start < spans[i - 1].Start + spans[i - 1].Length) ok = false;
|
||||
Check(ok, $"{what}: sorted and non-overlapping");
|
||||
}
|
||||
|
||||
private static void Same(ChatSpan[] got, ChatSpan[] want, string what) =>
|
||||
Check(got.Length == want.Length && got.Zip(want).All(p => p.First == p.Second), what);
|
||||
|
||||
private static void One(string text, double ns, double ew, string formatted)
|
||||
{
|
||||
var found = ChatCoords.Find(text);
|
||||
|
|
|
|||
Loading…
Reference in a new issue