Scaffold AvParser: Avalonia 12 shell with adaptive layout

Greenfield skeleton for a parser desktop app. The domain is deliberately a
placeholder — IParser<TIn,TOut> plus two sample parsers — so the shell is
runnable and verifiable end to end before real logic lands.

Layers run one way: Core (no Avalonia, no IO) <- Infrastructure <- UI <- Desktop.
UI is a class library rather than the exe so headless tests build real views
without dragging in Program.cs, Serilog or the container.

Adaptive layout is built from what Avalonia actually offers, since it has no
AdaptiveTrigger or media queries: ResponsiveLayout observes Visual.Bounds and
projects a breakpoint onto both an attached property and :compact/:medium/
:expanded pseudoclasses, with 24px hysteresis so dragging a window edge cannot
make the layout flap. Pane state lives in the view model because a style setter
loses to a local value permanently; styles own only the visual variance.

Stack notes worth remembering: Avalonia.ReactiveUI is deprecated in favour of
ReactiveUI.Avalonia, and ReactiveUI 24 runs on the Primitives engine (RxVoid,
ISequencer, Signal<T>) and no longer self-initialises. Avalonia.Headless.XUnit
12.x requires xUnit v3. InvariantGlobalization must stay false or Semi.Avalonia
throws in its static constructor.

102 tests across three projects, including headless guards for the two failures
that are otherwise completely silent: a stylesheet whose selectors match nothing,
and a light palette too low-contrast for cards to read.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Leonid Pershin
2026-08-13 16:07:08 +03:00
co-authored by Claude Opus 5
commit 3db9d4dfc6
94 changed files with 5966 additions and 0 deletions
@@ -0,0 +1,114 @@
using AvParser.Core.Parsing;
using AvParser.Core.Parsing.Samples;
namespace AvParser.Core.Tests;
public class DelimitedTextParserTests
{
private readonly DelimitedTextParser _parser = new();
[Fact]
public async Task Parses_header_and_rows()
{
var (records, errors) = await _parser.CollectAsync("id,name\n1,Ada\n2,Grace");
errors.ShouldBeEmpty();
records.Count.ShouldBe(2);
records[0].Field("id").ShouldBe("1");
records[0].Field("name").ShouldBe("Ada");
records[1].LineNumber.ShouldBe(3);
}
[Theory]
[InlineData("a;b\n1;2")]
[InlineData("a\tb\n1\t2")]
[InlineData("a|b\n1|2")]
public async Task Detects_the_delimiter_from_the_header(string input)
{
var (records, errors) = await _parser.CollectAsync(input);
errors.ShouldBeEmpty();
records.ShouldHaveSingleItem().Fields.Count.ShouldBe(2);
}
[Fact]
public async Task Reports_a_field_count_mismatch_without_aborting()
{
var (records, errors) = await _parser.CollectAsync("id,name\n1\n2,Grace");
// The bad line becomes an error; the good line after it still parses.
errors.ShouldHaveSingleItem().LineNumber.ShouldBe(2);
records.ShouldHaveSingleItem().Field("name").ShouldBe("Grace");
}
[Fact]
public async Task Skips_blank_lines_and_comments()
{
var (records, errors) = await _parser.CollectAsync("# a comment\nid,name\n\n1,Ada\n");
errors.ShouldBeEmpty();
records.ShouldHaveSingleItem().Field("name").ShouldBe("Ada");
}
[Fact]
public async Task Trims_surrounding_whitespace()
{
var (records, _) = await _parser.CollectAsync("id , name\n 1 , Ada ");
records.ShouldHaveSingleItem().Field("name").ShouldBe("Ada");
}
[Fact]
public async Task Reports_an_error_when_there_is_no_header()
{
var (records, errors) = await _parser.CollectAsync("\n\n");
records.ShouldBeEmpty();
errors.ShouldHaveSingleItem().Message.ShouldContain("header");
}
[Fact]
public async Task Reports_progress_reaching_completion()
{
var reports = new List<ParseProgress>();
// Not Progress<T>: it posts to the captured synchronization context, so the reports would
// arrive after the assertions. A direct IProgress<T> keeps the test deterministic.
await foreach (
var _ in _parser.ParseAsync(
ParserTestExtensions.DelimitedDocument(900),
new SynchronousProgress<ParseProgress>(reports.Add),
TestContext.Current.CancellationToken
)
) { }
reports.ShouldNotBeEmpty();
reports[^1].Fraction.ShouldBe(1d);
}
[Fact]
public async Task Honours_cancellation()
{
using var cancellation = new CancellationTokenSource();
var act = async () =>
{
await foreach (
var _ in _parser.ParseAsync(ParserTestExtensions.DelimitedDocument(20_000), null, cancellation.Token)
)
{
await cancellation.CancelAsync();
}
};
await act.ShouldThrowAsync<OperationCanceledException>();
}
[Theory]
[InlineData("", false)]
[InlineData(" ", false)]
[InlineData("no delimiters here", false)]
[InlineData("a,b", true)]
public void CanParse_checks_for_a_delimiter(string input, bool expected) =>
_parser.CanParse(input).ShouldBe(expected);
}