using AcDream.App.Configuration; namespace AcDream.App.Tests.Configuration; /// /// Campaign LA slice LA1 review fix (F5): pins /// 's trailing-flag edge case — /// --session-config present as the LAST argument with nothing after /// it must be distinguishable from the flag being entirely absent, so /// Program.cs can turn it into a hard error instead of a silent /// fall-through to the env-var/positional dat-dir path. /// public sealed class SessionConfigArgumentParsingTests { private const string Flag = "--session-config"; [Fact] public void FlagWithAFollowingValueReturnsThatValueAndIsPresent() { string? value = SessionConfigArgumentParsing.ExtractFlagValue( ["D:\\dats", Flag, "session.json"], Flag, out bool present); Assert.True(present); Assert.Equal("session.json", value); } [Fact] public void FlagAbsentReturnsNullAndIsNotPresent() { string? value = SessionConfigArgumentParsing.ExtractFlagValue( ["D:\\dats"], Flag, out bool present); Assert.False(present); Assert.Null(value); } [Fact] public void TrailingFlagWithNoValueIsPresentWithANullValue() { string? value = SessionConfigArgumentParsing.ExtractFlagValue( ["D:\\dats", Flag], Flag, out bool present); // This is the case Program.cs must turn into exit code 2 — present // but no value is categorically different from "not present at // all", even though both currently yield a null return value. Assert.True(present); Assert.Null(value); } [Fact] public void FlagAloneAsTheOnlyArgumentIsPresentWithANullValue() { string? value = SessionConfigArgumentParsing.ExtractFlagValue( [Flag], Flag, out bool present); Assert.True(present); Assert.Null(value); } [Fact] public void WithoutFlagAndValueDropsTheFlagAndItsValue() { string[] positional = SessionConfigArgumentParsing.WithoutFlagAndValue( ["D:\\dats", Flag, "session.json", "extra"], Flag); Assert.Equal(["D:\\dats", "extra"], positional); } [Fact] public void WithoutFlagAndValueTrailingFlagDropsOnlyTheFlagItself() { string[] positional = SessionConfigArgumentParsing.WithoutFlagAndValue( ["D:\\dats", Flag], Flag); Assert.Equal(["D:\\dats"], positional); } [Fact] public void WithoutFlagAndValueLeavesArgumentsUnchangedWhenFlagIsAbsent() { string[] positional = SessionConfigArgumentParsing.WithoutFlagAndValue( ["D:\\dats"], Flag); Assert.Equal(["D:\\dats"], positional); } }