From 98efe06f6ada7d61564d3c870b5854b4804cdbae Mon Sep 17 00:00:00 2001 From: Nick Khalow <71646502+NickKhalow@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:36:31 +0300 Subject: [PATCH] AppArgs test and fix debug flag (#1892) --- .../AppArgs/ApplicationParametersParser.cs | 10 +++++++-- .../Assets/Scripts/Global/AppArgs/IAppArgs.cs | 6 +++++- .../Assets/Scripts/Global/AppArgs/Tests.meta | 3 +++ .../Global/AppArgs/Tests/AppArgs.Tests.asmref | 3 +++ .../AppArgs/Tests/AppArgs.Tests.asmref.meta | 3 +++ .../Global/AppArgs/Tests/AppArgsTests.cs | 21 +++++++++++++++++++ .../Global/AppArgs/Tests/AppArgsTests.cs.meta | 3 +++ 7 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 Explorer/Assets/Scripts/Global/AppArgs/Tests.meta create mode 100644 Explorer/Assets/Scripts/Global/AppArgs/Tests/AppArgs.Tests.asmref create mode 100644 Explorer/Assets/Scripts/Global/AppArgs/Tests/AppArgs.Tests.asmref.meta create mode 100644 Explorer/Assets/Scripts/Global/AppArgs/Tests/AppArgsTests.cs create mode 100644 Explorer/Assets/Scripts/Global/AppArgs/Tests/AppArgsTests.cs.meta diff --git a/Explorer/Assets/Scripts/Global/AppArgs/ApplicationParametersParser.cs b/Explorer/Assets/Scripts/Global/AppArgs/ApplicationParametersParser.cs index 45af498038..b9b027225c 100644 --- a/Explorer/Assets/Scripts/Global/AppArgs/ApplicationParametersParser.cs +++ b/Explorer/Assets/Scripts/Global/AppArgs/ApplicationParametersParser.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text.RegularExpressions; @@ -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(); } @@ -33,6 +36,9 @@ public bool HasFlag(string flagName) => public bool TryGetValue(string flagName, out string? value) => appParameters.TryGetValue(flagName, out value); + public IEnumerable Flags() => + appParameters.Keys; + private void AddAlwaysInEditorFlags() { foreach ((string? key, string? value) in ALWAYS_IN_EDITOR) diff --git a/Explorer/Assets/Scripts/Global/AppArgs/IAppArgs.cs b/Explorer/Assets/Scripts/Global/AppArgs/IAppArgs.cs index 55d1b1b588..99a6f1f2fd 100644 --- a/Explorer/Assets/Scripts/Global/AppArgs/IAppArgs.cs +++ b/Explorer/Assets/Scripts/Global/AppArgs/IAppArgs.cs @@ -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 Flags(); } public static class AppArgsExtensions diff --git a/Explorer/Assets/Scripts/Global/AppArgs/Tests.meta b/Explorer/Assets/Scripts/Global/AppArgs/Tests.meta new file mode 100644 index 0000000000..71551b83f6 --- /dev/null +++ b/Explorer/Assets/Scripts/Global/AppArgs/Tests.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 5e39e87a17df4a71806309ed9e1298ac +timeCreated: 1724747358 \ No newline at end of file diff --git a/Explorer/Assets/Scripts/Global/AppArgs/Tests/AppArgs.Tests.asmref b/Explorer/Assets/Scripts/Global/AppArgs/Tests/AppArgs.Tests.asmref new file mode 100644 index 0000000000..9c56917b75 --- /dev/null +++ b/Explorer/Assets/Scripts/Global/AppArgs/Tests/AppArgs.Tests.asmref @@ -0,0 +1,3 @@ +{ + "reference": "GUID:da80994a355e49d5b84f91c0a84a721f" +} \ No newline at end of file diff --git a/Explorer/Assets/Scripts/Global/AppArgs/Tests/AppArgs.Tests.asmref.meta b/Explorer/Assets/Scripts/Global/AppArgs/Tests/AppArgs.Tests.asmref.meta new file mode 100644 index 0000000000..001d044b92 --- /dev/null +++ b/Explorer/Assets/Scripts/Global/AppArgs/Tests/AppArgs.Tests.asmref.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 30872d32e06b46419bd50cce890a8a26 +timeCreated: 1724747381 \ No newline at end of file diff --git a/Explorer/Assets/Scripts/Global/AppArgs/Tests/AppArgsTests.cs b/Explorer/Assets/Scripts/Global/AppArgs/Tests/AppArgsTests.cs new file mode 100644 index 0000000000..02d5121371 --- /dev/null +++ b/Explorer/Assets/Scripts/Global/AppArgs/Tests/AppArgsTests.cs @@ -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())}"); + } + } +} diff --git a/Explorer/Assets/Scripts/Global/AppArgs/Tests/AppArgsTests.cs.meta b/Explorer/Assets/Scripts/Global/AppArgs/Tests/AppArgsTests.cs.meta new file mode 100644 index 0000000000..9059f571a2 --- /dev/null +++ b/Explorer/Assets/Scripts/Global/AppArgs/Tests/AppArgsTests.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d271992a069149f5856d40ce163f300b +timeCreated: 1724747376 \ No newline at end of file