tests(calendar): Add calendar render tests (#3)

- updates calendar to support overriding the current day when rendering
- supports current culture when rendering
- renames Calendar to CalendarGenerator
This commit is contained in:
Scott 2026-08-05 06:15:53 +00:00
commit 3547e32b6e
29 changed files with 542 additions and 19 deletions

View file

@ -1,6 +1,7 @@
using System;
using System.Globalization;
using System.Management.Automation;
using ModuleCore.Calendar;
namespace PowershellModule.Calendar
{
@ -42,7 +43,7 @@ namespace PowershellModule.Calendar
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
// Guaranteed to be initialised in BeginProcessing. If it's not, something is cooked in some other way
private ModuleCore.Calendar.Calendar _calendar = null!;
private CalendarGenerator _calendar = null!;
private const string Noun = "Calendar";
public const string FullName = $"{VerbsCommon.Get}-{Noun}";
@ -80,7 +81,7 @@ namespace PowershellModule.Calendar
{
if (dayOfWeek is null)
{
return ModuleCore.Calendar.Calendar.DefaultStartOfWeek;
return CalendarGenerator.DefaultStartOfWeek;
}
return dayOfWeek.ToLowerInvariant() switch
@ -92,13 +93,13 @@ namespace PowershellModule.Calendar
"thursday" => DayOfWeek.Thursday,
"friday" => DayOfWeek.Friday,
"saturday" => DayOfWeek.Saturday,
_ => ModuleCore.Calendar.Calendar.DefaultStartOfWeek
_ => CalendarGenerator.DefaultStartOfWeek
};
}
protected override void ProcessRecord()
{
var calendar = _calendar.RenderCalendar(_dateToRender);
var calendar = _calendar.Render(_dateToRender);
// From _very_ basic testing, string split allocates the same as making a span and iterating over it.
// I'm assuming this is because a lot of the span code is what string.Split() does internally and the rest