51 lines
4.1 KiB
C#
51 lines
4.1 KiB
C#
using PlotLine.Services.Context;
|
||
using static PlotLine.Services.Context.ContextIntentText;
|
||
|
||
internal static class ContextIntentTextTests
|
||
{
|
||
public static void Run()
|
||
{
|
||
static void Check(bool condition, string message) { if (!condition) throw new Exception(message); }
|
||
static void Reject(Action action) { try { action(); } catch (ArgumentException) { return; } throw new Exception("Expected bounded-input rejection."); }
|
||
var parsed = Parse("- [ ] Introduce the disagreement\r\n* [x] Keep the promise\n\n1. Reveal a clue\n• Keep the promise\nUnbulleted objective\n- [ ] ");
|
||
Check(parsed.Count == 5, "Blank lines and empty checklist entries are omitted.");
|
||
Check(parsed[1].RequestedCompleted && !parsed[0].RequestedCompleted, "Pasted checks remain explicit preview choices.");
|
||
Check(parsed[1].Text == parsed[3].Text, "Repeated author objectives are preserved.");
|
||
Check(Parse("- [X] A\r+ B\n2) C\n– D").Select(x => x.Text).SequenceEqual(new[] { "A", "B", "C", "D" }), "Common bullet and newline formats.");
|
||
Check(Parse("<script>alert('text')</script>")[0].Text.StartsWith("<script>"), "Parser returns plain text; rendering must encode it.");
|
||
Reject(() => Parse(new string('a', 301)));
|
||
Reject(() => Parse(string.Join('\n', Enumerable.Repeat("- a", 201))));
|
||
Reject(() => Parse(new string(' ', 64_001)));
|
||
|
||
var chapters = ParseChapters("# Opening\r\nA summary\r\n- First beat\n\nChapter 4: Return\n1. Second beat");
|
||
Check(chapters.Select(chapter => chapter.Heading).SequenceEqual(["Opening", "Chapter 4: Return"]),
|
||
"Chapter headings split a paste without inferring chapter IDs.");
|
||
Check(chapters[0].Body.Contains("A summary") && Parse(chapters[1].Body).Single().Text == "Second beat",
|
||
"Notes retain prose and bullets can become checklist items.");
|
||
Reject(() => ParseChapters(string.Join('\n', Enumerable.Repeat("# Heading\n- item", 21))));
|
||
|
||
Entity[] library = [
|
||
new("character:1", "Mira Vale", ["Mira", "Captain"], ["Recorded scene appearance"]),
|
||
new("character:1", "Mira Vale", ["M. Vale"], ["Author plan"]),
|
||
new("candidate:2", "Captain", [], ["Pending candidate; not confirmed"]),
|
||
new("location:1", "Vale", [], ["Recorded location"]),
|
||
new("asset:1", "Key", [], ["Existing asset"])
|
||
];
|
||
var palette = Deduplicate(library);
|
||
Check(palette.Count == 4 && palette[0].Provenance.Count == 2, "Deduplicate identities and retain provenance.");
|
||
var mentions = Match("MIRA VALE met the Captain. Mira had the key, not a keyboard or a monkey. M. Vale left.", library);
|
||
Check(mentions.Count == 5, "Case insensitive, whole word/phrase and aliases only.");
|
||
Check(mentions[0].Text == "MIRA VALE" && mentions[0].EntityKeys.SequenceEqual(new[] { "character:1" }), "Longest phrase suppresses nested names.");
|
||
Check(mentions[1].Ambiguous && mentions[1].EntityKeys.SequenceEqual(new[] { "candidate:2", "character:1" }), "Shared canonical/candidate labels remain ambiguous.");
|
||
Check(mentions[^1].Text == "M. Vale", "Punctuation within an exact alias is literal.");
|
||
Check(Match("Key_Key Key2 2Key Key\u0301 Key", library).Count == 1, "Unicode marks, numbers and connectors form word boundaries.");
|
||
Check(Match("\U00010400Key Key\U00010400 (Key)", library).Count == 1, "Supplementary Unicode letters cannot be mistaken for boundaries.");
|
||
Check(Match("Mira! Mira?", library).Count == 2, "Repeated occurrences retain independent passage offsets.");
|
||
Check(Match("", library).Count == 0 && Match("Mira", []).Count == 0, "Empty accepted text/reference libraries produce no suggestions.");
|
||
Check(Match("Someone keeps an unspoken promise.", library).Count == 0, "No semantic inference.");
|
||
Reject(() => Match(new string('a', MaximumPassageLength + 1), library));
|
||
Reject(() => Deduplicate([new("", "Name", [], [])]));
|
||
Check(library[0].Provenance.Count == 1 && library[0].Aliases.Count == 2, "Preparation never mutates canonical input.");
|
||
}
|
||
}
|