Skip to content

Commit

Permalink
AppArgs test and fix debug flag (#1892)
Browse files Browse the repository at this point in the history
  • Loading branch information
NickKhalow authored Aug 27, 2024
1 parent 11ffe9f commit 98efe06
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text.RegularExpressions;
Expand All @@ -19,11 +20,13 @@ public class ApplicationParametersParser : IAppArgs

public ApplicationParametersParser() : this(Environment.GetCommandLineArgs()) { }

public ApplicationParametersParser(string[] args)
public ApplicationParametersParser(string[] args) : this(true, args) { }

public ApplicationParametersParser(bool useInEditorFlags = true, params string[] args)
{
ParseApplicationParameters(args);

if (Application.isEditor)
if (useInEditorFlags && Application.isEditor)
AddAlwaysInEditorFlags();
}

Expand All @@ -33,6 +36,9 @@ public bool HasFlag(string flagName) =>
public bool TryGetValue(string flagName, out string? value) =>
appParameters.TryGetValue(flagName, out value);

public IEnumerable<string> Flags() =>
appParameters.Keys;

private void AddAlwaysInEditorFlags()
{
foreach ((string? key, string? value) in ALWAYS_IN_EDITOR)
Expand Down
6 changes: 5 additions & 1 deletion Explorer/Assets/Scripts/Global/AppArgs/IAppArgs.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using System.Collections.Generic;

namespace Global.AppArgs
{
public interface IAppArgs
{
public const string DEBUG_FLAG = "-debug";
public const string DEBUG_FLAG = "debug";

bool HasFlag(string flagName);

bool TryGetValue(string flagName, out string? value);

IEnumerable<string> Flags();
}

public static class AppArgsExtensions
Expand Down
3 changes: 3 additions & 0 deletions Explorer/Assets/Scripts/Global/AppArgs/Tests.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"reference": "GUID:da80994a355e49d5b84f91c0a84a721f"
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions Explorer/Assets/Scripts/Global/AppArgs/Tests/AppArgsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using NUnit.Framework;

namespace Global.AppArgs.Tests
{
public class AppArgsTest
{
[Test]
public void DebugArgFailTest()
{
IAppArgs args = new ApplicationParametersParser(false, "-debug");
Assert.False(args.HasDebugFlag(), $"flags in args: {string.Join(", ", args.Flags())}");
}

[Test]
public void DebugArgContainsTest()
{
IAppArgs args = new ApplicationParametersParser(false, "--debug");
Assert.True(args.HasDebugFlag(), $"flags in args: {string.Join(", ", args.Flags())}");
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 98efe06

Please sign in to comment.