Files
james.maesandCodex GPT-6 38dd5c1488 feat: implement Windows MarkdownViewr (#35)
This replaces the blocked history in PR #3 with one properly attributed,
signed/DCO commit. The owner personally reviewed and approved PR #3 in
the release session.

**No file changes from the approved candidate:** both
baee14f492 and
e605df62c4 have exact Git tree
a85912cbad. Original PR #3 and its commits
are preserved for review history. Historical commits were locally signed
but GitHub reported no_user; protected merge checks those introduced
commits even for squash merging. This commit resolves attribution
without bypassing or weakening signature rules.

The reader, Settings, themes, source highlighting/split, live reload,
file associations, Print/PDF, About credits, toolbar/footer/editor
fixes, user-first README/screenshots and developer guides are exactly
the approved implementation. Stable/dev separation and protected Azure
signing caller are unchanged.

Evidence:
- Approved tree baee14f / CI38285775463 passes all checks. Downloaded
focused29/29, published111/111, stable110/110 and dev110/110 TRXs have
zero failures/skips. Core coverage100% lines/98.86% branches; actual
update/restart/coexistence/default-preservation receipts verify.
- New single-commit hooks, online workflow security, signing and DCO
pass. GitHub must rerun all required checks on this commit; results are
not copied across SHAs.
- Live repository setup validates18 Actions-bound checks, with only
fuzzing added and all prior protections preserved.
- OpenSSF project15417 is now owner-reviewed and saved at70% under
owner-confirmed CDLA-Permissive2.0. This is an in-progress assessment,
not a passing badge.
- Production CI OIDC and signed1.0/dev publication remain required;
local representative signing is not CI proof.

Substantial AI assistance: Codex (GPT-6). Supersedes PR #3. Release work
remains tracked in #33.

Closes #4, #6, #7, #8, #9, #10, #11, #12, #13, #14, #15, #16, #17, #18,
#19, #20, #21, #22, #23, #24, #25, #26, #27, #28, #29, #32, #34.
Refs #1, #5, #30, #31, #33.

Signed-off-by: James Maes <james@kof22.com>
Co-authored-by: Codex GPT-6 <noreply@openai.com>
2026-10-12 14:01:42 -05:00

114 lines
4.4 KiB
C#

/*
* Copyright (c) 2026 James Maes
* SPDX-License-Identifier: MIT
*/
using System.Globalization;
using System.Text.Json;
using MarkdownViewr.Windows.Core.Navigation;
using MarkdownViewr.Windows.Core.Themes;
namespace MarkdownViewr.Windows.Core.Tests;
/// <summary>Verifies window-local bounded state and real bundled theme font scaling without changing persisted source themes.</summary>
public sealed class ReaderZoomTests
{
/// <summary>Repeated commands stay bounded, actual size resets, and another window retains its independent state.</summary>
[Fact]
public void Apply_RepeatedAndIndependentCommands_RetainsBoundsAndActualSize()
{
var zoom = new ReaderZoom();
var other = new ReaderZoom();
Assert.Equal(1, zoom.Scale);
zoom.Apply(ReaderCommand.None);
Assert.Equal(1, zoom.Scale);
zoom.Apply(ReaderCommand.ZoomIn);
Assert.Equal(1.1, zoom.Scale);
zoom.Apply(ReaderCommand.ZoomOut);
Assert.Equal(1, zoom.Scale, precision: 12);
for(int index = 0; index < 100; index++)
{
zoom.Apply(ReaderCommand.ZoomIn);
}
Assert.Equal(5, zoom.Scale);
for(int index = 0; index < 100; index++)
{
zoom.Apply(ReaderCommand.ZoomOut);
}
Assert.Equal(0.3, zoom.Scale);
zoom.Apply(ReaderCommand.ZoomReset);
Assert.Equal(1, zoom.Scale);
Assert.Equal(1, other.Scale);
}
/// <summary>Every bundled theme scales all eight font sizes but retains line height, original JSON and actual-size CSS.</summary>
[Theory]
[InlineData(0.3)]
[InlineData(1.1)]
[InlineData(5)]
public void GetStyles_BundledThemes_ScalesFontsWithInvariantNumbers(double scale)
{
CultureInfo previous = CultureInfo.CurrentCulture;
try
{
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("fr-FR");
foreach(ReaderTheme theme in ThemeCatalog.BuiltIn)
{
string original = theme.Json;
using var json = JsonDocument.Parse(original);
JsonElement sizes = json.RootElement.GetProperty("sizes");
string styles = theme.GetStyles(scale);
foreach(string field in new[] { "baseFontSize", "h1Size", "h2Size", "h3Size", "h4Size", "h5Size", "h6Size", "codeFontSize" })
{
string number = (sizes.GetProperty(field).GetDouble() * scale).ToString("R", CultureInfo.InvariantCulture);
Assert.Contains("--" + field + ":" + number + "px;", styles, StringComparison.Ordinal);
}
Assert.Contains("--lineHeight:" + sizes.GetProperty("lineHeight").GetDouble().ToString("R", CultureInfo.InvariantCulture) + ";", styles, StringComparison.Ordinal);
Assert.Equal(theme.Styles, theme.GetStyles(1));
Assert.Equal(original, theme.Json);
}
}
finally
{
CultureInfo.CurrentCulture = previous;
}
}
/// <summary>Nonfinite and out-of-range scales cannot become generated browser CSS.</summary>
[Theory]
[InlineData(double.NaN)]
[InlineData(double.PositiveInfinity)]
[InlineData(double.NegativeInfinity)]
[InlineData(0)]
[InlineData(0.299)]
[InlineData(5.001)]
public void GetStyles_InvalidScale_RejectsInput(double scale)
=> Assert.Throws<ArgumentOutOfRangeException>(() => ThemeCatalog.Find(null).GetStyles(scale));
/// <summary>Ctrl zoom commands own only reading focus and their allowed shift combinations.</summary>
[Theory]
[InlineData('+', false, ReaderCommand.ZoomIn)]
[InlineData('+', true, ReaderCommand.ZoomIn)]
[InlineData('=', false, ReaderCommand.ZoomIn)]
[InlineData('=', true, ReaderCommand.None)]
[InlineData('-', false, ReaderCommand.ZoomOut)]
[InlineData('-', true, ReaderCommand.None)]
[InlineData('0', false, ReaderCommand.ZoomReset)]
[InlineData('0', true, ReaderCommand.None)]
public void Resolve_ZoomModifiersAndFocus_PreservesNativeTextInput(char character, bool shift, ReaderCommand expected)
{
var key = new ReaderKey(character, Control: true, Shift: shift);
Assert.Equal(expected, new ReaderKeyboard().Resolve(key, readingFocused: true, 0));
Assert.Equal(ReaderCommand.None, new ReaderKeyboard().Resolve(key, readingFocused: false, 0));
Assert.Equal(ReaderCommand.None, new ReaderKeyboard().Resolve(key with { Alt = true }, readingFocused: true, 0));
Assert.Equal(ReaderCommand.None, new ReaderKeyboard().Resolve(key with { Windows = true }, readingFocused: true, 0));
}
}