diff --git a/src/Spectre.Console.Analyzer.Sandbox/Program.cs b/src/Spectre.Console.Analyzer.Sandbox/Program.cs index cf927c3..65463c4 100644 --- a/src/Spectre.Console.Analyzer.Sandbox/Program.cs +++ b/src/Spectre.Console.Analyzer.Sandbox/Program.cs @@ -12,4 +12,4 @@ public static class Program { AnsiConsole.WriteLine("Project is set up with a reference to Spectre.Console.Analyzer"); } -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Analyzer/Analyzers/FavorInstanceAnsiConsoleOverStaticAnalyzer.cs b/src/Spectre.Console.Analyzer/Analyzers/FavorInstanceAnsiConsoleOverStaticAnalyzer.cs index b65cace..bd9bb28 100644 --- a/src/Spectre.Console.Analyzer/Analyzers/FavorInstanceAnsiConsoleOverStaticAnalyzer.cs +++ b/src/Spectre.Console.Analyzer/Analyzers/FavorInstanceAnsiConsoleOverStaticAnalyzer.cs @@ -1,11 +1,3 @@ -using System.Collections.Immutable; -using System.Linq; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.Operations; - namespace Spectre.Console.Analyzer; /// @@ -91,4 +83,4 @@ public class FavorInstanceAnsiConsoleOverStaticAnalyzer : SpectreAnalyzer i.Declaration.Type.NormalizeWhitespace().ToString() == "IAnsiConsole" && (!isStatic ^ i.Modifiers.Any(modifier => modifier.Kind() == SyntaxKind.StaticKeyword))); } -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Analyzer/Analyzers/NoConcurrentLiveRenderablesAnalyzer.cs b/src/Spectre.Console.Analyzer/Analyzers/NoConcurrentLiveRenderablesAnalyzer.cs index 8133c50..9aa59d4 100644 --- a/src/Spectre.Console.Analyzer/Analyzers/NoConcurrentLiveRenderablesAnalyzer.cs +++ b/src/Spectre.Console.Analyzer/Analyzers/NoConcurrentLiveRenderablesAnalyzer.cs @@ -1,12 +1,3 @@ -using System.Collections.Immutable; -using System.Composition; -using System.Linq; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.Operations; - namespace Spectre.Console.Analyzer; /// @@ -74,4 +65,4 @@ public class NoConcurrentLiveRenderablesAnalyzer : SpectreAnalyzer displayString)); }, OperationKind.Invocation); } -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Analyzer/Analyzers/NoPromptsDuringLiveRenderablesAnalyzer.cs b/src/Spectre.Console.Analyzer/Analyzers/NoPromptsDuringLiveRenderablesAnalyzer.cs index 4496eab..8e87ef9 100644 --- a/src/Spectre.Console.Analyzer/Analyzers/NoPromptsDuringLiveRenderablesAnalyzer.cs +++ b/src/Spectre.Console.Analyzer/Analyzers/NoPromptsDuringLiveRenderablesAnalyzer.cs @@ -1,12 +1,3 @@ -using System.Collections.Immutable; -using System.Composition; -using System.Linq; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.Operations; - namespace Spectre.Console.Analyzer; /// @@ -80,4 +71,4 @@ public class NoPromptsDuringLiveRenderablesAnalyzer : SpectreAnalyzer displayString)); }, OperationKind.Invocation); } -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Analyzer/Analyzers/SpectreAnalyzer.cs b/src/Spectre.Console.Analyzer/Analyzers/SpectreAnalyzer.cs index b5486de..54436c8 100644 --- a/src/Spectre.Console.Analyzer/Analyzers/SpectreAnalyzer.cs +++ b/src/Spectre.Console.Analyzer/Analyzers/SpectreAnalyzer.cs @@ -1,5 +1,3 @@ -using Microsoft.CodeAnalysis.Diagnostics; - namespace Spectre.Console.Analyzer; /// @@ -21,4 +19,4 @@ public abstract class SpectreAnalyzer : DiagnosticAnalyzer /// /// Compilation Start Analysis Context. protected abstract void AnalyzeCompilation(CompilationStartAnalysisContext compilationStartContext); -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Analyzer/Analyzers/UseSpectreInsteadOfSystemConsoleAnalyzer.cs b/src/Spectre.Console.Analyzer/Analyzers/UseSpectreInsteadOfSystemConsoleAnalyzer.cs index 865c095..3c91f1d 100644 --- a/src/Spectre.Console.Analyzer/Analyzers/UseSpectreInsteadOfSystemConsoleAnalyzer.cs +++ b/src/Spectre.Console.Analyzer/Analyzers/UseSpectreInsteadOfSystemConsoleAnalyzer.cs @@ -1,9 +1,3 @@ -using System.Collections.Immutable; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.Operations; - namespace Spectre.Console.Analyzer; /// @@ -59,4 +53,4 @@ public class UseSpectreInsteadOfSystemConsoleAnalyzer : SpectreAnalyzer displayString)); }, OperationKind.Invocation); } -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Analyzer/Constants.cs b/src/Spectre.Console.Analyzer/Constants.cs index bec402a..e617071 100644 --- a/src/Spectre.Console.Analyzer/Constants.cs +++ b/src/Spectre.Console.Analyzer/Constants.cs @@ -11,4 +11,4 @@ internal static class Constants "Spectre.Console.Progress", "Spectre.Console.Status", }; -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Analyzer/Descriptors.cs b/src/Spectre.Console.Analyzer/Descriptors.cs index 70b6bc0..592a6df 100644 --- a/src/Spectre.Console.Analyzer/Descriptors.cs +++ b/src/Spectre.Console.Analyzer/Descriptors.cs @@ -1,5 +1,3 @@ -using System.Collections.Concurrent; -using Microsoft.CodeAnalysis; using static Microsoft.CodeAnalysis.DiagnosticSeverity; using static Spectre.Console.Analyzer.Descriptors.Category; @@ -75,4 +73,4 @@ public static class Descriptors Usage, Warning, "Avoid prompting for input while a current renderable is running."); -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Analyzer/Fixes/CodeActions/SwitchToAnsiConsoleAction.cs b/src/Spectre.Console.Analyzer/Fixes/CodeActions/SwitchToAnsiConsoleAction.cs index 72dd104..f4421ef 100644 --- a/src/Spectre.Console.Analyzer/Fixes/CodeActions/SwitchToAnsiConsoleAction.cs +++ b/src/Spectre.Console.Analyzer/Fixes/CodeActions/SwitchToAnsiConsoleAction.cs @@ -1,10 +1,3 @@ -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CodeActions; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; namespace Spectre.Console.Analyzer.CodeActions; @@ -112,4 +105,4 @@ public class SwitchToAnsiConsoleAction : CodeAction .WithLeadingTrivia(_originalInvocation.GetLeadingTrivia())) .Expression; } -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Analyzer/Fixes/FixProviders/StaticAnsiConsoleToInstanceFix.cs b/src/Spectre.Console.Analyzer/Fixes/FixProviders/StaticAnsiConsoleToInstanceFix.cs index 2e8ff8b..3a73748 100644 --- a/src/Spectre.Console.Analyzer/Fixes/FixProviders/StaticAnsiConsoleToInstanceFix.cs +++ b/src/Spectre.Console.Analyzer/Fixes/FixProviders/StaticAnsiConsoleToInstanceFix.cs @@ -1,11 +1,3 @@ -using System.Collections.Immutable; -using System.Composition; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CodeFixes; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using Spectre.Console.Analyzer.CodeActions; - namespace Spectre.Console.Analyzer.FixProviders; /// @@ -31,4 +23,4 @@ public class StaticAnsiConsoleToInstanceFix : CodeFixProvider new SwitchToAnsiConsoleAction(context.Document, methodDeclaration, "Convert static AnsiConsole calls to local instance."), context.Diagnostics); } -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Analyzer/Fixes/FixProviders/SystemConsoleToAnsiConsoleFix.cs b/src/Spectre.Console.Analyzer/Fixes/FixProviders/SystemConsoleToAnsiConsoleFix.cs index 7cfdbb3..eeee888 100644 --- a/src/Spectre.Console.Analyzer/Fixes/FixProviders/SystemConsoleToAnsiConsoleFix.cs +++ b/src/Spectre.Console.Analyzer/Fixes/FixProviders/SystemConsoleToAnsiConsoleFix.cs @@ -1,11 +1,3 @@ -using System.Collections.Immutable; -using System.Composition; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CodeFixes; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using Spectre.Console.Analyzer.CodeActions; - namespace Spectre.Console.Analyzer.FixProviders; /// @@ -31,4 +23,4 @@ public class SystemConsoleToAnsiConsoleFix : CodeFixProvider new SwitchToAnsiConsoleAction(context.Document, methodDeclaration, "Convert static call to AnsiConsole to Spectre.Console.AnsiConsole"), context.Diagnostics); } -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Analyzer/Fixes/Syntax.cs b/src/Spectre.Console.Analyzer/Fixes/Syntax.cs index 0e3aefd..6cedc68 100644 --- a/src/Spectre.Console.Analyzer/Fixes/Syntax.cs +++ b/src/Spectre.Console.Analyzer/Fixes/Syntax.cs @@ -1,4 +1,3 @@ -using Microsoft.CodeAnalysis.CSharp.Syntax; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; namespace Spectre.Console.Analyzer; @@ -6,4 +5,4 @@ namespace Spectre.Console.Analyzer; internal static class Syntax { public static readonly UsingDirectiveSyntax SpectreUsing = UsingDirective(QualifiedName(IdentifierName("Spectre"), IdentifierName("Console"))); -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Analyzer/Properties/Usings.cs b/src/Spectre.Console.Analyzer/Properties/Usings.cs new file mode 100644 index 0000000..b48e0f2 --- /dev/null +++ b/src/Spectre.Console.Analyzer/Properties/Usings.cs @@ -0,0 +1,14 @@ +global using System.Collections.Concurrent; +global using System.Collections.Immutable; +global using System.Composition; +global using System.Linq; +global using System.Threading; +global using System.Threading.Tasks; +global using Microsoft.CodeAnalysis; +global using Microsoft.CodeAnalysis.CodeActions; +global using Microsoft.CodeAnalysis.CodeFixes; +global using Microsoft.CodeAnalysis.CSharp; +global using Microsoft.CodeAnalysis.CSharp.Syntax; +global using Microsoft.CodeAnalysis.Diagnostics; +global using Microsoft.CodeAnalysis.Operations; +global using Spectre.Console.Analyzer.CodeActions; \ No newline at end of file diff --git a/src/Spectre.Console.Testing/Cli/CallbackCommandInterceptor.cs b/src/Spectre.Console.Testing/Cli/CallbackCommandInterceptor.cs index cfb96b5..4c71177 100644 --- a/src/Spectre.Console.Testing/Cli/CallbackCommandInterceptor.cs +++ b/src/Spectre.Console.Testing/Cli/CallbackCommandInterceptor.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Cli; - namespace Spectre.Console.Testing; /// @@ -24,4 +21,4 @@ public sealed class CallbackCommandInterceptor : ICommandInterceptor { _callback(context, settings); } -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Testing/Cli/CommandAppFailure.cs b/src/Spectre.Console.Testing/Cli/CommandAppFailure.cs index 22d9215..611cdd0 100644 --- a/src/Spectre.Console.Testing/Cli/CommandAppFailure.cs +++ b/src/Spectre.Console.Testing/Cli/CommandAppFailure.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Cli; - namespace Spectre.Console.Testing; /// @@ -25,4 +22,4 @@ public sealed class CommandAppFailure .TrimLines() .Trim(); } -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Testing/Cli/CommandAppResult.cs b/src/Spectre.Console.Testing/Cli/CommandAppResult.cs index dacedd5..3b5a914 100644 --- a/src/Spectre.Console.Testing/Cli/CommandAppResult.cs +++ b/src/Spectre.Console.Testing/Cli/CommandAppResult.cs @@ -1,5 +1,3 @@ -using Spectre.Console.Cli; - namespace Spectre.Console.Testing; /// @@ -39,4 +37,4 @@ public sealed class CommandAppResult .TrimLines() .Trim(); } -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Testing/Cli/CommandAppTester.cs b/src/Spectre.Console.Testing/Cli/CommandAppTester.cs index 31f8773..8143e1c 100644 --- a/src/Spectre.Console.Testing/Cli/CommandAppTester.cs +++ b/src/Spectre.Console.Testing/Cli/CommandAppTester.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Cli; - namespace Spectre.Console.Testing; /// @@ -131,4 +128,4 @@ public sealed class CommandAppTester return new CommandAppResult(result, output, context, settings); } -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Testing/Cli/TypeRegistrarBaseTests.cs b/src/Spectre.Console.Testing/Cli/TypeRegistrarBaseTests.cs index 67cc4f5..b1baa38 100644 --- a/src/Spectre.Console.Testing/Cli/TypeRegistrarBaseTests.cs +++ b/src/Spectre.Console.Testing/Cli/TypeRegistrarBaseTests.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Cli; - namespace Spectre.Console.Testing; /// @@ -187,4 +184,4 @@ public sealed class TypeRegistrarBaseTests { } } -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Testing/Extensions/StringExtensions.cs b/src/Spectre.Console.Testing/Extensions/StringExtensions.cs index 68aa3fb..72c0cd8 100644 --- a/src/Spectre.Console.Testing/Extensions/StringExtensions.cs +++ b/src/Spectre.Console.Testing/Extensions/StringExtensions.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console.Testing; /// @@ -43,4 +41,4 @@ public static class StringExtensions return string.Empty; } -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Testing/Extensions/StyleExtensions.cs b/src/Spectre.Console.Testing/Extensions/StyleExtensions.cs index a4f392f..2416804 100644 --- a/src/Spectre.Console.Testing/Extensions/StyleExtensions.cs +++ b/src/Spectre.Console.Testing/Extensions/StyleExtensions.cs @@ -21,4 +21,4 @@ public static class StyleExtensions return style.Background(color); } -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Testing/Internal/NoopCursor.cs b/src/Spectre.Console.Testing/Internal/NoopCursor.cs index 67b7379..d43204c 100644 --- a/src/Spectre.Console.Testing/Internal/NoopCursor.cs +++ b/src/Spectre.Console.Testing/Internal/NoopCursor.cs @@ -13,4 +13,4 @@ internal sealed class NoopCursor : IAnsiConsoleCursor public void Show(bool show) { } -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Testing/Internal/NoopExclusivityMode.cs b/src/Spectre.Console.Testing/Internal/NoopExclusivityMode.cs index ec7be80..c792e1e 100644 --- a/src/Spectre.Console.Testing/Internal/NoopExclusivityMode.cs +++ b/src/Spectre.Console.Testing/Internal/NoopExclusivityMode.cs @@ -1,6 +1,3 @@ -using System; -using System.Threading.Tasks; - namespace Spectre.Console.Testing; internal sealed class NoopExclusivityMode : IExclusivityMode @@ -14,4 +11,4 @@ internal sealed class NoopExclusivityMode : IExclusivityMode { return await func().ConfigureAwait(false); } -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Testing/Properties/Usings.cs b/src/Spectre.Console.Testing/Properties/Usings.cs new file mode 100644 index 0000000..19e56f3 --- /dev/null +++ b/src/Spectre.Console.Testing/Properties/Usings.cs @@ -0,0 +1,7 @@ +global using System; +global using System.Collections.Generic; +global using System.IO; +global using System.Threading; +global using System.Threading.Tasks; +global using Spectre.Console.Cli; +global using Spectre.Console.Rendering; \ No newline at end of file diff --git a/src/Spectre.Console.Testing/Spectre.Console.Testing.csproj b/src/Spectre.Console.Testing/Spectre.Console.Testing.csproj index b38c7b2..46c6ada 100644 --- a/src/Spectre.Console.Testing/Spectre.Console.Testing.csproj +++ b/src/Spectre.Console.Testing/Spectre.Console.Testing.csproj @@ -17,8 +17,4 @@ - - - - diff --git a/src/Spectre.Console.Testing/TestCapabilities.cs b/src/Spectre.Console.Testing/TestCapabilities.cs index 749005d..1064bd5 100644 --- a/src/Spectre.Console.Testing/TestCapabilities.cs +++ b/src/Spectre.Console.Testing/TestCapabilities.cs @@ -1,5 +1,3 @@ -using Spectre.Console.Rendering; - namespace Spectre.Console.Testing; /// @@ -36,4 +34,4 @@ public sealed class TestCapabilities : IReadOnlyCapabilities { return new RenderContext(this); } -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Testing/TestConsole.cs b/src/Spectre.Console.Testing/TestConsole.cs index d40c01f..fe140a9 100644 --- a/src/Spectre.Console.Testing/TestConsole.cs +++ b/src/Spectre.Console.Testing/TestConsole.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.IO; -using Spectre.Console.Rendering; - namespace Spectre.Console.Testing; /// @@ -118,4 +113,4 @@ public sealed class TestConsole : IAnsiConsole, IDisposable { _cursor = cursor; } -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Testing/TestConsoleExtensions.cs b/src/Spectre.Console.Testing/TestConsoleExtensions.cs index feeda73..c2397d0 100644 --- a/src/Spectre.Console.Testing/TestConsoleExtensions.cs +++ b/src/Spectre.Console.Testing/TestConsoleExtensions.cs @@ -63,4 +63,4 @@ public static class TestConsoleExtensions console.EmitAnsiSequences = true; return console; } -} +} \ No newline at end of file diff --git a/src/Spectre.Console.Testing/TestConsoleInput.cs b/src/Spectre.Console.Testing/TestConsoleInput.cs index 274bec4..09273cd 100644 --- a/src/Spectre.Console.Testing/TestConsoleInput.cs +++ b/src/Spectre.Console.Testing/TestConsoleInput.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - namespace Spectre.Console.Testing; /// @@ -88,4 +83,4 @@ public sealed class TestConsoleInput : IAnsiConsoleInput { return Task.FromResult(ReadKey(intercept)); } -} +} \ No newline at end of file diff --git a/src/Spectre.Console/AnsiConsole.Exceptions.cs b/src/Spectre.Console/AnsiConsole.Exceptions.cs index b49a03d..12d4420 100644 --- a/src/Spectre.Console/AnsiConsole.Exceptions.cs +++ b/src/Spectre.Console/AnsiConsole.Exceptions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/AnsiConsole.Live.cs b/src/Spectre.Console/AnsiConsole.Live.cs index 4efd7c5..3d3e4b8 100644 --- a/src/Spectre.Console/AnsiConsole.Live.cs +++ b/src/Spectre.Console/AnsiConsole.Live.cs @@ -1,5 +1,3 @@ -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/AnsiConsole.Markup.cs b/src/Spectre.Console/AnsiConsole.Markup.cs index 962e7ff..87b35ca 100644 --- a/src/Spectre.Console/AnsiConsole.Markup.cs +++ b/src/Spectre.Console/AnsiConsole.Markup.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/AnsiConsole.Prompt.cs b/src/Spectre.Console/AnsiConsole.Prompt.cs index 2bd5ba2..ef892ae 100644 --- a/src/Spectre.Console/AnsiConsole.Prompt.cs +++ b/src/Spectre.Console/AnsiConsole.Prompt.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/AnsiConsole.Recording.cs b/src/Spectre.Console/AnsiConsole.Recording.cs index a28c89f..a398a37 100644 --- a/src/Spectre.Console/AnsiConsole.Recording.cs +++ b/src/Spectre.Console/AnsiConsole.Recording.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/AnsiConsole.Rendering.cs b/src/Spectre.Console/AnsiConsole.Rendering.cs index 0ede6fd..ca56a90 100644 --- a/src/Spectre.Console/AnsiConsole.Rendering.cs +++ b/src/Spectre.Console/AnsiConsole.Rendering.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/AnsiConsole.Screen.cs b/src/Spectre.Console/AnsiConsole.Screen.cs index 35740da..f89fd59 100644 --- a/src/Spectre.Console/AnsiConsole.Screen.cs +++ b/src/Spectre.Console/AnsiConsole.Screen.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/AnsiConsole.Write.cs b/src/Spectre.Console/AnsiConsole.Write.cs index bb936b1..8d40819 100644 --- a/src/Spectre.Console/AnsiConsole.Write.cs +++ b/src/Spectre.Console/AnsiConsole.Write.cs @@ -1,6 +1,3 @@ -using System; -using System.Globalization; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/AnsiConsole.WriteLine.cs b/src/Spectre.Console/AnsiConsole.WriteLine.cs index afd2687..57ba6b7 100644 --- a/src/Spectre.Console/AnsiConsole.WriteLine.cs +++ b/src/Spectre.Console/AnsiConsole.WriteLine.cs @@ -1,6 +1,3 @@ -using System; -using System.Globalization; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/AnsiConsole.cs b/src/Spectre.Console/AnsiConsole.cs index ac88d3c..120b25b 100644 --- a/src/Spectre.Console/AnsiConsole.cs +++ b/src/Spectre.Console/AnsiConsole.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/AnsiConsoleFactory.cs b/src/Spectre.Console/AnsiConsoleFactory.cs index 6f0dbba..16c2b10 100644 --- a/src/Spectre.Console/AnsiConsoleFactory.cs +++ b/src/Spectre.Console/AnsiConsoleFactory.cs @@ -1,8 +1,3 @@ -using System; -using System.Runtime.InteropServices; -using Spectre.Console.Enrichment; -using Spectre.Console.Internal; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/AnsiConsoleOutput.cs b/src/Spectre.Console/AnsiConsoleOutput.cs index 392eaef..4e278f9 100644 --- a/src/Spectre.Console/AnsiConsoleOutput.cs +++ b/src/Spectre.Console/AnsiConsoleOutput.cs @@ -1,7 +1,3 @@ -using System; -using System.IO; -using System.Text; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/AnsiConsoleSettings.cs b/src/Spectre.Console/AnsiConsoleSettings.cs index 6fdea92..0841303 100644 --- a/src/Spectre.Console/AnsiConsoleSettings.cs +++ b/src/Spectre.Console/AnsiConsoleSettings.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/BoxBorder.Known.cs b/src/Spectre.Console/BoxBorder.Known.cs index e7e4730..afc487f 100644 --- a/src/Spectre.Console/BoxBorder.Known.cs +++ b/src/Spectre.Console/BoxBorder.Known.cs @@ -1,6 +1,3 @@ -using System.Diagnostics.CodeAnalysis; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/BoxBorder.cs b/src/Spectre.Console/BoxBorder.cs index 8cd5e87..e30d5f3 100644 --- a/src/Spectre.Console/BoxBorder.cs +++ b/src/Spectre.Console/BoxBorder.cs @@ -1,5 +1,3 @@ -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Capabilities.cs b/src/Spectre.Console/Capabilities.cs index 9a4ec30..49a9b47 100644 --- a/src/Spectre.Console/Capabilities.cs +++ b/src/Spectre.Console/Capabilities.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Cli/Annotations/CommandArgumentAttribute.cs b/src/Spectre.Console/Cli/Annotations/CommandArgumentAttribute.cs index 44b0a4c..4d7e6b0 100644 --- a/src/Spectre.Console/Cli/Annotations/CommandArgumentAttribute.cs +++ b/src/Spectre.Console/Cli/Annotations/CommandArgumentAttribute.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/Annotations/CommandOptionAttribute.cs b/src/Spectre.Console/Cli/Annotations/CommandOptionAttribute.cs index f57068d..098c3f4 100644 --- a/src/Spectre.Console/Cli/Annotations/CommandOptionAttribute.cs +++ b/src/Spectre.Console/Cli/Annotations/CommandOptionAttribute.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/Annotations/PairDeconstructorAttribute.cs b/src/Spectre.Console/Cli/Annotations/PairDeconstructorAttribute.cs index 3575735..b212602 100644 --- a/src/Spectre.Console/Cli/Annotations/PairDeconstructorAttribute.cs +++ b/src/Spectre.Console/Cli/Annotations/PairDeconstructorAttribute.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/Annotations/ParameterValidationAttribute.cs b/src/Spectre.Console/Cli/Annotations/ParameterValidationAttribute.cs index 2bd2300..38f3f19 100644 --- a/src/Spectre.Console/Cli/Annotations/ParameterValidationAttribute.cs +++ b/src/Spectre.Console/Cli/Annotations/ParameterValidationAttribute.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/Annotations/ParameterValueProviderAttribute.cs b/src/Spectre.Console/Cli/Annotations/ParameterValueProviderAttribute.cs index 336f260..69f1f73 100644 --- a/src/Spectre.Console/Cli/Annotations/ParameterValueProviderAttribute.cs +++ b/src/Spectre.Console/Cli/Annotations/ParameterValueProviderAttribute.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/AsyncCommand.cs b/src/Spectre.Console/Cli/AsyncCommand.cs index 72099b9..5dd1209 100644 --- a/src/Spectre.Console/Cli/AsyncCommand.cs +++ b/src/Spectre.Console/Cli/AsyncCommand.cs @@ -1,5 +1,3 @@ -using System.Threading.Tasks; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/AsyncCommandOfT.cs b/src/Spectre.Console/Cli/AsyncCommandOfT.cs index 80be43d..87da022 100644 --- a/src/Spectre.Console/Cli/AsyncCommandOfT.cs +++ b/src/Spectre.Console/Cli/AsyncCommandOfT.cs @@ -1,6 +1,3 @@ -using System.Diagnostics; -using System.Threading.Tasks; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/CaseSensitivity.cs b/src/Spectre.Console/Cli/CaseSensitivity.cs index ce00760..778579b 100644 --- a/src/Spectre.Console/Cli/CaseSensitivity.cs +++ b/src/Spectre.Console/Cli/CaseSensitivity.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/Command.cs b/src/Spectre.Console/Cli/Command.cs index 4b87fe9..2261e6f 100644 --- a/src/Spectre.Console/Cli/Command.cs +++ b/src/Spectre.Console/Cli/Command.cs @@ -1,5 +1,3 @@ -using System.Threading.Tasks; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/CommandApp.cs b/src/Spectre.Console/Cli/CommandApp.cs index bb6256d..8ea2c63 100644 --- a/src/Spectre.Console/Cli/CommandApp.cs +++ b/src/Spectre.Console/Cli/CommandApp.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Threading.Tasks; -using Spectre.Console.Rendering; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/CommandAppException.cs b/src/Spectre.Console/Cli/CommandAppException.cs index f3d4fe3..cfd5529 100644 --- a/src/Spectre.Console/Cli/CommandAppException.cs +++ b/src/Spectre.Console/Cli/CommandAppException.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Rendering; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/CommandAppOfT.cs b/src/Spectre.Console/Cli/CommandAppOfT.cs index 05befdd..b4a1287 100644 --- a/src/Spectre.Console/Cli/CommandAppOfT.cs +++ b/src/Spectre.Console/Cli/CommandAppOfT.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/CommandConfigurationException.cs b/src/Spectre.Console/Cli/CommandConfigurationException.cs index 0bd43bc..f1a1ed5 100644 --- a/src/Spectre.Console/Cli/CommandConfigurationException.cs +++ b/src/Spectre.Console/Cli/CommandConfigurationException.cs @@ -1,7 +1,3 @@ -using System; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/CommandOfT.cs b/src/Spectre.Console/Cli/CommandOfT.cs index 57833b2..3415e32 100644 --- a/src/Spectre.Console/Cli/CommandOfT.cs +++ b/src/Spectre.Console/Cli/CommandOfT.cs @@ -1,7 +1,3 @@ -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; -using System.Threading.Tasks; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/CommandParameterContext.cs b/src/Spectre.Console/Cli/CommandParameterContext.cs index 442abdd..a7d5cfd 100644 --- a/src/Spectre.Console/Cli/CommandParameterContext.cs +++ b/src/Spectre.Console/Cli/CommandParameterContext.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/CommandParseException.cs b/src/Spectre.Console/Cli/CommandParseException.cs index 589554a..2520da8 100644 --- a/src/Spectre.Console/Cli/CommandParseException.cs +++ b/src/Spectre.Console/Cli/CommandParseException.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using Spectre.Console.Rendering; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/CommandRuntimeException.cs b/src/Spectre.Console/Cli/CommandRuntimeException.cs index 413e345..786d294 100644 --- a/src/Spectre.Console/Cli/CommandRuntimeException.cs +++ b/src/Spectre.Console/Cli/CommandRuntimeException.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Rendering; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/CommandTemplateException.cs b/src/Spectre.Console/Cli/CommandTemplateException.cs index b9946cc..d862f72 100644 --- a/src/Spectre.Console/Cli/CommandTemplateException.cs +++ b/src/Spectre.Console/Cli/CommandTemplateException.cs @@ -1,6 +1,3 @@ -using System.Globalization; -using Spectre.Console.Rendering; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/ConfiguratorExtensions.cs b/src/Spectre.Console/Cli/ConfiguratorExtensions.cs index 789c55b..5ffaf96 100644 --- a/src/Spectre.Console/Cli/ConfiguratorExtensions.cs +++ b/src/Spectre.Console/Cli/ConfiguratorExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/FlagValue.cs b/src/Spectre.Console/Cli/FlagValue.cs index 2d697f8..8e295ce 100644 --- a/src/Spectre.Console/Cli/FlagValue.cs +++ b/src/Spectre.Console/Cli/FlagValue.cs @@ -1,6 +1,3 @@ -using System; -using System.Globalization; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/ICommand.cs b/src/Spectre.Console/Cli/ICommand.cs index 3c8c9bf..8cbcbf7 100644 --- a/src/Spectre.Console/Cli/ICommand.cs +++ b/src/Spectre.Console/Cli/ICommand.cs @@ -1,5 +1,3 @@ -using System.Threading.Tasks; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/ICommandApp.cs b/src/Spectre.Console/Cli/ICommandApp.cs index 005e810..5d5e2e7 100644 --- a/src/Spectre.Console/Cli/ICommandApp.cs +++ b/src/Spectre.Console/Cli/ICommandApp.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/ICommandAppSettings.cs b/src/Spectre.Console/Cli/ICommandAppSettings.cs index 6768919..8e89a78 100644 --- a/src/Spectre.Console/Cli/ICommandAppSettings.cs +++ b/src/Spectre.Console/Cli/ICommandAppSettings.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/ICommandOfT.cs b/src/Spectre.Console/Cli/ICommandOfT.cs index a563372..5b92cf8 100644 --- a/src/Spectre.Console/Cli/ICommandOfT.cs +++ b/src/Spectre.Console/Cli/ICommandOfT.cs @@ -1,5 +1,3 @@ -using System.Threading.Tasks; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/ICommandParameterInfo.cs b/src/Spectre.Console/Cli/ICommandParameterInfo.cs index 4121115..b6483ef 100644 --- a/src/Spectre.Console/Cli/ICommandParameterInfo.cs +++ b/src/Spectre.Console/Cli/ICommandParameterInfo.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/IConfigurator.cs b/src/Spectre.Console/Cli/IConfigurator.cs index 14b27f1..565a4f3 100644 --- a/src/Spectre.Console/Cli/IConfigurator.cs +++ b/src/Spectre.Console/Cli/IConfigurator.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/IConfiguratorOfT.cs b/src/Spectre.Console/Cli/IConfiguratorOfT.cs index 1bcfcb6..7852aaf 100644 --- a/src/Spectre.Console/Cli/IConfiguratorOfT.cs +++ b/src/Spectre.Console/Cli/IConfiguratorOfT.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/IFlagValue.cs b/src/Spectre.Console/Cli/IFlagValue.cs index c67a3a6..0463319 100644 --- a/src/Spectre.Console/Cli/IFlagValue.cs +++ b/src/Spectre.Console/Cli/IFlagValue.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/IRemainingArguments.cs b/src/Spectre.Console/Cli/IRemainingArguments.cs index 22d3009..8127416 100644 --- a/src/Spectre.Console/Cli/IRemainingArguments.cs +++ b/src/Spectre.Console/Cli/IRemainingArguments.cs @@ -1,6 +1,3 @@ -using System.Collections.Generic; -using System.Linq; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/ITypeRegistrar.cs b/src/Spectre.Console/Cli/ITypeRegistrar.cs index 48f2a3a..0feea7e 100644 --- a/src/Spectre.Console/Cli/ITypeRegistrar.cs +++ b/src/Spectre.Console/Cli/ITypeRegistrar.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/ITypeResolver.cs b/src/Spectre.Console/Cli/ITypeResolver.cs index a75af93..fbfa904 100644 --- a/src/Spectre.Console/Cli/ITypeResolver.cs +++ b/src/Spectre.Console/Cli/ITypeResolver.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/Internal/Binding/CommandConstructorBinder.cs b/src/Spectre.Console/Cli/Internal/Binding/CommandConstructorBinder.cs index a3b6d69..7e1e6c8 100644 --- a/src/Spectre.Console/Cli/Internal/Binding/CommandConstructorBinder.cs +++ b/src/Spectre.Console/Cli/Internal/Binding/CommandConstructorBinder.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Reflection; - namespace Spectre.Console.Cli; internal static class CommandConstructorBinder diff --git a/src/Spectre.Console/Cli/Internal/Binding/CommandPropertyBinder.cs b/src/Spectre.Console/Cli/Internal/Binding/CommandPropertyBinder.cs index 0486685..31cbf5b 100644 --- a/src/Spectre.Console/Cli/Internal/Binding/CommandPropertyBinder.cs +++ b/src/Spectre.Console/Cli/Internal/Binding/CommandPropertyBinder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; internal static class CommandPropertyBinder diff --git a/src/Spectre.Console/Cli/Internal/Binding/CommandValueBinder.cs b/src/Spectre.Console/Cli/Internal/Binding/CommandValueBinder.cs index 49968ef..cd4094c 100644 --- a/src/Spectre.Console/Cli/Internal/Binding/CommandValueBinder.cs +++ b/src/Spectre.Console/Cli/Internal/Binding/CommandValueBinder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; internal sealed class CommandValueBinder diff --git a/src/Spectre.Console/Cli/Internal/Binding/CommandValueLookup.cs b/src/Spectre.Console/Cli/Internal/Binding/CommandValueLookup.cs index b7f9845..f41f77b 100644 --- a/src/Spectre.Console/Cli/Internal/Binding/CommandValueLookup.cs +++ b/src/Spectre.Console/Cli/Internal/Binding/CommandValueLookup.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; - namespace Spectre.Console.Cli; internal sealed class CommandValueLookup : IEnumerable<(CommandParameter Parameter, object? Value)> diff --git a/src/Spectre.Console/Cli/Internal/Binding/CommandValueResolver.cs b/src/Spectre.Console/Cli/Internal/Binding/CommandValueResolver.cs index 859c5f1..6812c7a 100644 --- a/src/Spectre.Console/Cli/Internal/Binding/CommandValueResolver.cs +++ b/src/Spectre.Console/Cli/Internal/Binding/CommandValueResolver.cs @@ -1,7 +1,3 @@ -using System; -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; - namespace Spectre.Console.Cli; internal static class CommandValueResolver diff --git a/src/Spectre.Console/Cli/Internal/Collections/MultiMap.cs b/src/Spectre.Console/Cli/Internal/Collections/MultiMap.cs index 72174b9..9309704 100644 --- a/src/Spectre.Console/Cli/Internal/Collections/MultiMap.cs +++ b/src/Spectre.Console/Cli/Internal/Collections/MultiMap.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Linq; - namespace Spectre.Console.Cli; [SuppressMessage("Performance", "CA1812: Avoid uninstantiated internal classes")] diff --git a/src/Spectre.Console/Cli/Internal/CommandBinder.cs b/src/Spectre.Console/Cli/Internal/CommandBinder.cs index 15e6618..69d8398 100644 --- a/src/Spectre.Console/Cli/Internal/CommandBinder.cs +++ b/src/Spectre.Console/Cli/Internal/CommandBinder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; internal static class CommandBinder diff --git a/src/Spectre.Console/Cli/Internal/CommandExecutor.cs b/src/Spectre.Console/Cli/Internal/CommandExecutor.cs index ca9c483..3194755 100644 --- a/src/Spectre.Console/Cli/Internal/CommandExecutor.cs +++ b/src/Spectre.Console/Cli/Internal/CommandExecutor.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Threading.Tasks; - namespace Spectre.Console.Cli; internal sealed class CommandExecutor diff --git a/src/Spectre.Console/Cli/Internal/CommandSuggestor.cs b/src/Spectre.Console/Cli/Internal/CommandSuggestor.cs index f08d0e3..0c6fba3 100644 --- a/src/Spectre.Console/Cli/Internal/CommandSuggestor.cs +++ b/src/Spectre.Console/Cli/Internal/CommandSuggestor.cs @@ -1,6 +1,3 @@ -using System; -using System.Linq; - namespace Spectre.Console.Cli; internal static class CommandSuggestor diff --git a/src/Spectre.Console/Cli/Internal/Commands/ExplainCommand.cs b/src/Spectre.Console/Cli/Internal/Commands/ExplainCommand.cs index a19a161..85467a1 100644 --- a/src/Spectre.Console/Cli/Internal/Commands/ExplainCommand.cs +++ b/src/Spectre.Console/Cli/Internal/Commands/ExplainCommand.cs @@ -1,10 +1,3 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console.Cli; [Description("Displays diagnostics about CLI configurations")] diff --git a/src/Spectre.Console/Cli/Internal/Commands/VersionCommand.cs b/src/Spectre.Console/Cli/Internal/Commands/VersionCommand.cs index 6bdb85c..4a944e3 100644 --- a/src/Spectre.Console/Cli/Internal/Commands/VersionCommand.cs +++ b/src/Spectre.Console/Cli/Internal/Commands/VersionCommand.cs @@ -1,6 +1,3 @@ -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; - namespace Spectre.Console.Cli; [Description("Displays the CLI library version")] diff --git a/src/Spectre.Console/Cli/Internal/Commands/XmlDocCommand.cs b/src/Spectre.Console/Cli/Internal/Commands/XmlDocCommand.cs index 1c02d6e..fb6cadc 100644 --- a/src/Spectre.Console/Cli/Internal/Commands/XmlDocCommand.cs +++ b/src/Spectre.Console/Cli/Internal/Commands/XmlDocCommand.cs @@ -1,12 +1,3 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Xml; - namespace Spectre.Console.Cli; [Description("Generates an XML representation of the CLI configuration.")] diff --git a/src/Spectre.Console/Cli/Internal/Composer.cs b/src/Spectre.Console/Cli/Internal/Composer.cs index 83321f3..2d8964b 100644 --- a/src/Spectre.Console/Cli/Internal/Composer.cs +++ b/src/Spectre.Console/Cli/Internal/Composer.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Spectre.Console.Rendering; - namespace Spectre.Console.Cli; internal sealed class Composer : IRenderable diff --git a/src/Spectre.Console/Cli/Internal/Composition/Activators.cs b/src/Spectre.Console/Cli/Internal/Composition/Activators.cs index bec575f..9e8d06d 100644 --- a/src/Spectre.Console/Cli/Internal/Composition/Activators.cs +++ b/src/Spectre.Console/Cli/Internal/Composition/Activators.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Reflection; - namespace Spectre.Console.Cli; internal abstract class ComponentActivator diff --git a/src/Spectre.Console/Cli/Internal/Composition/ComponentRegistration.cs b/src/Spectre.Console/Cli/Internal/Composition/ComponentRegistration.cs index 9732db3..5b5d666 100644 --- a/src/Spectre.Console/Cli/Internal/Composition/ComponentRegistration.cs +++ b/src/Spectre.Console/Cli/Internal/Composition/ComponentRegistration.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace Spectre.Console.Cli; internal sealed class ComponentRegistration diff --git a/src/Spectre.Console/Cli/Internal/Composition/ComponentRegistry.cs b/src/Spectre.Console/Cli/Internal/Composition/ComponentRegistry.cs index 94c6410..426c349 100644 --- a/src/Spectre.Console/Cli/Internal/Composition/ComponentRegistry.cs +++ b/src/Spectre.Console/Cli/Internal/Composition/ComponentRegistry.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - namespace Spectre.Console.Cli; internal sealed class ComponentRegistry : IDisposable diff --git a/src/Spectre.Console/Cli/Internal/Composition/DefaultTypeRegistrar.cs b/src/Spectre.Console/Cli/Internal/Composition/DefaultTypeRegistrar.cs index 948c80a..5672fca 100644 --- a/src/Spectre.Console/Cli/Internal/Composition/DefaultTypeRegistrar.cs +++ b/src/Spectre.Console/Cli/Internal/Composition/DefaultTypeRegistrar.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace Spectre.Console.Cli; internal sealed class DefaultTypeRegistrar : ITypeRegistrar diff --git a/src/Spectre.Console/Cli/Internal/Composition/DefaultTypeResolver.cs b/src/Spectre.Console/Cli/Internal/Composition/DefaultTypeResolver.cs index a0a714e..d59fbb3 100644 --- a/src/Spectre.Console/Cli/Internal/Composition/DefaultTypeResolver.cs +++ b/src/Spectre.Console/Cli/Internal/Composition/DefaultTypeResolver.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - namespace Spectre.Console.Cli; internal sealed class DefaultTypeResolver : IDisposable, ITypeResolver diff --git a/src/Spectre.Console/Cli/Internal/Configuration/CommandAppSettings.cs b/src/Spectre.Console/Cli/Internal/Configuration/CommandAppSettings.cs index 798399c..8fdfff3 100644 --- a/src/Spectre.Console/Cli/Internal/Configuration/CommandAppSettings.cs +++ b/src/Spectre.Console/Cli/Internal/Configuration/CommandAppSettings.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; internal sealed class CommandAppSettings : ICommandAppSettings diff --git a/src/Spectre.Console/Cli/Internal/Configuration/ConfigurationHelper.cs b/src/Spectre.Console/Cli/Internal/Configuration/ConfigurationHelper.cs index e1265a0..405a6c8 100644 --- a/src/Spectre.Console/Cli/Internal/Configuration/ConfigurationHelper.cs +++ b/src/Spectre.Console/Cli/Internal/Configuration/ConfigurationHelper.cs @@ -1,7 +1,3 @@ -using System; -using System.Diagnostics.CodeAnalysis; -using System.Reflection; - namespace Spectre.Console.Cli; internal static class ConfigurationHelper diff --git a/src/Spectre.Console/Cli/Internal/Configuration/Configurator.cs b/src/Spectre.Console/Cli/Internal/Configuration/Configurator.cs index ac4e54e..746393c 100644 --- a/src/Spectre.Console/Cli/Internal/Configuration/Configurator.cs +++ b/src/Spectre.Console/Cli/Internal/Configuration/Configurator.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using Spectre.Console.Cli.Unsafe; - namespace Spectre.Console.Cli; internal sealed class Configurator : IUnsafeConfigurator, IConfigurator, IConfiguration diff --git a/src/Spectre.Console/Cli/Internal/Configuration/ConfiguratorOfT.cs b/src/Spectre.Console/Cli/Internal/Configuration/ConfiguratorOfT.cs index 075cc0d..18cb8ed 100644 --- a/src/Spectre.Console/Cli/Internal/Configuration/ConfiguratorOfT.cs +++ b/src/Spectre.Console/Cli/Internal/Configuration/ConfiguratorOfT.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Cli.Unsafe; - namespace Spectre.Console.Cli; internal sealed class Configurator : IUnsafeBranchConfigurator, IConfigurator diff --git a/src/Spectre.Console/Cli/Internal/Configuration/ConfiguredCommand.cs b/src/Spectre.Console/Cli/Internal/Configuration/ConfiguredCommand.cs index a8cc312..f855dcf 100644 --- a/src/Spectre.Console/Cli/Internal/Configuration/ConfiguredCommand.cs +++ b/src/Spectre.Console/Cli/Internal/Configuration/ConfiguredCommand.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace Spectre.Console.Cli; internal sealed class ConfiguredCommand diff --git a/src/Spectre.Console/Cli/Internal/Configuration/IConfiguration.cs b/src/Spectre.Console/Cli/Internal/Configuration/IConfiguration.cs index 65724df..8aca969 100644 --- a/src/Spectre.Console/Cli/Internal/Configuration/IConfiguration.cs +++ b/src/Spectre.Console/Cli/Internal/Configuration/IConfiguration.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/Internal/Configuration/TemplateParser.cs b/src/Spectre.Console/Cli/Internal/Configuration/TemplateParser.cs index 0d4736b..75a9326 100644 --- a/src/Spectre.Console/Cli/Internal/Configuration/TemplateParser.cs +++ b/src/Spectre.Console/Cli/Internal/Configuration/TemplateParser.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console.Cli; internal static class TemplateParser diff --git a/src/Spectre.Console/Cli/Internal/Configuration/TemplateTokenizer.cs b/src/Spectre.Console/Cli/Internal/Configuration/TemplateTokenizer.cs index 6787672..932a37b 100644 --- a/src/Spectre.Console/Cli/Internal/Configuration/TemplateTokenizer.cs +++ b/src/Spectre.Console/Cli/Internal/Configuration/TemplateTokenizer.cs @@ -1,6 +1,3 @@ -using System.Collections.Generic; -using System.Text; - namespace Spectre.Console.Cli; internal static class TemplateTokenizer diff --git a/src/Spectre.Console/Cli/Internal/DefaultPairDeconstructor.cs b/src/Spectre.Console/Cli/Internal/DefaultPairDeconstructor.cs index 375c686..8d1e73e 100644 --- a/src/Spectre.Console/Cli/Internal/DefaultPairDeconstructor.cs +++ b/src/Spectre.Console/Cli/Internal/DefaultPairDeconstructor.cs @@ -1,7 +1,3 @@ -using System; -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; - namespace Spectre.Console.Cli; [SuppressMessage("Performance", "CA1812: Avoid uninstantiated internal classes")] diff --git a/src/Spectre.Console/Cli/Internal/DelegateCommand.cs b/src/Spectre.Console/Cli/Internal/DelegateCommand.cs index 44f3b8c..ba66c6d 100644 --- a/src/Spectre.Console/Cli/Internal/DelegateCommand.cs +++ b/src/Spectre.Console/Cli/Internal/DelegateCommand.cs @@ -1,6 +1,3 @@ -using System; -using System.Threading.Tasks; - namespace Spectre.Console.Cli; internal sealed class DelegateCommand : ICommand diff --git a/src/Spectre.Console/Cli/Internal/Exceptions/CommandLineParseExceptionFactory.cs b/src/Spectre.Console/Cli/Internal/Exceptions/CommandLineParseExceptionFactory.cs index a216d88..2054206 100644 --- a/src/Spectre.Console/Cli/Internal/Exceptions/CommandLineParseExceptionFactory.cs +++ b/src/Spectre.Console/Cli/Internal/Exceptions/CommandLineParseExceptionFactory.cs @@ -1,6 +1,3 @@ -using System.Collections.Generic; -using Spectre.Console.Rendering; - namespace Spectre.Console.Cli; internal static class CommandLineParseExceptionFactory diff --git a/src/Spectre.Console/Cli/Internal/Exceptions/CommandLineTemplateExceptionFactory.cs b/src/Spectre.Console/Cli/Internal/Exceptions/CommandLineTemplateExceptionFactory.cs index 14c1ee0..3e8d8a5 100644 --- a/src/Spectre.Console/Cli/Internal/Exceptions/CommandLineTemplateExceptionFactory.cs +++ b/src/Spectre.Console/Cli/Internal/Exceptions/CommandLineTemplateExceptionFactory.cs @@ -1,5 +1,3 @@ -using Spectre.Console.Rendering; - namespace Spectre.Console.Cli; internal static class CommandLineTemplateExceptionFactory diff --git a/src/Spectre.Console/Cli/Internal/Extensions/AnsiConsoleExtensions.cs b/src/Spectre.Console/Cli/Internal/Extensions/AnsiConsoleExtensions.cs index 8125625..2e92f32 100644 --- a/src/Spectre.Console/Cli/Internal/Extensions/AnsiConsoleExtensions.cs +++ b/src/Spectre.Console/Cli/Internal/Extensions/AnsiConsoleExtensions.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using Spectre.Console.Rendering; - namespace Spectre.Console.Cli; internal static class AnsiConsoleExtensions diff --git a/src/Spectre.Console/Cli/Internal/Extensions/CaseSensitivityExtensions.cs b/src/Spectre.Console/Cli/Internal/Extensions/CaseSensitivityExtensions.cs index 4b8101d..1411618 100644 --- a/src/Spectre.Console/Cli/Internal/Extensions/CaseSensitivityExtensions.cs +++ b/src/Spectre.Console/Cli/Internal/Extensions/CaseSensitivityExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; internal static class CaseSensitivityExtensions diff --git a/src/Spectre.Console/Cli/Internal/Extensions/ListExtensions.cs b/src/Spectre.Console/Cli/Internal/Extensions/ListExtensions.cs index 996c9cc..0c6d358 100644 --- a/src/Spectre.Console/Cli/Internal/Extensions/ListExtensions.cs +++ b/src/Spectre.Console/Cli/Internal/Extensions/ListExtensions.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace Spectre.Console.Cli; internal static class ListExtensions diff --git a/src/Spectre.Console/Cli/Internal/Extensions/TypeExtensions.cs b/src/Spectre.Console/Cli/Internal/Extensions/TypeExtensions.cs index f416065..fe1def3 100644 --- a/src/Spectre.Console/Cli/Internal/Extensions/TypeExtensions.cs +++ b/src/Spectre.Console/Cli/Internal/Extensions/TypeExtensions.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - namespace Spectre.Console.Cli; internal static class TypeExtensions diff --git a/src/Spectre.Console/Cli/Internal/Extensions/TypeRegistrarExtensions.cs b/src/Spectre.Console/Cli/Internal/Extensions/TypeRegistrarExtensions.cs index d445fd1..d1b0b2b 100644 --- a/src/Spectre.Console/Cli/Internal/Extensions/TypeRegistrarExtensions.cs +++ b/src/Spectre.Console/Cli/Internal/Extensions/TypeRegistrarExtensions.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; - namespace Spectre.Console.Cli; internal static class TypeRegistrarExtensions diff --git a/src/Spectre.Console/Cli/Internal/Extensions/XmlElementExtensions.cs b/src/Spectre.Console/Cli/Internal/Extensions/XmlElementExtensions.cs index 4fe8d51..a3b6626 100644 --- a/src/Spectre.Console/Cli/Internal/Extensions/XmlElementExtensions.cs +++ b/src/Spectre.Console/Cli/Internal/Extensions/XmlElementExtensions.cs @@ -1,10 +1,3 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Reflection; -using System.Xml; - namespace Spectre.Console.Cli; internal static class XmlElementExtensions diff --git a/src/Spectre.Console/Cli/Internal/HelpWriter.cs b/src/Spectre.Console/Cli/Internal/HelpWriter.cs index 353c0e8..e9f47f0 100644 --- a/src/Spectre.Console/Cli/Internal/HelpWriter.cs +++ b/src/Spectre.Console/Cli/Internal/HelpWriter.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Spectre.Console.Rendering; - namespace Spectre.Console.Cli; internal static class HelpWriter diff --git a/src/Spectre.Console/Cli/Internal/IPairDeconstructor.cs b/src/Spectre.Console/Cli/Internal/IPairDeconstructor.cs index 9050694..de6fa45 100644 --- a/src/Spectre.Console/Cli/Internal/IPairDeconstructor.cs +++ b/src/Spectre.Console/Cli/Internal/IPairDeconstructor.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/Internal/Modelling/CommandArgument.cs b/src/Spectre.Console/Cli/Internal/Modelling/CommandArgument.cs index f6c265a..d0bb05c 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/CommandArgument.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/CommandArgument.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Reflection; - namespace Spectre.Console.Cli; internal sealed class CommandArgument : CommandParameter diff --git a/src/Spectre.Console/Cli/Internal/Modelling/CommandContainerExtensions.cs b/src/Spectre.Console/Cli/Internal/Modelling/CommandContainerExtensions.cs index 6941a57..cebcbc5 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/CommandContainerExtensions.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/CommandContainerExtensions.cs @@ -1,5 +1,3 @@ -using System.Linq; - namespace Spectre.Console.Cli; internal static class CommandContainerExtensions diff --git a/src/Spectre.Console/Cli/Internal/Modelling/CommandInfo.cs b/src/Spectre.Console/Cli/Internal/Modelling/CommandInfo.cs index 6f8936e..f2751f4 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/CommandInfo.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/CommandInfo.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Reflection; - namespace Spectre.Console.Cli; internal sealed class CommandInfo : ICommandContainer diff --git a/src/Spectre.Console/Cli/Internal/Modelling/CommandInfoExtensions.cs b/src/Spectre.Console/Cli/Internal/Modelling/CommandInfoExtensions.cs index 76a9d09..b2aa9e6 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/CommandInfoExtensions.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/CommandInfoExtensions.cs @@ -1,5 +1,3 @@ -using System.Linq; - namespace Spectre.Console.Cli; internal static class CommandInfoExtensions diff --git a/src/Spectre.Console/Cli/Internal/Modelling/CommandModel.cs b/src/Spectre.Console/Cli/Internal/Modelling/CommandModel.cs index ae54942..e7a60c0 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/CommandModel.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/CommandModel.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Reflection; - namespace Spectre.Console.Cli; internal sealed class CommandModel : ICommandContainer diff --git a/src/Spectre.Console/Cli/Internal/Modelling/CommandModelBuilder.cs b/src/Spectre.Console/Cli/Internal/Modelling/CommandModelBuilder.cs index 7511c14..da15174 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/CommandModelBuilder.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/CommandModelBuilder.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Reflection; - namespace Spectre.Console.Cli; internal static class CommandModelBuilder diff --git a/src/Spectre.Console/Cli/Internal/Modelling/CommandModelValidator.cs b/src/Spectre.Console/Cli/Internal/Modelling/CommandModelValidator.cs index 21ce93f..dbce5a5 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/CommandModelValidator.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/CommandModelValidator.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - namespace Spectre.Console.Cli; internal static class CommandModelValidator diff --git a/src/Spectre.Console/Cli/Internal/Modelling/CommandOption.cs b/src/Spectre.Console/Cli/Internal/Modelling/CommandOption.cs index ce150b8..cecd1f9 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/CommandOption.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/CommandOption.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Reflection; - namespace Spectre.Console.Cli; internal sealed class CommandOption : CommandParameter diff --git a/src/Spectre.Console/Cli/Internal/Modelling/CommandParameter.cs b/src/Spectre.Console/Cli/Internal/Modelling/CommandParameter.cs index 84c481c..0c96b98 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/CommandParameter.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/CommandParameter.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Reflection; - namespace Spectre.Console.Cli; internal abstract class CommandParameter : ICommandParameterInfo diff --git a/src/Spectre.Console/Cli/Internal/Modelling/CommandParameterComparer.cs b/src/Spectre.Console/Cli/Internal/Modelling/CommandParameterComparer.cs index fa40155..6997b8b 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/CommandParameterComparer.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/CommandParameterComparer.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console.Cli; internal static class CommandParameterComparer diff --git a/src/Spectre.Console/Cli/Internal/Modelling/ICommandContainer.cs b/src/Spectre.Console/Cli/Internal/Modelling/ICommandContainer.cs index 98ff861..a197310 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/ICommandContainer.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/ICommandContainer.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/Internal/Modelling/ParameterKind.cs b/src/Spectre.Console/Cli/Internal/Modelling/ParameterKind.cs index ee139b4..f1fbaa1 100644 --- a/src/Spectre.Console/Cli/Internal/Modelling/ParameterKind.cs +++ b/src/Spectre.Console/Cli/Internal/Modelling/ParameterKind.cs @@ -1,5 +1,3 @@ -using System.ComponentModel; - namespace Spectre.Console.Cli; internal enum ParameterKind diff --git a/src/Spectre.Console/Cli/Internal/Parsing/CommandTree.cs b/src/Spectre.Console/Cli/Internal/Parsing/CommandTree.cs index 0a8946a..edee268 100644 --- a/src/Spectre.Console/Cli/Internal/Parsing/CommandTree.cs +++ b/src/Spectre.Console/Cli/Internal/Parsing/CommandTree.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console.Cli; internal sealed class CommandTree diff --git a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeExtensions.cs b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeExtensions.cs index 4f451db..e7cb225 100644 --- a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeExtensions.cs +++ b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeExtensions.cs @@ -1,6 +1,3 @@ -using System; -using System.Linq; - namespace Spectre.Console.Cli; internal static class CommandTreeExtensions diff --git a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeParser.cs b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeParser.cs index 2b794a0..8801ed0 100644 --- a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeParser.cs +++ b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeParser.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - namespace Spectre.Console.Cli; internal class CommandTreeParser diff --git a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeParserContext.cs b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeParserContext.cs index 9d340fa..65dad51 100644 --- a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeParserContext.cs +++ b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeParserContext.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Linq; - namespace Spectre.Console.Cli; internal class CommandTreeParserContext diff --git a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenStream.cs b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenStream.cs index 9e42250..39d8d53 100644 --- a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenStream.cs +++ b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenStream.cs @@ -1,7 +1,3 @@ -using System.Collections; -using System.Collections.Generic; -using System.Linq; - namespace Spectre.Console.Cli; internal sealed class CommandTreeTokenStream : IReadOnlyList diff --git a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenizer.cs b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenizer.cs index dcb5621..c37303b 100644 --- a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenizer.cs +++ b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenizer.cs @@ -1,8 +1,3 @@ -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; - namespace Spectre.Console.Cli; internal static class CommandTreeTokenizer diff --git a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenizerContext.cs b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenizerContext.cs index 0e1fb3d..b8adf13 100644 --- a/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenizerContext.cs +++ b/src/Spectre.Console/Cli/Internal/Parsing/CommandTreeTokenizerContext.cs @@ -1,6 +1,3 @@ -using System.Collections.Generic; -using System.Text; - namespace Spectre.Console.Cli; internal sealed class CommandTreeTokenizerContext diff --git a/src/Spectre.Console/Cli/Internal/RemainingArguments.cs b/src/Spectre.Console/Cli/Internal/RemainingArguments.cs index 25ec4fe..092eaa5 100644 --- a/src/Spectre.Console/Cli/Internal/RemainingArguments.cs +++ b/src/Spectre.Console/Cli/Internal/RemainingArguments.cs @@ -1,6 +1,3 @@ -using System.Collections.Generic; -using System.Linq; - namespace Spectre.Console.Cli; internal sealed class RemainingArguments : IRemainingArguments diff --git a/src/Spectre.Console/Cli/Internal/StringWriterWithEncoding.cs b/src/Spectre.Console/Cli/Internal/StringWriterWithEncoding.cs index 7ddc846..a366f65 100644 --- a/src/Spectre.Console/Cli/Internal/StringWriterWithEncoding.cs +++ b/src/Spectre.Console/Cli/Internal/StringWriterWithEncoding.cs @@ -1,7 +1,3 @@ -using System; -using System.IO; -using System.Text; - namespace Spectre.Console.Cli; internal sealed class StringWriterWithEncoding : StringWriter diff --git a/src/Spectre.Console/Cli/Internal/TextBuffer.cs b/src/Spectre.Console/Cli/Internal/TextBuffer.cs index 45cb663..cd704bf 100644 --- a/src/Spectre.Console/Cli/Internal/TextBuffer.cs +++ b/src/Spectre.Console/Cli/Internal/TextBuffer.cs @@ -1,6 +1,3 @@ -using System; -using System.IO; - namespace Spectre.Console.Cli; internal sealed class TextBuffer : IDisposable diff --git a/src/Spectre.Console/Cli/Internal/TypeRegistrar.cs b/src/Spectre.Console/Cli/Internal/TypeRegistrar.cs index 5a3548c..1fc0445 100644 --- a/src/Spectre.Console/Cli/Internal/TypeRegistrar.cs +++ b/src/Spectre.Console/Cli/Internal/TypeRegistrar.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; internal sealed class TypeRegistrar : ITypeRegistrarFrontend diff --git a/src/Spectre.Console/Cli/Internal/TypeResolverAdapter.cs b/src/Spectre.Console/Cli/Internal/TypeResolverAdapter.cs index 62d5b0c..c2cc360 100644 --- a/src/Spectre.Console/Cli/Internal/TypeResolverAdapter.cs +++ b/src/Spectre.Console/Cli/Internal/TypeResolverAdapter.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; internal sealed class TypeResolverAdapter : ITypeResolver, IDisposable diff --git a/src/Spectre.Console/Cli/Internal/VersionHelper.cs b/src/Spectre.Console/Cli/Internal/VersionHelper.cs index dc7f37f..6926627 100644 --- a/src/Spectre.Console/Cli/Internal/VersionHelper.cs +++ b/src/Spectre.Console/Cli/Internal/VersionHelper.cs @@ -1,5 +1,3 @@ -using System.Reflection; - namespace Spectre.Console.Cli; internal static class VersionHelper diff --git a/src/Spectre.Console/Cli/PairDeconstructor.cs b/src/Spectre.Console/Cli/PairDeconstructor.cs index 3cbdae3..318c328 100644 --- a/src/Spectre.Console/Cli/PairDeconstructor.cs +++ b/src/Spectre.Console/Cli/PairDeconstructor.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli; /// diff --git a/src/Spectre.Console/Cli/Unsafe/IUnsafeConfigurator.cs b/src/Spectre.Console/Cli/Unsafe/IUnsafeConfigurator.cs index f2b7633..9268cb6 100644 --- a/src/Spectre.Console/Cli/Unsafe/IUnsafeConfigurator.cs +++ b/src/Spectre.Console/Cli/Unsafe/IUnsafeConfigurator.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Cli.Unsafe; /// diff --git a/src/Spectre.Console/Cli/Unsafe/UnsafeConfiguratorExtensions.cs b/src/Spectre.Console/Cli/Unsafe/UnsafeConfiguratorExtensions.cs index 63d25eb..6d24ed8 100644 --- a/src/Spectre.Console/Cli/Unsafe/UnsafeConfiguratorExtensions.cs +++ b/src/Spectre.Console/Cli/Unsafe/UnsafeConfiguratorExtensions.cs @@ -1,5 +1,3 @@ -using System.Linq; - namespace Spectre.Console.Cli.Unsafe; /// diff --git a/src/Spectre.Console/Color.cs b/src/Spectre.Console/Color.cs index 91ebf62..38825a9 100644 --- a/src/Spectre.Console/Color.cs +++ b/src/Spectre.Console/Color.cs @@ -1,7 +1,3 @@ -using System; -using System.Diagnostics; -using System.Globalization; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Decoration.cs b/src/Spectre.Console/Decoration.cs index 219374b..93d2c53 100644 --- a/src/Spectre.Console/Decoration.cs +++ b/src/Spectre.Console/Decoration.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Emoji.cs b/src/Spectre.Console/Emoji.cs index 465ed38..aaea746 100644 --- a/src/Spectre.Console/Emoji.cs +++ b/src/Spectre.Console/Emoji.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Text; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Enrichment/CI/AppVeyorEnricher.cs b/src/Spectre.Console/Enrichment/CI/AppVeyorEnricher.cs index c1c710d..3235c79 100644 --- a/src/Spectre.Console/Enrichment/CI/AppVeyorEnricher.cs +++ b/src/Spectre.Console/Enrichment/CI/AppVeyorEnricher.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console.Enrichment; internal sealed class AppVeyorEnricher : IProfileEnricher diff --git a/src/Spectre.Console/Enrichment/CI/BambooEnricher.cs b/src/Spectre.Console/Enrichment/CI/BambooEnricher.cs index db135a5..91c66e7 100644 --- a/src/Spectre.Console/Enrichment/CI/BambooEnricher.cs +++ b/src/Spectre.Console/Enrichment/CI/BambooEnricher.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console.Enrichment; internal sealed class BambooEnricher : IProfileEnricher diff --git a/src/Spectre.Console/Enrichment/CI/BitbucketEnricher.cs b/src/Spectre.Console/Enrichment/CI/BitbucketEnricher.cs index e990111..fce4ca1 100644 --- a/src/Spectre.Console/Enrichment/CI/BitbucketEnricher.cs +++ b/src/Spectre.Console/Enrichment/CI/BitbucketEnricher.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console.Enrichment; internal sealed class BitbucketEnricher : IProfileEnricher diff --git a/src/Spectre.Console/Enrichment/CI/BitriseEnricher.cs b/src/Spectre.Console/Enrichment/CI/BitriseEnricher.cs index 515f471..a9e4491 100644 --- a/src/Spectre.Console/Enrichment/CI/BitriseEnricher.cs +++ b/src/Spectre.Console/Enrichment/CI/BitriseEnricher.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console.Enrichment; internal sealed class BitriseEnricher : IProfileEnricher diff --git a/src/Spectre.Console/Enrichment/CI/ContinuaEnricher.cs b/src/Spectre.Console/Enrichment/CI/ContinuaEnricher.cs index 59eb240..42c179d 100644 --- a/src/Spectre.Console/Enrichment/CI/ContinuaEnricher.cs +++ b/src/Spectre.Console/Enrichment/CI/ContinuaEnricher.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console.Enrichment; internal sealed class ContinuaEnricher : IProfileEnricher diff --git a/src/Spectre.Console/Enrichment/CI/GitHubEnricher.cs b/src/Spectre.Console/Enrichment/CI/GitHubEnricher.cs index c8ce699..5671f9a 100644 --- a/src/Spectre.Console/Enrichment/CI/GitHubEnricher.cs +++ b/src/Spectre.Console/Enrichment/CI/GitHubEnricher.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace Spectre.Console.Enrichment; internal sealed class GitHubEnricher : IProfileEnricher diff --git a/src/Spectre.Console/Enrichment/CI/GitLabEnricher.cs b/src/Spectre.Console/Enrichment/CI/GitLabEnricher.cs index e668f3d..e16d4bf 100644 --- a/src/Spectre.Console/Enrichment/CI/GitLabEnricher.cs +++ b/src/Spectre.Console/Enrichment/CI/GitLabEnricher.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace Spectre.Console.Enrichment; internal sealed class GitLabEnricher : IProfileEnricher diff --git a/src/Spectre.Console/Enrichment/CI/GoCDEnricher.cs b/src/Spectre.Console/Enrichment/CI/GoCDEnricher.cs index 9baa6bb..066d9b5 100644 --- a/src/Spectre.Console/Enrichment/CI/GoCDEnricher.cs +++ b/src/Spectre.Console/Enrichment/CI/GoCDEnricher.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console.Enrichment; internal sealed class GoCDEnricher : IProfileEnricher diff --git a/src/Spectre.Console/Enrichment/CI/JenkinsEnricher.cs b/src/Spectre.Console/Enrichment/CI/JenkinsEnricher.cs index ff2e30d..2aa4e16 100644 --- a/src/Spectre.Console/Enrichment/CI/JenkinsEnricher.cs +++ b/src/Spectre.Console/Enrichment/CI/JenkinsEnricher.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console.Enrichment; internal sealed class JenkinsEnricher : IProfileEnricher diff --git a/src/Spectre.Console/Enrichment/CI/MyGetEnricher.cs b/src/Spectre.Console/Enrichment/CI/MyGetEnricher.cs index 4eb2424..6be48a6 100644 --- a/src/Spectre.Console/Enrichment/CI/MyGetEnricher.cs +++ b/src/Spectre.Console/Enrichment/CI/MyGetEnricher.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace Spectre.Console.Enrichment; internal sealed class MyGetEnricher : IProfileEnricher diff --git a/src/Spectre.Console/Enrichment/CI/TeamCityEnricher.cs b/src/Spectre.Console/Enrichment/CI/TeamCityEnricher.cs index ae8fb30..71d19c5 100644 --- a/src/Spectre.Console/Enrichment/CI/TeamCityEnricher.cs +++ b/src/Spectre.Console/Enrichment/CI/TeamCityEnricher.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console.Enrichment; internal sealed class TeamCityEnricher : IProfileEnricher diff --git a/src/Spectre.Console/Enrichment/CI/TfsEnricher.cs b/src/Spectre.Console/Enrichment/CI/TfsEnricher.cs index 9dac0b5..e7673bf 100644 --- a/src/Spectre.Console/Enrichment/CI/TfsEnricher.cs +++ b/src/Spectre.Console/Enrichment/CI/TfsEnricher.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console.Enrichment; internal sealed class TfsEnricher : IProfileEnricher diff --git a/src/Spectre.Console/Enrichment/CI/TravisEnricher.cs b/src/Spectre.Console/Enrichment/CI/TravisEnricher.cs index 526bc18..f684d37 100644 --- a/src/Spectre.Console/Enrichment/CI/TravisEnricher.cs +++ b/src/Spectre.Console/Enrichment/CI/TravisEnricher.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console.Enrichment; internal sealed class TravisEnricher : IProfileEnricher diff --git a/src/Spectre.Console/Enrichment/ProfileEnricher.cs b/src/Spectre.Console/Enrichment/ProfileEnricher.cs index e2062a8..8465a74 100644 --- a/src/Spectre.Console/Enrichment/ProfileEnricher.cs +++ b/src/Spectre.Console/Enrichment/ProfileEnricher.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - namespace Spectre.Console.Enrichment; internal static class ProfileEnricher diff --git a/src/Spectre.Console/Enrichment/ProfileEnrichment.cs b/src/Spectre.Console/Enrichment/ProfileEnrichment.cs index e72dd62..fe1f1e3 100644 --- a/src/Spectre.Console/Enrichment/ProfileEnrichment.cs +++ b/src/Spectre.Console/Enrichment/ProfileEnrichment.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/Advanced/AnsiConsoleExtensions.cs b/src/Spectre.Console/Extensions/Advanced/AnsiConsoleExtensions.cs index 12a3cd7..5df87d4 100644 --- a/src/Spectre.Console/Extensions/Advanced/AnsiConsoleExtensions.cs +++ b/src/Spectre.Console/Extensions/Advanced/AnsiConsoleExtensions.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Rendering; - namespace Spectre.Console.Advanced; /// diff --git a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Exceptions.cs b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Exceptions.cs index 3676111..a31ad3c 100644 --- a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Exceptions.cs +++ b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Exceptions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Exclusive.cs b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Exclusive.cs index ffcd9da..160a635 100644 --- a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Exclusive.cs +++ b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Exclusive.cs @@ -1,6 +1,3 @@ -using System; -using System.Threading.Tasks; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Input.cs b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Input.cs index de634d7..30c493e 100644 --- a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Input.cs +++ b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Input.cs @@ -1,10 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Live.cs b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Live.cs index d954331..d9451bb 100644 --- a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Live.cs +++ b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Live.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Markup.cs b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Markup.cs index de3b073..b6d8139 100644 --- a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Markup.cs +++ b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Markup.cs @@ -1,6 +1,3 @@ -using System; -using System.Globalization; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Progress.cs b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Progress.cs index d9daf78..efabdbe 100644 --- a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Progress.cs +++ b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Progress.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Prompt.cs b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Prompt.cs index 9eed583..1b7878a 100644 --- a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Prompt.cs +++ b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Prompt.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Rendering.cs b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Rendering.cs index 254e542..5c48238 100644 --- a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Rendering.cs +++ b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Rendering.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Screen.cs b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Screen.cs index 7f9385e..f41ba46 100644 --- a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Screen.cs +++ b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Screen.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.cs b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.cs index 74f3bf9..3b7f18b 100644 --- a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.cs +++ b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/BarChartExtensions.cs b/src/Spectre.Console/Extensions/BarChartExtensions.cs index b89b553..484f81b 100644 --- a/src/Spectre.Console/Extensions/BarChartExtensions.cs +++ b/src/Spectre.Console/Extensions/BarChartExtensions.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/BoxExtensions.cs b/src/Spectre.Console/Extensions/BoxExtensions.cs index fa3871b..49250ec 100644 --- a/src/Spectre.Console/Extensions/BoxExtensions.cs +++ b/src/Spectre.Console/Extensions/BoxExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Extensions/BreakdownChartExtensions.cs b/src/Spectre.Console/Extensions/BreakdownChartExtensions.cs index ffb4efc..5ace7a9 100644 --- a/src/Spectre.Console/Extensions/BreakdownChartExtensions.cs +++ b/src/Spectre.Console/Extensions/BreakdownChartExtensions.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Globalization; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/CalendarExtensions.cs b/src/Spectre.Console/Extensions/CalendarExtensions.cs index 9c9d119..3d55649 100644 --- a/src/Spectre.Console/Extensions/CalendarExtensions.cs +++ b/src/Spectre.Console/Extensions/CalendarExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/ColumnExtensions.cs b/src/Spectre.Console/Extensions/ColumnExtensions.cs index 468ac60..6a0e4dc 100644 --- a/src/Spectre.Console/Extensions/ColumnExtensions.cs +++ b/src/Spectre.Console/Extensions/ColumnExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/ConfirmationPromptExtensions.cs b/src/Spectre.Console/Extensions/ConfirmationPromptExtensions.cs index d4196de..24a3e90 100644 --- a/src/Spectre.Console/Extensions/ConfirmationPromptExtensions.cs +++ b/src/Spectre.Console/Extensions/ConfirmationPromptExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/DayOfWeekExtensions.cs b/src/Spectre.Console/Extensions/DayOfWeekExtensions.cs index 11377bc..607cab4 100644 --- a/src/Spectre.Console/Extensions/DayOfWeekExtensions.cs +++ b/src/Spectre.Console/Extensions/DayOfWeekExtensions.cs @@ -1,6 +1,3 @@ -using System; -using System.Globalization; - namespace Spectre.Console; internal static class DayOfWeekExtensions diff --git a/src/Spectre.Console/Extensions/DictionaryExtensions.cs b/src/Spectre.Console/Extensions/DictionaryExtensions.cs index 4f87502..d4c2d57 100644 --- a/src/Spectre.Console/Extensions/DictionaryExtensions.cs +++ b/src/Spectre.Console/Extensions/DictionaryExtensions.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console; internal static class DictionaryExtensions diff --git a/src/Spectre.Console/Extensions/EnumerableExtensions.cs b/src/Spectre.Console/Extensions/EnumerableExtensions.cs index 2eb8442..ba43319 100644 --- a/src/Spectre.Console/Extensions/EnumerableExtensions.cs +++ b/src/Spectre.Console/Extensions/EnumerableExtensions.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - namespace Spectre.Console; internal static class EnumerableExtensions diff --git a/src/Spectre.Console/Extensions/ExceptionExtensions.cs b/src/Spectre.Console/Extensions/ExceptionExtensions.cs index 1977061..29e1f07 100644 --- a/src/Spectre.Console/Extensions/ExceptionExtensions.cs +++ b/src/Spectre.Console/Extensions/ExceptionExtensions.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/ExpandableExtensions.cs b/src/Spectre.Console/Extensions/ExpandableExtensions.cs index 18acf8c..ca72b82 100644 --- a/src/Spectre.Console/Extensions/ExpandableExtensions.cs +++ b/src/Spectre.Console/Extensions/ExpandableExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/FigletTextExtensions.cs b/src/Spectre.Console/Extensions/FigletTextExtensions.cs index f6b4375..e789d91 100644 --- a/src/Spectre.Console/Extensions/FigletTextExtensions.cs +++ b/src/Spectre.Console/Extensions/FigletTextExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/GridExtensions.cs b/src/Spectre.Console/Extensions/GridExtensions.cs index 494677d..d9cbcb5 100644 --- a/src/Spectre.Console/Extensions/GridExtensions.cs +++ b/src/Spectre.Console/Extensions/GridExtensions.cs @@ -1,7 +1,3 @@ -using System; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/HasBorderExtensions.cs b/src/Spectre.Console/Extensions/HasBorderExtensions.cs index 1ebed1d..460a942 100644 --- a/src/Spectre.Console/Extensions/HasBorderExtensions.cs +++ b/src/Spectre.Console/Extensions/HasBorderExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/HasBoxBorderExtensions.cs b/src/Spectre.Console/Extensions/HasBoxBorderExtensions.cs index 3d7354e..a79f981 100644 --- a/src/Spectre.Console/Extensions/HasBoxBorderExtensions.cs +++ b/src/Spectre.Console/Extensions/HasBoxBorderExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/HasCultureExtensions.cs b/src/Spectre.Console/Extensions/HasCultureExtensions.cs index 53e7911..32d05bd 100644 --- a/src/Spectre.Console/Extensions/HasCultureExtensions.cs +++ b/src/Spectre.Console/Extensions/HasCultureExtensions.cs @@ -1,6 +1,3 @@ -using System; -using System.Globalization; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/HasTableBorderExtensions.cs b/src/Spectre.Console/Extensions/HasTableBorderExtensions.cs index 3aba4ad..fc5705a 100644 --- a/src/Spectre.Console/Extensions/HasTableBorderExtensions.cs +++ b/src/Spectre.Console/Extensions/HasTableBorderExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/HasTreeNodeExtensions.cs b/src/Spectre.Console/Extensions/HasTreeNodeExtensions.cs index 7a8bbd0..ae2f803 100644 --- a/src/Spectre.Console/Extensions/HasTreeNodeExtensions.cs +++ b/src/Spectre.Console/Extensions/HasTreeNodeExtensions.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/ListExtensions.cs b/src/Spectre.Console/Extensions/ListExtensions.cs index 87d7252..2a7862c 100644 --- a/src/Spectre.Console/Extensions/ListExtensions.cs +++ b/src/Spectre.Console/Extensions/ListExtensions.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace Spectre.Console; internal static class ListExtensions diff --git a/src/Spectre.Console/Extensions/LiveDisplayExtensions.cs b/src/Spectre.Console/Extensions/LiveDisplayExtensions.cs index 69c02e8..123da4d 100644 --- a/src/Spectre.Console/Extensions/LiveDisplayExtensions.cs +++ b/src/Spectre.Console/Extensions/LiveDisplayExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/OverflowableExtensions.cs b/src/Spectre.Console/Extensions/OverflowableExtensions.cs index 0fe33be..a8a47f2 100644 --- a/src/Spectre.Console/Extensions/OverflowableExtensions.cs +++ b/src/Spectre.Console/Extensions/OverflowableExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/PaddableExtensions.cs b/src/Spectre.Console/Extensions/PaddableExtensions.cs index 6ee787c..7cc01ad 100644 --- a/src/Spectre.Console/Extensions/PaddableExtensions.cs +++ b/src/Spectre.Console/Extensions/PaddableExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/PanelExtensions.cs b/src/Spectre.Console/Extensions/PanelExtensions.cs index 7475bfc..cc957e4 100644 --- a/src/Spectre.Console/Extensions/PanelExtensions.cs +++ b/src/Spectre.Console/Extensions/PanelExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/Progress/PercentageColumnExtensions.cs b/src/Spectre.Console/Extensions/Progress/PercentageColumnExtensions.cs index eae9e11..bd365a2 100644 --- a/src/Spectre.Console/Extensions/Progress/PercentageColumnExtensions.cs +++ b/src/Spectre.Console/Extensions/Progress/PercentageColumnExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/Progress/ProgressBarColumnExtensions.cs b/src/Spectre.Console/Extensions/Progress/ProgressBarColumnExtensions.cs index 314621a..4d46d0e 100644 --- a/src/Spectre.Console/Extensions/Progress/ProgressBarColumnExtensions.cs +++ b/src/Spectre.Console/Extensions/Progress/ProgressBarColumnExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/Progress/ProgressExtensions.cs b/src/Spectre.Console/Extensions/Progress/ProgressExtensions.cs index 14ee9de..58672d3 100644 --- a/src/Spectre.Console/Extensions/Progress/ProgressExtensions.cs +++ b/src/Spectre.Console/Extensions/Progress/ProgressExtensions.cs @@ -1,6 +1,3 @@ -using System; -using System.Linq; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/Progress/ProgressTaskExtensions.cs b/src/Spectre.Console/Extensions/Progress/ProgressTaskExtensions.cs index 5bf6b43..309ee86 100644 --- a/src/Spectre.Console/Extensions/Progress/ProgressTaskExtensions.cs +++ b/src/Spectre.Console/Extensions/Progress/ProgressTaskExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/Progress/RemainingTimeColumnExtensions.cs b/src/Spectre.Console/Extensions/Progress/RemainingTimeColumnExtensions.cs index c33b994..a542b75 100644 --- a/src/Spectre.Console/Extensions/Progress/RemainingTimeColumnExtensions.cs +++ b/src/Spectre.Console/Extensions/Progress/RemainingTimeColumnExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/Progress/SpinnerColumnExtensions.cs b/src/Spectre.Console/Extensions/Progress/SpinnerColumnExtensions.cs index 8c4ea16..fcfeed2 100644 --- a/src/Spectre.Console/Extensions/Progress/SpinnerColumnExtensions.cs +++ b/src/Spectre.Console/Extensions/Progress/SpinnerColumnExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/Progress/StatusContextExtensions.cs b/src/Spectre.Console/Extensions/Progress/StatusContextExtensions.cs index 7e73b95..6edcbb4 100644 --- a/src/Spectre.Console/Extensions/Progress/StatusContextExtensions.cs +++ b/src/Spectre.Console/Extensions/Progress/StatusContextExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/Progress/StatusExtensions.cs b/src/Spectre.Console/Extensions/Progress/StatusExtensions.cs index bc88c22..9b5c9e2 100644 --- a/src/Spectre.Console/Extensions/Progress/StatusExtensions.cs +++ b/src/Spectre.Console/Extensions/Progress/StatusExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/RecorderExtensions.cs b/src/Spectre.Console/Extensions/RecorderExtensions.cs index f9a6230..459a2ec 100644 --- a/src/Spectre.Console/Extensions/RecorderExtensions.cs +++ b/src/Spectre.Console/Extensions/RecorderExtensions.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Internal; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/RenderableExtensions.cs b/src/Spectre.Console/Extensions/RenderableExtensions.cs index 73d6c4b..9e72be9 100644 --- a/src/Spectre.Console/Extensions/RenderableExtensions.cs +++ b/src/Spectre.Console/Extensions/RenderableExtensions.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/RuleExtensions.cs b/src/Spectre.Console/Extensions/RuleExtensions.cs index fff2863..02d474f 100644 --- a/src/Spectre.Console/Extensions/RuleExtensions.cs +++ b/src/Spectre.Console/Extensions/RuleExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/StackExtensions.cs b/src/Spectre.Console/Extensions/StackExtensions.cs index afac5fe..a25143e 100644 --- a/src/Spectre.Console/Extensions/StackExtensions.cs +++ b/src/Spectre.Console/Extensions/StackExtensions.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace Spectre.Console; internal static class StackExtensions diff --git a/src/Spectre.Console/Extensions/StringBuilderExtensions.cs b/src/Spectre.Console/Extensions/StringBuilderExtensions.cs index 97448da..3c91e50 100644 --- a/src/Spectre.Console/Extensions/StringBuilderExtensions.cs +++ b/src/Spectre.Console/Extensions/StringBuilderExtensions.cs @@ -1,7 +1,3 @@ -using System; -using System.Globalization; -using System.Text; - namespace Spectre.Console; internal static class StringBuilderExtensions diff --git a/src/Spectre.Console/Extensions/StringExtensions.cs b/src/Spectre.Console/Extensions/StringExtensions.cs index 85df022..a14dd00 100644 --- a/src/Spectre.Console/Extensions/StringExtensions.cs +++ b/src/Spectre.Console/Extensions/StringExtensions.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/StyleExtensions.cs b/src/Spectre.Console/Extensions/StyleExtensions.cs index 232cd14..1ddc433 100644 --- a/src/Spectre.Console/Extensions/StyleExtensions.cs +++ b/src/Spectre.Console/Extensions/StyleExtensions.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/TableBorderExtensions.cs b/src/Spectre.Console/Extensions/TableBorderExtensions.cs index 6aeb463..eb91b34 100644 --- a/src/Spectre.Console/Extensions/TableBorderExtensions.cs +++ b/src/Spectre.Console/Extensions/TableBorderExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Extensions/TableColumnExtensions.cs b/src/Spectre.Console/Extensions/TableColumnExtensions.cs index c69035b..092e32b 100644 --- a/src/Spectre.Console/Extensions/TableColumnExtensions.cs +++ b/src/Spectre.Console/Extensions/TableColumnExtensions.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/TableExtensions.cs b/src/Spectre.Console/Extensions/TableExtensions.cs index 2d4147e..e232e64 100644 --- a/src/Spectre.Console/Extensions/TableExtensions.cs +++ b/src/Spectre.Console/Extensions/TableExtensions.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/TextWriterExtensions.cs b/src/Spectre.Console/Extensions/TextWriterExtensions.cs index d213aba..ee77262 100644 --- a/src/Spectre.Console/Extensions/TextWriterExtensions.cs +++ b/src/Spectre.Console/Extensions/TextWriterExtensions.cs @@ -1,5 +1,3 @@ -using System.IO; - namespace Spectre.Console; internal static class TextWriterExtensions diff --git a/src/Spectre.Console/Extensions/TreeExtensions.cs b/src/Spectre.Console/Extensions/TreeExtensions.cs index c5b64b1..06e4bca 100644 --- a/src/Spectre.Console/Extensions/TreeExtensions.cs +++ b/src/Spectre.Console/Extensions/TreeExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Extensions/TreeGuideExtensions.cs b/src/Spectre.Console/Extensions/TreeGuideExtensions.cs index d48c78f..3ee8040 100644 --- a/src/Spectre.Console/Extensions/TreeGuideExtensions.cs +++ b/src/Spectre.Console/Extensions/TreeGuideExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Extensions/TreeNodeExtensions.cs b/src/Spectre.Console/Extensions/TreeNodeExtensions.cs index 896c87c..bcc39e9 100644 --- a/src/Spectre.Console/Extensions/TreeNodeExtensions.cs +++ b/src/Spectre.Console/Extensions/TreeNodeExtensions.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/IAnsiConsole.cs b/src/Spectre.Console/IAnsiConsole.cs index d718156..da40c50 100644 --- a/src/Spectre.Console/IAnsiConsole.cs +++ b/src/Spectre.Console/IAnsiConsole.cs @@ -1,5 +1,3 @@ -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/IAnsiConsoleInput.cs b/src/Spectre.Console/IAnsiConsoleInput.cs index b6a3beb..9bc5a12 100644 --- a/src/Spectre.Console/IAnsiConsoleInput.cs +++ b/src/Spectre.Console/IAnsiConsoleInput.cs @@ -1,7 +1,3 @@ -using System; -using System.Threading; -using System.Threading.Tasks; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/IAnsiConsoleOutput.cs b/src/Spectre.Console/IAnsiConsoleOutput.cs index 0ce965a..2c7861c 100644 --- a/src/Spectre.Console/IAnsiConsoleOutput.cs +++ b/src/Spectre.Console/IAnsiConsoleOutput.cs @@ -1,6 +1,3 @@ -using System.IO; -using System.Text; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/IExclusivityMode.cs b/src/Spectre.Console/IExclusivityMode.cs index 6d5abef..77b034b 100644 --- a/src/Spectre.Console/IExclusivityMode.cs +++ b/src/Spectre.Console/IExclusivityMode.cs @@ -1,6 +1,3 @@ -using System; -using System.Threading.Tasks; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/IHasCulture.cs b/src/Spectre.Console/IHasCulture.cs index f2efe42..96b9249 100644 --- a/src/Spectre.Console/IHasCulture.cs +++ b/src/Spectre.Console/IHasCulture.cs @@ -1,5 +1,3 @@ -using System.Globalization; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/IHasTreeNodes.cs b/src/Spectre.Console/IHasTreeNodes.cs index c0f28d3..c06367c 100644 --- a/src/Spectre.Console/IHasTreeNodes.cs +++ b/src/Spectre.Console/IHasTreeNodes.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/IProfileEnricher.cs b/src/Spectre.Console/IProfileEnricher.cs index 9ad9bc8..5fbbce7 100644 --- a/src/Spectre.Console/IProfileEnricher.cs +++ b/src/Spectre.Console/IProfileEnricher.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/IReadOnlyCapabilities.cs b/src/Spectre.Console/IReadOnlyCapabilities.cs index 7039886..d8b30ab 100644 --- a/src/Spectre.Console/IReadOnlyCapabilities.cs +++ b/src/Spectre.Console/IReadOnlyCapabilities.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/IRenderable.cs b/src/Spectre.Console/IRenderable.cs index 042023a..af27d38 100644 --- a/src/Spectre.Console/IRenderable.cs +++ b/src/Spectre.Console/IRenderable.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Internal/Aligner.cs b/src/Spectre.Console/Internal/Aligner.cs index 0a72582..97cda49 100644 --- a/src/Spectre.Console/Internal/Aligner.cs +++ b/src/Spectre.Console/Internal/Aligner.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using Spectre.Console.Rendering; - namespace Spectre.Console; internal static class Aligner diff --git a/src/Spectre.Console/Internal/Backends/Ansi/AnsiBuilder.cs b/src/Spectre.Console/Internal/Backends/Ansi/AnsiBuilder.cs index 36fcf49..a48722f 100644 --- a/src/Spectre.Console/Internal/Backends/Ansi/AnsiBuilder.cs +++ b/src/Spectre.Console/Internal/Backends/Ansi/AnsiBuilder.cs @@ -1,7 +1,3 @@ -using System; -using System.Linq; -using System.Text; -using Spectre.Console.Rendering; using static Spectre.Console.AnsiSequences; namespace Spectre.Console; diff --git a/src/Spectre.Console/Internal/Backends/Ansi/AnsiColorBuilder.cs b/src/Spectre.Console/Internal/Backends/Ansi/AnsiColorBuilder.cs index e7f7ea4..0b698e3 100644 --- a/src/Spectre.Console/Internal/Backends/Ansi/AnsiColorBuilder.cs +++ b/src/Spectre.Console/Internal/Backends/Ansi/AnsiColorBuilder.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; - namespace Spectre.Console; internal static class AnsiColorBuilder diff --git a/src/Spectre.Console/Internal/Backends/Ansi/AnsiConsoleBackend.cs b/src/Spectre.Console/Internal/Backends/Ansi/AnsiConsoleBackend.cs index c4f29a4..db29b49 100644 --- a/src/Spectre.Console/Internal/Backends/Ansi/AnsiConsoleBackend.cs +++ b/src/Spectre.Console/Internal/Backends/Ansi/AnsiConsoleBackend.cs @@ -1,5 +1,3 @@ -using System; -using Spectre.Console.Rendering; using static Spectre.Console.AnsiSequences; namespace Spectre.Console; diff --git a/src/Spectre.Console/Internal/Backends/Ansi/AnsiConsoleCursor.cs b/src/Spectre.Console/Internal/Backends/Ansi/AnsiConsoleCursor.cs index 12453ec..bbc3086 100644 --- a/src/Spectre.Console/Internal/Backends/Ansi/AnsiConsoleCursor.cs +++ b/src/Spectre.Console/Internal/Backends/Ansi/AnsiConsoleCursor.cs @@ -1,4 +1,3 @@ -using System; using static Spectre.Console.AnsiSequences; namespace Spectre.Console; diff --git a/src/Spectre.Console/Internal/Backends/Ansi/AnsiDecorationBuilder.cs b/src/Spectre.Console/Internal/Backends/Ansi/AnsiDecorationBuilder.cs index e43ee93..ab7dbde 100644 --- a/src/Spectre.Console/Internal/Backends/Ansi/AnsiDecorationBuilder.cs +++ b/src/Spectre.Console/Internal/Backends/Ansi/AnsiDecorationBuilder.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console; internal static class AnsiDecorationBuilder diff --git a/src/Spectre.Console/Internal/Backends/Ansi/AnsiDetector.cs b/src/Spectre.Console/Internal/Backends/Ansi/AnsiDetector.cs index 5c7b8f7..58c512b 100644 --- a/src/Spectre.Console/Internal/Backends/Ansi/AnsiDetector.cs +++ b/src/Spectre.Console/Internal/Backends/Ansi/AnsiDetector.cs @@ -1,9 +1,3 @@ -using System; -using System.Diagnostics.CodeAnalysis; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text.RegularExpressions; - ///////////////////////////////////////////////////////////////////////////////////////////////////// // Portions of this code was ported from the supports-ansi project by Qingrong Ke // https://github.com/keqingrong/supports-ansi/blob/master/index.js diff --git a/src/Spectre.Console/Internal/Backends/Ansi/AnsiLinkHasher.cs b/src/Spectre.Console/Internal/Backends/Ansi/AnsiLinkHasher.cs index 664184a..d8a314e 100644 --- a/src/Spectre.Console/Internal/Backends/Ansi/AnsiLinkHasher.cs +++ b/src/Spectre.Console/Internal/Backends/Ansi/AnsiLinkHasher.cs @@ -1,6 +1,3 @@ -using System; -using System.Runtime.CompilerServices; - namespace Spectre.Console; internal sealed class AnsiLinkHasher diff --git a/src/Spectre.Console/Internal/Backends/Ansi/AnsiSequences.cs b/src/Spectre.Console/Internal/Backends/Ansi/AnsiSequences.cs index 4dfdb71..6eeadf6 100644 --- a/src/Spectre.Console/Internal/Backends/Ansi/AnsiSequences.cs +++ b/src/Spectre.Console/Internal/Backends/Ansi/AnsiSequences.cs @@ -1,5 +1,3 @@ -using System.Linq; - namespace Spectre.Console; internal static class AnsiSequences diff --git a/src/Spectre.Console/Internal/Backends/AnsiConsoleFacade.cs b/src/Spectre.Console/Internal/Backends/AnsiConsoleFacade.cs index b617521..d8ef656 100644 --- a/src/Spectre.Console/Internal/Backends/AnsiConsoleFacade.cs +++ b/src/Spectre.Console/Internal/Backends/AnsiConsoleFacade.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Rendering; - namespace Spectre.Console; internal sealed class AnsiConsoleFacade : IAnsiConsole diff --git a/src/Spectre.Console/Internal/Backends/IAnsiConsoleBackend.cs b/src/Spectre.Console/Internal/Backends/IAnsiConsoleBackend.cs index 92308b4..3569ee7 100644 --- a/src/Spectre.Console/Internal/Backends/IAnsiConsoleBackend.cs +++ b/src/Spectre.Console/Internal/Backends/IAnsiConsoleBackend.cs @@ -1,5 +1,3 @@ -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Internal/Backends/Legacy/LegacyConsoleBackend.cs b/src/Spectre.Console/Internal/Backends/Legacy/LegacyConsoleBackend.cs index 5a2c00c..026f96c 100644 --- a/src/Spectre.Console/Internal/Backends/Legacy/LegacyConsoleBackend.cs +++ b/src/Spectre.Console/Internal/Backends/Legacy/LegacyConsoleBackend.cs @@ -1,5 +1,3 @@ -using Spectre.Console.Rendering; - namespace Spectre.Console; internal sealed class LegacyConsoleBackend : IAnsiConsoleBackend diff --git a/src/Spectre.Console/Internal/Cell.cs b/src/Spectre.Console/Internal/Cell.cs index 88dfbea..b79e7e5 100644 --- a/src/Spectre.Console/Internal/Cell.cs +++ b/src/Spectre.Console/Internal/Cell.cs @@ -1,5 +1,3 @@ -using Wcwidth; - namespace Spectre.Console; internal static class Cell diff --git a/src/Spectre.Console/Internal/Collections/ListWithCallback.cs b/src/Spectre.Console/Internal/Collections/ListWithCallback.cs index 9299e6e..830d92f 100644 --- a/src/Spectre.Console/Internal/Collections/ListWithCallback.cs +++ b/src/Spectre.Console/Internal/Collections/ListWithCallback.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections; -using System.Collections.Generic; - namespace Spectre.Console; internal sealed class ListWithCallback : IList, IReadOnlyList diff --git a/src/Spectre.Console/Internal/Colors/ColorPalette.cs b/src/Spectre.Console/Internal/Colors/ColorPalette.cs index f50f3ca..3e5e835 100644 --- a/src/Spectre.Console/Internal/Colors/ColorPalette.cs +++ b/src/Spectre.Console/Internal/Colors/ColorPalette.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - namespace Spectre.Console; internal static partial class ColorPalette diff --git a/src/Spectre.Console/Internal/Colors/ColorSystemDetector.cs b/src/Spectre.Console/Internal/Colors/ColorSystemDetector.cs index 748d5e9..67d8c71 100644 --- a/src/Spectre.Console/Internal/Colors/ColorSystemDetector.cs +++ b/src/Spectre.Console/Internal/Colors/ColorSystemDetector.cs @@ -1,6 +1,3 @@ -using System; -using System.Runtime.InteropServices; - namespace Spectre.Console; internal static class ColorSystemDetector diff --git a/src/Spectre.Console/Internal/Colors/ColorTable.cs b/src/Spectre.Console/Internal/Colors/ColorTable.cs index f358620..4fc7292 100644 --- a/src/Spectre.Console/Internal/Colors/ColorTable.cs +++ b/src/Spectre.Console/Internal/Colors/ColorTable.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace Spectre.Console; internal static partial class ColorTable diff --git a/src/Spectre.Console/Internal/ConsoleHelper.cs b/src/Spectre.Console/Internal/ConsoleHelper.cs index bfe757e..943b1da 100644 --- a/src/Spectre.Console/Internal/ConsoleHelper.cs +++ b/src/Spectre.Console/Internal/ConsoleHelper.cs @@ -1,5 +1,3 @@ -using System.IO; - namespace Spectre.Console; internal static class ConsoleHelper diff --git a/src/Spectre.Console/Internal/DecorationTable.cs b/src/Spectre.Console/Internal/DecorationTable.cs index 3d72d40..9871e29 100644 --- a/src/Spectre.Console/Internal/DecorationTable.cs +++ b/src/Spectre.Console/Internal/DecorationTable.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - namespace Spectre.Console; internal static class DecorationTable diff --git a/src/Spectre.Console/Internal/DefaultExclusivityMode.cs b/src/Spectre.Console/Internal/DefaultExclusivityMode.cs index 0dcac36..c928af2 100644 --- a/src/Spectre.Console/Internal/DefaultExclusivityMode.cs +++ b/src/Spectre.Console/Internal/DefaultExclusivityMode.cs @@ -1,7 +1,3 @@ -using System; -using System.Threading; -using System.Threading.Tasks; - namespace Spectre.Console.Internal; internal sealed class DefaultExclusivityMode : IExclusivityMode diff --git a/src/Spectre.Console/Internal/DefaultInput.cs b/src/Spectre.Console/Internal/DefaultInput.cs index 325fcf5..423285c 100644 --- a/src/Spectre.Console/Internal/DefaultInput.cs +++ b/src/Spectre.Console/Internal/DefaultInput.cs @@ -1,7 +1,3 @@ -using System; -using System.Threading; -using System.Threading.Tasks; - namespace Spectre.Console; internal sealed class DefaultInput : IAnsiConsoleInput diff --git a/src/Spectre.Console/Internal/FileSize.cs b/src/Spectre.Console/Internal/FileSize.cs index 1419add..4a8254a 100644 --- a/src/Spectre.Console/Internal/FileSize.cs +++ b/src/Spectre.Console/Internal/FileSize.cs @@ -1,6 +1,3 @@ -using System; -using System.Globalization; - namespace Spectre.Console; internal struct FileSize diff --git a/src/Spectre.Console/Internal/Ratio.cs b/src/Spectre.Console/Internal/Ratio.cs index 607d555..a0f3fc9 100644 --- a/src/Spectre.Console/Internal/Ratio.cs +++ b/src/Spectre.Console/Internal/Ratio.cs @@ -1,11 +1,6 @@ // Ported from Rich by Will McGugan, licensed under MIT. // https://github.com/willmcgugan/rich/blob/527475837ebbfc427530b3ee0d4d0741d2d0fc6d/rich/_ratio.py -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; - namespace Spectre.Console; internal static class Ratio diff --git a/src/Spectre.Console/Internal/ResourceReader.cs b/src/Spectre.Console/Internal/ResourceReader.cs index eb830fe..f1bca5e 100644 --- a/src/Spectre.Console/Internal/ResourceReader.cs +++ b/src/Spectre.Console/Internal/ResourceReader.cs @@ -1,6 +1,3 @@ -using System; -using System.IO; - namespace Spectre.Console; internal static class ResourceReader diff --git a/src/Spectre.Console/Internal/Text/Encoding/HtmlEncoder.cs b/src/Spectre.Console/Internal/Text/Encoding/HtmlEncoder.cs index 508073d..d021e26 100644 --- a/src/Spectre.Console/Internal/Text/Encoding/HtmlEncoder.cs +++ b/src/Spectre.Console/Internal/Text/Encoding/HtmlEncoder.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Spectre.Console.Rendering; - namespace Spectre.Console.Internal; internal sealed class HtmlEncoder : IAnsiConsoleEncoder diff --git a/src/Spectre.Console/Internal/Text/Encoding/TextEncoder.cs b/src/Spectre.Console/Internal/Text/Encoding/TextEncoder.cs index 777095c..ac2bc61 100644 --- a/src/Spectre.Console/Internal/Text/Encoding/TextEncoder.cs +++ b/src/Spectre.Console/Internal/Text/Encoding/TextEncoder.cs @@ -1,7 +1,3 @@ -using System.Collections.Generic; -using System.Text; -using Spectre.Console.Rendering; - namespace Spectre.Console.Internal; internal sealed class TextEncoder : IAnsiConsoleEncoder diff --git a/src/Spectre.Console/Internal/Text/Markup/MarkupParser.cs b/src/Spectre.Console/Internal/Text/Markup/MarkupParser.cs index 03f6f91..cc46464 100644 --- a/src/Spectre.Console/Internal/Text/Markup/MarkupParser.cs +++ b/src/Spectre.Console/Internal/Text/Markup/MarkupParser.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - namespace Spectre.Console; internal static class MarkupParser diff --git a/src/Spectre.Console/Internal/Text/Markup/MarkupToken.cs b/src/Spectre.Console/Internal/Text/Markup/MarkupToken.cs index 47c7a40..13e0a46 100644 --- a/src/Spectre.Console/Internal/Text/Markup/MarkupToken.cs +++ b/src/Spectre.Console/Internal/Text/Markup/MarkupToken.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; internal sealed class MarkupToken diff --git a/src/Spectre.Console/Internal/Text/Markup/MarkupTokenizer.cs b/src/Spectre.Console/Internal/Text/Markup/MarkupTokenizer.cs index 3c1763f..c2fc8e1 100644 --- a/src/Spectre.Console/Internal/Text/Markup/MarkupTokenizer.cs +++ b/src/Spectre.Console/Internal/Text/Markup/MarkupTokenizer.cs @@ -1,6 +1,3 @@ -using System; -using System.Text; - namespace Spectre.Console; internal sealed class MarkupTokenizer : IDisposable diff --git a/src/Spectre.Console/Internal/Text/StringBuffer.cs b/src/Spectre.Console/Internal/Text/StringBuffer.cs index e529a1e..61a189f 100644 --- a/src/Spectre.Console/Internal/Text/StringBuffer.cs +++ b/src/Spectre.Console/Internal/Text/StringBuffer.cs @@ -1,6 +1,3 @@ -using System; -using System.IO; - namespace Spectre.Console; internal sealed class StringBuffer : IDisposable diff --git a/src/Spectre.Console/Internal/TypeConverterHelper.cs b/src/Spectre.Console/Internal/TypeConverterHelper.cs index 1cc579b..0b4fc24 100644 --- a/src/Spectre.Console/Internal/TypeConverterHelper.cs +++ b/src/Spectre.Console/Internal/TypeConverterHelper.cs @@ -1,8 +1,3 @@ -using System; -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; -using System.Reflection; - namespace Spectre.Console; internal static class TypeConverterHelper diff --git a/src/Spectre.Console/Live/LiveDisplay.cs b/src/Spectre.Console/Live/LiveDisplay.cs index c3ead5e..7331fff 100644 --- a/src/Spectre.Console/Live/LiveDisplay.cs +++ b/src/Spectre.Console/Live/LiveDisplay.cs @@ -1,7 +1,3 @@ -using System; -using System.Threading.Tasks; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Live/LiveDisplayContext.cs b/src/Spectre.Console/Live/LiveDisplayContext.cs index a2d7114..93a211b 100644 --- a/src/Spectre.Console/Live/LiveDisplayContext.cs +++ b/src/Spectre.Console/Live/LiveDisplayContext.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Live/LiveDisplayRenderer.cs b/src/Spectre.Console/Live/LiveDisplayRenderer.cs index 817c009..3a95df1 100644 --- a/src/Spectre.Console/Live/LiveDisplayRenderer.cs +++ b/src/Spectre.Console/Live/LiveDisplayRenderer.cs @@ -1,6 +1,3 @@ -using System.Collections.Generic; -using Spectre.Console.Rendering; - namespace Spectre.Console; internal sealed class LiveDisplayRenderer : IRenderHook diff --git a/src/Spectre.Console/Live/LiveRenderable.cs b/src/Spectre.Console/Live/LiveRenderable.cs index ffd3557..9152540 100644 --- a/src/Spectre.Console/Live/LiveRenderable.cs +++ b/src/Spectre.Console/Live/LiveRenderable.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using static Spectre.Console.AnsiSequences; namespace Spectre.Console.Rendering; diff --git a/src/Spectre.Console/Live/Progress/Columns/DownloadedColumn.cs b/src/Spectre.Console/Live/Progress/Columns/DownloadedColumn.cs index 6b8029b..fa8e496 100644 --- a/src/Spectre.Console/Live/Progress/Columns/DownloadedColumn.cs +++ b/src/Spectre.Console/Live/Progress/Columns/DownloadedColumn.cs @@ -1,7 +1,3 @@ -using System; -using System.Globalization; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Live/Progress/Columns/ElapsedTimeColumn.cs b/src/Spectre.Console/Live/Progress/Columns/ElapsedTimeColumn.cs index 2e8d957..a005be6 100644 --- a/src/Spectre.Console/Live/Progress/Columns/ElapsedTimeColumn.cs +++ b/src/Spectre.Console/Live/Progress/Columns/ElapsedTimeColumn.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Live/Progress/Columns/PercentageColumn.cs b/src/Spectre.Console/Live/Progress/Columns/PercentageColumn.cs index 9c964c8..f0bf597 100644 --- a/src/Spectre.Console/Live/Progress/Columns/PercentageColumn.cs +++ b/src/Spectre.Console/Live/Progress/Columns/PercentageColumn.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Live/Progress/Columns/ProgressBarColumn.cs b/src/Spectre.Console/Live/Progress/Columns/ProgressBarColumn.cs index 0a656b1..7b0b018 100644 --- a/src/Spectre.Console/Live/Progress/Columns/ProgressBarColumn.cs +++ b/src/Spectre.Console/Live/Progress/Columns/ProgressBarColumn.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Live/Progress/Columns/RemainingTimeColumn.cs b/src/Spectre.Console/Live/Progress/Columns/RemainingTimeColumn.cs index 50cf4cc..49aeae5 100644 --- a/src/Spectre.Console/Live/Progress/Columns/RemainingTimeColumn.cs +++ b/src/Spectre.Console/Live/Progress/Columns/RemainingTimeColumn.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Live/Progress/Columns/SpinnerColumn.cs b/src/Spectre.Console/Live/Progress/Columns/SpinnerColumn.cs index 61ae5ed..429d484 100644 --- a/src/Spectre.Console/Live/Progress/Columns/SpinnerColumn.cs +++ b/src/Spectre.Console/Live/Progress/Columns/SpinnerColumn.cs @@ -1,7 +1,3 @@ -using System; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Live/Progress/Columns/TaskDescriptionColumn.cs b/src/Spectre.Console/Live/Progress/Columns/TaskDescriptionColumn.cs index b966e4a..b6ffb0d 100644 --- a/src/Spectre.Console/Live/Progress/Columns/TaskDescriptionColumn.cs +++ b/src/Spectre.Console/Live/Progress/Columns/TaskDescriptionColumn.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Live/Progress/Columns/TransferSpeedColumn.cs b/src/Spectre.Console/Live/Progress/Columns/TransferSpeedColumn.cs index 1417bdf..7e6e783 100644 --- a/src/Spectre.Console/Live/Progress/Columns/TransferSpeedColumn.cs +++ b/src/Spectre.Console/Live/Progress/Columns/TransferSpeedColumn.cs @@ -1,7 +1,3 @@ -using System; -using System.Globalization; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Live/Progress/Progress.cs b/src/Spectre.Console/Live/Progress/Progress.cs index c7e3d86..b183990 100644 --- a/src/Spectre.Console/Live/Progress/Progress.cs +++ b/src/Spectre.Console/Live/Progress/Progress.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Live/Progress/ProgressColumn.cs b/src/Spectre.Console/Live/Progress/ProgressColumn.cs index c2c854a..2aa593d 100644 --- a/src/Spectre.Console/Live/Progress/ProgressColumn.cs +++ b/src/Spectre.Console/Live/Progress/ProgressColumn.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Live/Progress/ProgressContext.cs b/src/Spectre.Console/Live/Progress/ProgressContext.cs index 90aaeb9..4603bc9 100644 --- a/src/Spectre.Console/Live/Progress/ProgressContext.cs +++ b/src/Spectre.Console/Live/Progress/ProgressContext.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Live/Progress/ProgressRefreshThread.cs b/src/Spectre.Console/Live/Progress/ProgressRefreshThread.cs index 65474ae..163917e 100644 --- a/src/Spectre.Console/Live/Progress/ProgressRefreshThread.cs +++ b/src/Spectre.Console/Live/Progress/ProgressRefreshThread.cs @@ -1,6 +1,3 @@ -using System; -using System.Threading; - namespace Spectre.Console; internal sealed class ProgressRefreshThread : IDisposable diff --git a/src/Spectre.Console/Live/Progress/ProgressRenderer.cs b/src/Spectre.Console/Live/Progress/ProgressRenderer.cs index 8b083c7..598ce5a 100644 --- a/src/Spectre.Console/Live/Progress/ProgressRenderer.cs +++ b/src/Spectre.Console/Live/Progress/ProgressRenderer.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using Spectre.Console.Rendering; - namespace Spectre.Console; internal abstract class ProgressRenderer : IRenderHook diff --git a/src/Spectre.Console/Live/Progress/ProgressSample.cs b/src/Spectre.Console/Live/Progress/ProgressSample.cs index d192f78..e22e734 100644 --- a/src/Spectre.Console/Live/Progress/ProgressSample.cs +++ b/src/Spectre.Console/Live/Progress/ProgressSample.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; internal readonly struct ProgressSample diff --git a/src/Spectre.Console/Live/Progress/ProgressTask.cs b/src/Spectre.Console/Live/Progress/ProgressTask.cs index 419c229..c239de0 100644 --- a/src/Spectre.Console/Live/Progress/ProgressTask.cs +++ b/src/Spectre.Console/Live/Progress/ProgressTask.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Live/Progress/ProgressTaskState.cs b/src/Spectre.Console/Live/Progress/ProgressTaskState.cs index a3e0f14..9e1194e 100644 --- a/src/Spectre.Console/Live/Progress/ProgressTaskState.cs +++ b/src/Spectre.Console/Live/Progress/ProgressTaskState.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Live/Progress/Renderers/DefaultProgressRenderer.cs b/src/Spectre.Console/Live/Progress/Renderers/DefaultProgressRenderer.cs index 2b3504b..9715402 100644 --- a/src/Spectre.Console/Live/Progress/Renderers/DefaultProgressRenderer.cs +++ b/src/Spectre.Console/Live/Progress/Renderers/DefaultProgressRenderer.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; internal sealed class DefaultProgressRenderer : ProgressRenderer diff --git a/src/Spectre.Console/Live/Progress/Renderers/FallbackProgressRenderer.cs b/src/Spectre.Console/Live/Progress/Renderers/FallbackProgressRenderer.cs index fc962ff..90c54b3 100644 --- a/src/Spectre.Console/Live/Progress/Renderers/FallbackProgressRenderer.cs +++ b/src/Spectre.Console/Live/Progress/Renderers/FallbackProgressRenderer.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using Spectre.Console.Rendering; - namespace Spectre.Console; internal sealed class FallbackProgressRenderer : ProgressRenderer diff --git a/src/Spectre.Console/Live/Progress/Renderers/FallbackStatusRenderer.cs b/src/Spectre.Console/Live/Progress/Renderers/FallbackStatusRenderer.cs index d8a1bbf..f8f445e 100644 --- a/src/Spectre.Console/Live/Progress/Renderers/FallbackStatusRenderer.cs +++ b/src/Spectre.Console/Live/Progress/Renderers/FallbackStatusRenderer.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; internal sealed class FallbackStatusRenderer : ProgressRenderer diff --git a/src/Spectre.Console/Live/Progress/Spinner.cs b/src/Spectre.Console/Live/Progress/Spinner.cs index 505d411..45ce0a7 100644 --- a/src/Spectre.Console/Live/Progress/Spinner.cs +++ b/src/Spectre.Console/Live/Progress/Spinner.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Live/Status/Status.cs b/src/Spectre.Console/Live/Status/Status.cs index 10d9974..59a1115 100644 --- a/src/Spectre.Console/Live/Status/Status.cs +++ b/src/Spectre.Console/Live/Status/Status.cs @@ -1,6 +1,3 @@ -using System; -using System.Threading.Tasks; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Live/Status/StatusContext.cs b/src/Spectre.Console/Live/Status/StatusContext.cs index 63c50ec..1ccdd2e 100644 --- a/src/Spectre.Console/Live/Status/StatusContext.cs +++ b/src/Spectre.Console/Live/Status/StatusContext.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Padding.cs b/src/Spectre.Console/Padding.cs index 3695f4f..d97e563 100644 --- a/src/Spectre.Console/Padding.cs +++ b/src/Spectre.Console/Padding.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Profile.cs b/src/Spectre.Console/Profile.cs index 091644e..aa98ebe 100644 --- a/src/Spectre.Console/Profile.cs +++ b/src/Spectre.Console/Profile.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Text; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Prompts/ConfirmationPrompt.cs b/src/Spectre.Console/Prompts/ConfirmationPrompt.cs index 3ccccf0..9a17bd3 100644 --- a/src/Spectre.Console/Prompts/ConfirmationPrompt.cs +++ b/src/Spectre.Console/Prompts/ConfirmationPrompt.cs @@ -1,6 +1,3 @@ -using System.Threading; -using System.Threading.Tasks; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Prompts/IPrompt.cs b/src/Spectre.Console/Prompts/IPrompt.cs index 25f27d1..36ed44c 100644 --- a/src/Spectre.Console/Prompts/IPrompt.cs +++ b/src/Spectre.Console/Prompts/IPrompt.cs @@ -1,6 +1,3 @@ -using System.Threading; -using System.Threading.Tasks; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Prompts/List/IListPromptStrategy.cs b/src/Spectre.Console/Prompts/List/IListPromptStrategy.cs index 178bddd..4db8f7a 100644 --- a/src/Spectre.Console/Prompts/List/IListPromptStrategy.cs +++ b/src/Spectre.Console/Prompts/List/IListPromptStrategy.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Prompts/List/ListPrompt.cs b/src/Spectre.Console/Prompts/List/ListPrompt.cs index 28c78b0..fa0d758 100644 --- a/src/Spectre.Console/Prompts/List/ListPrompt.cs +++ b/src/Spectre.Console/Prompts/List/ListPrompt.cs @@ -1,9 +1,3 @@ -using System; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using Spectre.Console.Rendering; - namespace Spectre.Console; internal sealed class ListPrompt diff --git a/src/Spectre.Console/Prompts/List/ListPromptItem.cs b/src/Spectre.Console/Prompts/List/ListPromptItem.cs index 3c3f8e1..482b902 100644 --- a/src/Spectre.Console/Prompts/List/ListPromptItem.cs +++ b/src/Spectre.Console/Prompts/List/ListPromptItem.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console; internal sealed class ListPromptItem : IMultiSelectionItem diff --git a/src/Spectre.Console/Prompts/List/ListPromptRenderHook.cs b/src/Spectre.Console/Prompts/List/ListPromptRenderHook.cs index b2d07cf..53fa21f 100644 --- a/src/Spectre.Console/Prompts/List/ListPromptRenderHook.cs +++ b/src/Spectre.Console/Prompts/List/ListPromptRenderHook.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using Spectre.Console.Rendering; - namespace Spectre.Console; internal sealed class ListPromptRenderHook : IRenderHook diff --git a/src/Spectre.Console/Prompts/List/ListPromptState.cs b/src/Spectre.Console/Prompts/List/ListPromptState.cs index ce73f47..a653449 100644 --- a/src/Spectre.Console/Prompts/List/ListPromptState.cs +++ b/src/Spectre.Console/Prompts/List/ListPromptState.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace Spectre.Console; internal sealed class ListPromptState diff --git a/src/Spectre.Console/Prompts/List/ListPromptTree.cs b/src/Spectre.Console/Prompts/List/ListPromptTree.cs index 6bd3ba4..23e466a 100644 --- a/src/Spectre.Console/Prompts/List/ListPromptTree.cs +++ b/src/Spectre.Console/Prompts/List/ListPromptTree.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace Spectre.Console; internal sealed class ListPromptTree diff --git a/src/Spectre.Console/Prompts/MultiSelectionPrompt.cs b/src/Spectre.Console/Prompts/MultiSelectionPrompt.cs index c6b2687..baccc19 100644 --- a/src/Spectre.Console/Prompts/MultiSelectionPrompt.cs +++ b/src/Spectre.Console/Prompts/MultiSelectionPrompt.cs @@ -1,11 +1,3 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Prompts/MultiSelectionPromptExtensions.cs b/src/Spectre.Console/Prompts/MultiSelectionPromptExtensions.cs index cf9e8f7..9646b8f 100644 --- a/src/Spectre.Console/Prompts/MultiSelectionPromptExtensions.cs +++ b/src/Spectre.Console/Prompts/MultiSelectionPromptExtensions.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Prompts/SelectionPrompt.cs b/src/Spectre.Console/Prompts/SelectionPrompt.cs index 2e65f44..cf17253 100644 --- a/src/Spectre.Console/Prompts/SelectionPrompt.cs +++ b/src/Spectre.Console/Prompts/SelectionPrompt.cs @@ -1,10 +1,3 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Threading; -using System.Threading.Tasks; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Prompts/SelectionPromptExtensions.cs b/src/Spectre.Console/Prompts/SelectionPromptExtensions.cs index 4f57bc4..57cd8fe 100644 --- a/src/Spectre.Console/Prompts/SelectionPromptExtensions.cs +++ b/src/Spectre.Console/Prompts/SelectionPromptExtensions.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Prompts/TextPrompt.cs b/src/Spectre.Console/Prompts/TextPrompt.cs index 46010f1..ebe3fbb 100644 --- a/src/Spectre.Console/Prompts/TextPrompt.cs +++ b/src/Spectre.Console/Prompts/TextPrompt.cs @@ -1,13 +1,3 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Prompts/TextPromptExtensions.cs b/src/Spectre.Console/Prompts/TextPromptExtensions.cs index a9f20b1..318639f 100644 --- a/src/Spectre.Console/Prompts/TextPromptExtensions.cs +++ b/src/Spectre.Console/Prompts/TextPromptExtensions.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Properties/Usings.cs b/src/Spectre.Console/Properties/Usings.cs new file mode 100644 index 0000000..45e8172 --- /dev/null +++ b/src/Spectre.Console/Properties/Usings.cs @@ -0,0 +1,23 @@ +global using System; +global using System.Collections; +global using System.Collections.Generic; +global using System.ComponentModel; +global using System.Diagnostics; +global using System.Diagnostics.CodeAnalysis; +global using System.Globalization; +global using System.IO; +global using System.Linq; +global using System.Net; +global using System.Reflection; +global using System.Runtime.CompilerServices; +global using System.Runtime.InteropServices; +global using System.Text; +global using System.Text.RegularExpressions; +global using System.Threading; +global using System.Threading.Tasks; +global using System.Xml; +global using Spectre.Console.Cli.Unsafe; +global using Spectre.Console.Enrichment; +global using Spectre.Console.Internal; +global using Spectre.Console.Rendering; +global using Wcwidth; \ No newline at end of file diff --git a/src/Spectre.Console/Recorder.cs b/src/Spectre.Console/Recorder.cs index dc967b4..ab415da 100644 --- a/src/Spectre.Console/Recorder.cs +++ b/src/Spectre.Console/Recorder.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Rendering/Borders/Boxes/AsciiBoxBorder.cs b/src/Spectre.Console/Rendering/Borders/Boxes/AsciiBoxBorder.cs index ef98190..0a0ee28 100644 --- a/src/Spectre.Console/Rendering/Borders/Boxes/AsciiBoxBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Boxes/AsciiBoxBorder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Borders/Boxes/DoubleBoxBorder.cs b/src/Spectre.Console/Rendering/Borders/Boxes/DoubleBoxBorder.cs index 7c7a7e3..d68850b 100644 --- a/src/Spectre.Console/Rendering/Borders/Boxes/DoubleBoxBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Boxes/DoubleBoxBorder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Borders/Boxes/HeavyBoxBorder.cs b/src/Spectre.Console/Rendering/Borders/Boxes/HeavyBoxBorder.cs index 5094614..53886a4 100644 --- a/src/Spectre.Console/Rendering/Borders/Boxes/HeavyBoxBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Boxes/HeavyBoxBorder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Borders/Boxes/RoundedBoxBorder.cs b/src/Spectre.Console/Rendering/Borders/Boxes/RoundedBoxBorder.cs index 7591700..55944f9 100644 --- a/src/Spectre.Console/Rendering/Borders/Boxes/RoundedBoxBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Boxes/RoundedBoxBorder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Borders/Boxes/SquareBoxBorder.cs b/src/Spectre.Console/Rendering/Borders/Boxes/SquareBoxBorder.cs index 2f35d13..833668c 100644 --- a/src/Spectre.Console/Rendering/Borders/Boxes/SquareBoxBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Boxes/SquareBoxBorder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Borders/Tables/Ascii2TableBorder.cs b/src/Spectre.Console/Rendering/Borders/Tables/Ascii2TableBorder.cs index dd7b276..7bd17d6 100644 --- a/src/Spectre.Console/Rendering/Borders/Tables/Ascii2TableBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Tables/Ascii2TableBorder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Borders/Tables/AsciiDoubleHeadTableBorder.cs b/src/Spectre.Console/Rendering/Borders/Tables/AsciiDoubleHeadTableBorder.cs index 7b6efca..f5f2bad 100644 --- a/src/Spectre.Console/Rendering/Borders/Tables/AsciiDoubleHeadTableBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Tables/AsciiDoubleHeadTableBorder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Borders/Tables/AsciiTableBorder.cs b/src/Spectre.Console/Rendering/Borders/Tables/AsciiTableBorder.cs index 5758035..7f4f743 100644 --- a/src/Spectre.Console/Rendering/Borders/Tables/AsciiTableBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Tables/AsciiTableBorder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Borders/Tables/DoubleEdgeTableBorder.cs b/src/Spectre.Console/Rendering/Borders/Tables/DoubleEdgeTableBorder.cs index ff2dbcf..ab13621 100644 --- a/src/Spectre.Console/Rendering/Borders/Tables/DoubleEdgeTableBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Tables/DoubleEdgeTableBorder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Borders/Tables/DoubleTableBorder.cs b/src/Spectre.Console/Rendering/Borders/Tables/DoubleTableBorder.cs index 8e726dd..b5eca04 100644 --- a/src/Spectre.Console/Rendering/Borders/Tables/DoubleTableBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Tables/DoubleTableBorder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Borders/Tables/HeavyEdgeTableBorder.cs b/src/Spectre.Console/Rendering/Borders/Tables/HeavyEdgeTableBorder.cs index c211618..f5728be 100644 --- a/src/Spectre.Console/Rendering/Borders/Tables/HeavyEdgeTableBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Tables/HeavyEdgeTableBorder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Borders/Tables/HeavyHeadTableBorder.cs b/src/Spectre.Console/Rendering/Borders/Tables/HeavyHeadTableBorder.cs index 53ba84e..87f3574 100644 --- a/src/Spectre.Console/Rendering/Borders/Tables/HeavyHeadTableBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Tables/HeavyHeadTableBorder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Borders/Tables/HeavyTableBorder.cs b/src/Spectre.Console/Rendering/Borders/Tables/HeavyTableBorder.cs index 5758ed7..783f742 100644 --- a/src/Spectre.Console/Rendering/Borders/Tables/HeavyTableBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Tables/HeavyTableBorder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Borders/Tables/HorizontalTableBorder.cs b/src/Spectre.Console/Rendering/Borders/Tables/HorizontalTableBorder.cs index 74101ec..db3021d 100644 --- a/src/Spectre.Console/Rendering/Borders/Tables/HorizontalTableBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Tables/HorizontalTableBorder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Borders/Tables/MarkdownTableBorder.cs b/src/Spectre.Console/Rendering/Borders/Tables/MarkdownTableBorder.cs index c42a6ff..f338c39 100644 --- a/src/Spectre.Console/Rendering/Borders/Tables/MarkdownTableBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Tables/MarkdownTableBorder.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Text; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Borders/Tables/MinimalDoubleHeadTableBorder.cs b/src/Spectre.Console/Rendering/Borders/Tables/MinimalDoubleHeadTableBorder.cs index 93c4c39..5fd281e 100644 --- a/src/Spectre.Console/Rendering/Borders/Tables/MinimalDoubleHeadTableBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Tables/MinimalDoubleHeadTableBorder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Borders/Tables/MinimalHeavyHeadTableBorder.cs b/src/Spectre.Console/Rendering/Borders/Tables/MinimalHeavyHeadTableBorder.cs index 9a23180..7c8cffe 100644 --- a/src/Spectre.Console/Rendering/Borders/Tables/MinimalHeavyHeadTableBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Tables/MinimalHeavyHeadTableBorder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Borders/Tables/MinimalTableBorder.cs b/src/Spectre.Console/Rendering/Borders/Tables/MinimalTableBorder.cs index 0621785..06d47aa 100644 --- a/src/Spectre.Console/Rendering/Borders/Tables/MinimalTableBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Tables/MinimalTableBorder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Borders/Tables/RoundedTableBorder.cs b/src/Spectre.Console/Rendering/Borders/Tables/RoundedTableBorder.cs index d0edc85..9d02c68 100644 --- a/src/Spectre.Console/Rendering/Borders/Tables/RoundedTableBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Tables/RoundedTableBorder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Borders/Tables/SimpleHeavyTableBorder.cs b/src/Spectre.Console/Rendering/Borders/Tables/SimpleHeavyTableBorder.cs index 7ce19f4..d8ae957 100644 --- a/src/Spectre.Console/Rendering/Borders/Tables/SimpleHeavyTableBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Tables/SimpleHeavyTableBorder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Borders/Tables/SimpleTableBorder.cs b/src/Spectre.Console/Rendering/Borders/Tables/SimpleTableBorder.cs index b0ee478..30fa563 100644 --- a/src/Spectre.Console/Rendering/Borders/Tables/SimpleTableBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Tables/SimpleTableBorder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Borders/Tables/SquareTableBorder.cs b/src/Spectre.Console/Rendering/Borders/Tables/SquareTableBorder.cs index f722c07..4e7e731 100644 --- a/src/Spectre.Console/Rendering/Borders/Tables/SquareTableBorder.cs +++ b/src/Spectre.Console/Rendering/Borders/Tables/SquareTableBorder.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/IAnsiConsoleEncoder.cs b/src/Spectre.Console/Rendering/IAnsiConsoleEncoder.cs index 363a32f..927afbe 100644 --- a/src/Spectre.Console/Rendering/IAnsiConsoleEncoder.cs +++ b/src/Spectre.Console/Rendering/IAnsiConsoleEncoder.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/IRenderHook.cs b/src/Spectre.Console/Rendering/IRenderHook.cs index 15b72ea..417a500 100644 --- a/src/Spectre.Console/Rendering/IRenderHook.cs +++ b/src/Spectre.Console/Rendering/IRenderHook.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/JustInTimeRenderable.cs b/src/Spectre.Console/Rendering/JustInTimeRenderable.cs index c522185..dd85e40 100644 --- a/src/Spectre.Console/Rendering/JustInTimeRenderable.cs +++ b/src/Spectre.Console/Rendering/JustInTimeRenderable.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Measurement.cs b/src/Spectre.Console/Rendering/Measurement.cs index 25d21bb..c5733ac 100644 --- a/src/Spectre.Console/Rendering/Measurement.cs +++ b/src/Spectre.Console/Rendering/Measurement.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/RenderContext.cs b/src/Spectre.Console/Rendering/RenderContext.cs index edc1b7a..c8d15f8 100644 --- a/src/Spectre.Console/Rendering/RenderContext.cs +++ b/src/Spectre.Console/Rendering/RenderContext.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/RenderHookScope.cs b/src/Spectre.Console/Rendering/RenderHookScope.cs index 48b0980..78f8558 100644 --- a/src/Spectre.Console/Rendering/RenderHookScope.cs +++ b/src/Spectre.Console/Rendering/RenderHookScope.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/RenderPipeline.cs b/src/Spectre.Console/Rendering/RenderPipeline.cs index 656cd86..367fffd 100644 --- a/src/Spectre.Console/Rendering/RenderPipeline.cs +++ b/src/Spectre.Console/Rendering/RenderPipeline.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Renderable.cs b/src/Spectre.Console/Rendering/Renderable.cs index 5f337a5..2b22f5d 100644 --- a/src/Spectre.Console/Rendering/Renderable.cs +++ b/src/Spectre.Console/Rendering/Renderable.cs @@ -1,6 +1,3 @@ -using System.Collections.Generic; -using System.Diagnostics; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Segment.cs b/src/Spectre.Console/Rendering/Segment.cs index b793714..53bd2f9 100644 --- a/src/Spectre.Console/Rendering/Segment.cs +++ b/src/Spectre.Console/Rendering/Segment.cs @@ -1,10 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using Wcwidth; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/SegmentLine.cs b/src/Spectre.Console/Rendering/SegmentLine.cs index eadd447..c594033 100644 --- a/src/Spectre.Console/Rendering/SegmentLine.cs +++ b/src/Spectre.Console/Rendering/SegmentLine.cs @@ -1,6 +1,3 @@ -using System.Collections.Generic; -using System.Linq; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/SegmentLineEnumerator.cs b/src/Spectre.Console/Rendering/SegmentLineEnumerator.cs index 7751241..94b728a 100644 --- a/src/Spectre.Console/Rendering/SegmentLineEnumerator.cs +++ b/src/Spectre.Console/Rendering/SegmentLineEnumerator.cs @@ -1,6 +1,3 @@ -using System.Collections; -using System.Collections.Generic; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/SegmentLineIterator.cs b/src/Spectre.Console/Rendering/SegmentLineIterator.cs index 0bb2568..b57de4f 100644 --- a/src/Spectre.Console/Rendering/SegmentLineIterator.cs +++ b/src/Spectre.Console/Rendering/SegmentLineIterator.cs @@ -1,6 +1,3 @@ -using System.Collections; -using System.Collections.Generic; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/SegmentShape.cs b/src/Spectre.Console/Rendering/SegmentShape.cs index 303eeac..6b45c38 100644 --- a/src/Spectre.Console/Rendering/SegmentShape.cs +++ b/src/Spectre.Console/Rendering/SegmentShape.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - namespace Spectre.Console.Rendering; internal readonly struct SegmentShape diff --git a/src/Spectre.Console/Rendering/Tree/AsciiTreeGuide.cs b/src/Spectre.Console/Rendering/Tree/AsciiTreeGuide.cs index 8fa7d2a..b27cf1b 100644 --- a/src/Spectre.Console/Rendering/Tree/AsciiTreeGuide.cs +++ b/src/Spectre.Console/Rendering/Tree/AsciiTreeGuide.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Tree/BoldLineTreeGuide.cs b/src/Spectre.Console/Rendering/Tree/BoldLineTreeGuide.cs index 9553f78..7bb38bf 100644 --- a/src/Spectre.Console/Rendering/Tree/BoldLineTreeGuide.cs +++ b/src/Spectre.Console/Rendering/Tree/BoldLineTreeGuide.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Tree/DoubleLineTreeGuide.cs b/src/Spectre.Console/Rendering/Tree/DoubleLineTreeGuide.cs index 5cbf6e0..d31759e 100644 --- a/src/Spectre.Console/Rendering/Tree/DoubleLineTreeGuide.cs +++ b/src/Spectre.Console/Rendering/Tree/DoubleLineTreeGuide.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Rendering/Tree/LineTreeGuide.cs b/src/Spectre.Console/Rendering/Tree/LineTreeGuide.cs index 4d50a0b..bb06a61 100644 --- a/src/Spectre.Console/Rendering/Tree/LineTreeGuide.cs +++ b/src/Spectre.Console/Rendering/Tree/LineTreeGuide.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console.Rendering; /// diff --git a/src/Spectre.Console/Style.cs b/src/Spectre.Console/Style.cs index 5bd66f3..9ca844e 100644 --- a/src/Spectre.Console/Style.cs +++ b/src/Spectre.Console/Style.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/StyleParser.cs b/src/Spectre.Console/StyleParser.cs index c88a9a3..c297555 100644 --- a/src/Spectre.Console/StyleParser.cs +++ b/src/Spectre.Console/StyleParser.cs @@ -1,6 +1,3 @@ -using System; -using System.Globalization; - namespace Spectre.Console; internal static class StyleParser diff --git a/src/Spectre.Console/TableBorder.Known.cs b/src/Spectre.Console/TableBorder.Known.cs index 49f3d9e..20aeb74 100644 --- a/src/Spectre.Console/TableBorder.Known.cs +++ b/src/Spectre.Console/TableBorder.Known.cs @@ -1,6 +1,3 @@ -using System.Diagnostics.CodeAnalysis; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/TableBorder.cs b/src/Spectre.Console/TableBorder.cs index 471214a..a206544 100644 --- a/src/Spectre.Console/TableBorder.cs +++ b/src/Spectre.Console/TableBorder.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/TreeGuide.Known.cs b/src/Spectre.Console/TreeGuide.Known.cs index 701a15d..50dc8b6 100644 --- a/src/Spectre.Console/TreeGuide.Known.cs +++ b/src/Spectre.Console/TreeGuide.Known.cs @@ -1,5 +1,3 @@ -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/TreeGuide.cs b/src/Spectre.Console/TreeGuide.cs index 5ba19b9..005a32a 100644 --- a/src/Spectre.Console/TreeGuide.cs +++ b/src/Spectre.Console/TreeGuide.cs @@ -1,5 +1,3 @@ -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Calendar.cs b/src/Spectre.Console/Widgets/Calendar.cs index a79c56b..3f4ece6 100644 --- a/src/Spectre.Console/Widgets/Calendar.cs +++ b/src/Spectre.Console/Widgets/Calendar.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Canvas.cs b/src/Spectre.Console/Widgets/Canvas.cs index 42fa4a9..2718a49 100644 --- a/src/Spectre.Console/Widgets/Canvas.cs +++ b/src/Spectre.Console/Widgets/Canvas.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Charts/BarChart.cs b/src/Spectre.Console/Widgets/Charts/BarChart.cs index 4fa9a87..457116b 100644 --- a/src/Spectre.Console/Widgets/Charts/BarChart.cs +++ b/src/Spectre.Console/Widgets/Charts/BarChart.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Charts/BarChartItem.cs b/src/Spectre.Console/Widgets/Charts/BarChartItem.cs index b5a0487..b3c540c 100644 --- a/src/Spectre.Console/Widgets/Charts/BarChartItem.cs +++ b/src/Spectre.Console/Widgets/Charts/BarChartItem.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Charts/BreakdownBar.cs b/src/Spectre.Console/Widgets/Charts/BreakdownBar.cs index 90e8ac0..4db0bc4 100644 --- a/src/Spectre.Console/Widgets/Charts/BreakdownBar.cs +++ b/src/Spectre.Console/Widgets/Charts/BreakdownBar.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; internal sealed class BreakdownBar : Renderable diff --git a/src/Spectre.Console/Widgets/Charts/BreakdownChart.cs b/src/Spectre.Console/Widgets/Charts/BreakdownChart.cs index f02f3ac..b7f973c 100644 --- a/src/Spectre.Console/Widgets/Charts/BreakdownChart.cs +++ b/src/Spectre.Console/Widgets/Charts/BreakdownChart.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Charts/BreakdownChartItem.cs b/src/Spectre.Console/Widgets/Charts/BreakdownChartItem.cs index 579d40b..b7f8c21 100644 --- a/src/Spectre.Console/Widgets/Charts/BreakdownChartItem.cs +++ b/src/Spectre.Console/Widgets/Charts/BreakdownChartItem.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Charts/BreakdownTags.cs b/src/Spectre.Console/Widgets/Charts/BreakdownTags.cs index d33bfa5..669660a 100644 --- a/src/Spectre.Console/Widgets/Charts/BreakdownTags.cs +++ b/src/Spectre.Console/Widgets/Charts/BreakdownTags.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using Spectre.Console.Rendering; - namespace Spectre.Console; internal sealed class BreakdownTags : Renderable diff --git a/src/Spectre.Console/Widgets/CircularTreeException.cs b/src/Spectre.Console/Widgets/CircularTreeException.cs index 1612e1b..73251cb 100644 --- a/src/Spectre.Console/Widgets/CircularTreeException.cs +++ b/src/Spectre.Console/Widgets/CircularTreeException.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Columns.cs b/src/Spectre.Console/Widgets/Columns.cs index 5389373..d6bb8de 100644 --- a/src/Spectre.Console/Widgets/Columns.cs +++ b/src/Spectre.Console/Widgets/Columns.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/ControlCode.cs b/src/Spectre.Console/Widgets/ControlCode.cs index 7fe11af..fa7b46e 100644 --- a/src/Spectre.Console/Widgets/ControlCode.cs +++ b/src/Spectre.Console/Widgets/ControlCode.cs @@ -1,6 +1,3 @@ -using System.Collections.Generic; -using Spectre.Console.Rendering; - namespace Spectre.Console; internal sealed class ControlCode : Renderable diff --git a/src/Spectre.Console/Widgets/Exceptions/ExceptionConverter.cs b/src/Spectre.Console/Widgets/Exceptions/ExceptionConverter.cs index 67d42c8..f392db1 100644 --- a/src/Spectre.Console/Widgets/Exceptions/ExceptionConverter.cs +++ b/src/Spectre.Console/Widgets/Exceptions/ExceptionConverter.cs @@ -1,10 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Reflection; -using System.Text; - namespace Spectre.Console; internal static class ExceptionConverter diff --git a/src/Spectre.Console/Widgets/Exceptions/ExceptionFormat.cs b/src/Spectre.Console/Widgets/Exceptions/ExceptionFormat.cs index b55c988..bc1977b 100644 --- a/src/Spectre.Console/Widgets/Exceptions/ExceptionFormat.cs +++ b/src/Spectre.Console/Widgets/Exceptions/ExceptionFormat.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs b/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs index 3637a85..7f20094 100644 --- a/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs +++ b/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs @@ -1,8 +1,3 @@ -using System; -using System.Linq; -using System.Text; -using Spectre.Console.Rendering; - namespace Spectre.Console; internal static class ExceptionFormatter diff --git a/src/Spectre.Console/Widgets/Exceptions/ExceptionInfo.cs b/src/Spectre.Console/Widgets/Exceptions/ExceptionInfo.cs index e0ee2cd..63f7c52 100644 --- a/src/Spectre.Console/Widgets/Exceptions/ExceptionInfo.cs +++ b/src/Spectre.Console/Widgets/Exceptions/ExceptionInfo.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Spectre.Console; internal sealed class ExceptionInfo diff --git a/src/Spectre.Console/Widgets/Exceptions/StackFrameInfo.cs b/src/Spectre.Console/Widgets/Exceptions/StackFrameInfo.cs index 533263a..1247c34 100644 --- a/src/Spectre.Console/Widgets/Exceptions/StackFrameInfo.cs +++ b/src/Spectre.Console/Widgets/Exceptions/StackFrameInfo.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Net; - namespace Spectre.Console; internal sealed class StackFrameInfo diff --git a/src/Spectre.Console/Widgets/Figlet/FigletCharacter.cs b/src/Spectre.Console/Widgets/Figlet/FigletCharacter.cs index b1e3c29..d232ddf 100644 --- a/src/Spectre.Console/Widgets/Figlet/FigletCharacter.cs +++ b/src/Spectre.Console/Widgets/Figlet/FigletCharacter.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - namespace Spectre.Console; internal sealed class FigletCharacter diff --git a/src/Spectre.Console/Widgets/Figlet/FigletFont.cs b/src/Spectre.Console/Widgets/Figlet/FigletFont.cs index 0304062..9ac7843 100644 --- a/src/Spectre.Console/Widgets/Figlet/FigletFont.cs +++ b/src/Spectre.Console/Widgets/Figlet/FigletFont.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.IO; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Figlet/FigletFontParser.cs b/src/Spectre.Console/Widgets/Figlet/FigletFontParser.cs index 3967ec9..43496c1 100644 --- a/src/Spectre.Console/Widgets/Figlet/FigletFontParser.cs +++ b/src/Spectre.Console/Widgets/Figlet/FigletFontParser.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; - namespace Spectre.Console; internal static class FigletFontParser diff --git a/src/Spectre.Console/Widgets/Figlet/FigletText.cs b/src/Spectre.Console/Widgets/Figlet/FigletText.cs index 97dcc2d..f17d6a5 100644 --- a/src/Spectre.Console/Widgets/Figlet/FigletText.cs +++ b/src/Spectre.Console/Widgets/Figlet/FigletText.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Grid.cs b/src/Spectre.Console/Widgets/Grid.cs index f2e1603..448ef1b 100644 --- a/src/Spectre.Console/Widgets/Grid.cs +++ b/src/Spectre.Console/Widgets/Grid.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/GridColumn.cs b/src/Spectre.Console/Widgets/GridColumn.cs index 1359555..2100784 100644 --- a/src/Spectre.Console/Widgets/GridColumn.cs +++ b/src/Spectre.Console/Widgets/GridColumn.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/GridRow.cs b/src/Spectre.Console/Widgets/GridRow.cs index a9fa55c..5761ae5 100644 --- a/src/Spectre.Console/Widgets/GridRow.cs +++ b/src/Spectre.Console/Widgets/GridRow.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Markup.cs b/src/Spectre.Console/Widgets/Markup.cs index 75f854d..e598a1b 100644 --- a/src/Spectre.Console/Widgets/Markup.cs +++ b/src/Spectre.Console/Widgets/Markup.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Padder.cs b/src/Spectre.Console/Widgets/Padder.cs index b04ef25..9f2d376 100644 --- a/src/Spectre.Console/Widgets/Padder.cs +++ b/src/Spectre.Console/Widgets/Padder.cs @@ -1,6 +1,3 @@ -using System.Collections.Generic; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Panel.cs b/src/Spectre.Console/Widgets/Panel.cs index f7f1f9a..0c263cb 100644 --- a/src/Spectre.Console/Widgets/Panel.cs +++ b/src/Spectre.Console/Widgets/Panel.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/PanelHeader.cs b/src/Spectre.Console/Widgets/PanelHeader.cs index 035f128..951dcbd 100644 --- a/src/Spectre.Console/Widgets/PanelHeader.cs +++ b/src/Spectre.Console/Widgets/PanelHeader.cs @@ -1,6 +1,3 @@ -using System; -using System.ComponentModel; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Paragraph.cs b/src/Spectre.Console/Widgets/Paragraph.cs index c6a3540..bfcc09b 100644 --- a/src/Spectre.Console/Widgets/Paragraph.cs +++ b/src/Spectre.Console/Widgets/Paragraph.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/ProgressBar.cs b/src/Spectre.Console/Widgets/ProgressBar.cs index 3da62ab..67ef339 100644 --- a/src/Spectre.Console/Widgets/ProgressBar.cs +++ b/src/Spectre.Console/Widgets/ProgressBar.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; internal sealed class ProgressBar : Renderable, IHasCulture diff --git a/src/Spectre.Console/Widgets/Rows.cs b/src/Spectre.Console/Widgets/Rows.cs index 65c2a67..32f88cf 100644 --- a/src/Spectre.Console/Widgets/Rows.cs +++ b/src/Spectre.Console/Widgets/Rows.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Rule.cs b/src/Spectre.Console/Widgets/Rule.cs index 169c555..210318c 100644 --- a/src/Spectre.Console/Widgets/Rule.cs +++ b/src/Spectre.Console/Widgets/Rule.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Table/Table.cs b/src/Spectre.Console/Widgets/Table/Table.cs index 77dfc45..a22dd63 100644 --- a/src/Spectre.Console/Widgets/Table/Table.cs +++ b/src/Spectre.Console/Widgets/Table/Table.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Table/TableAccessor.cs b/src/Spectre.Console/Widgets/Table/TableAccessor.cs index 3cb2e70..2979a0d 100644 --- a/src/Spectre.Console/Widgets/Table/TableAccessor.cs +++ b/src/Spectre.Console/Widgets/Table/TableAccessor.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using Spectre.Console.Rendering; - namespace Spectre.Console; internal abstract class TableAccessor diff --git a/src/Spectre.Console/Widgets/Table/TableColumn.cs b/src/Spectre.Console/Widgets/Table/TableColumn.cs index eee45a6..3979dfd 100644 --- a/src/Spectre.Console/Widgets/Table/TableColumn.cs +++ b/src/Spectre.Console/Widgets/Table/TableColumn.cs @@ -1,6 +1,3 @@ -using System; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Table/TableMeasurer.cs b/src/Spectre.Console/Widgets/Table/TableMeasurer.cs index 877d2c8..d7a26cd 100644 --- a/src/Spectre.Console/Widgets/Table/TableMeasurer.cs +++ b/src/Spectre.Console/Widgets/Table/TableMeasurer.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; internal sealed class TableMeasurer : TableAccessor diff --git a/src/Spectre.Console/Widgets/Table/TableRenderer.cs b/src/Spectre.Console/Widgets/Table/TableRenderer.cs index 621d44e..a0e178a 100644 --- a/src/Spectre.Console/Widgets/Table/TableRenderer.cs +++ b/src/Spectre.Console/Widgets/Table/TableRenderer.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; internal static class TableRenderer diff --git a/src/Spectre.Console/Widgets/Table/TableRendererContext.cs b/src/Spectre.Console/Widgets/Table/TableRendererContext.cs index 4dea84a..17e98c7 100644 --- a/src/Spectre.Console/Widgets/Table/TableRendererContext.cs +++ b/src/Spectre.Console/Widgets/Table/TableRendererContext.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; internal sealed class TableRendererContext : TableAccessor diff --git a/src/Spectre.Console/Widgets/Table/TableRow.cs b/src/Spectre.Console/Widgets/Table/TableRow.cs index db41d93..e73ade0 100644 --- a/src/Spectre.Console/Widgets/Table/TableRow.cs +++ b/src/Spectre.Console/Widgets/Table/TableRow.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Table/TableRowCollection.cs b/src/Spectre.Console/Widgets/Table/TableRowCollection.cs index 43a8801..11c0938 100644 --- a/src/Spectre.Console/Widgets/Table/TableRowCollection.cs +++ b/src/Spectre.Console/Widgets/Table/TableRowCollection.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Table/TableRowEnumerator.cs b/src/Spectre.Console/Widgets/Table/TableRowEnumerator.cs index 3ee1954..3506a50 100644 --- a/src/Spectre.Console/Widgets/Table/TableRowEnumerator.cs +++ b/src/Spectre.Console/Widgets/Table/TableRowEnumerator.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections; -using System.Collections.Generic; - namespace Spectre.Console; internal sealed class TableRowEnumerator : IEnumerator diff --git a/src/Spectre.Console/Widgets/Table/TableTitle.cs b/src/Spectre.Console/Widgets/Table/TableTitle.cs index 3805da2..25883d1 100644 --- a/src/Spectre.Console/Widgets/Table/TableTitle.cs +++ b/src/Spectre.Console/Widgets/Table/TableTitle.cs @@ -1,5 +1,3 @@ -using System; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Text.cs b/src/Spectre.Console/Widgets/Text.cs index 4903bd2..e84c2f3 100644 --- a/src/Spectre.Console/Widgets/Text.cs +++ b/src/Spectre.Console/Widgets/Text.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/Tree.cs b/src/Spectre.Console/Widgets/Tree.cs index c95a5fb..9929a53 100644 --- a/src/Spectre.Console/Widgets/Tree.cs +++ b/src/Spectre.Console/Widgets/Tree.cs @@ -1,7 +1,3 @@ -using System.Collections.Generic; -using System.Linq; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/src/Spectre.Console/Widgets/TreeNode.cs b/src/Spectre.Console/Widgets/TreeNode.cs index 4e77425..04c2854 100644 --- a/src/Spectre.Console/Widgets/TreeNode.cs +++ b/src/Spectre.Console/Widgets/TreeNode.cs @@ -1,6 +1,3 @@ -using System.Collections.Generic; -using Spectre.Console.Rendering; - namespace Spectre.Console; /// diff --git a/test/.editorconfig b/test/.editorconfig index 5a0cfde..6b10758 100644 --- a/test/.editorconfig +++ b/test/.editorconfig @@ -1,35 +1,107 @@ root = false -[*.cs] +[*.cs] # Default severity for analyzer diagnostics with category 'StyleCop.CSharp.DocumentationRules' dotnet_analyzer_diagnostic.category-StyleCop.CSharp.DocumentationRules.severity = none -# CA1707: Identifiers should not contain underscores -dotnet_diagnostic.CA1707.severity = none +# IDE0055: Fix formatting +dotnet_diagnostic.IDE0055.severity = warning -# SA1600: Elements should be documented -dotnet_diagnostic.SA1600.severity = none +# SA1101: Prefix local calls with this +dotnet_diagnostic.SA1101.severity = none -# SA1601: Partial elements should be documented -dotnet_diagnostic.SA1601.severity = none +# SA1633: File should have header +dotnet_diagnostic.SA1633.severity = none -# SA1200: Using directives should be placed correctly -dotnet_diagnostic.SA1200.severity = none +# SA1201: Elements should appear in the correct order +dotnet_diagnostic.SA1201.severity = none + +# SA1202: Public members should come before private members +dotnet_diagnostic.SA1202.severity = none + +# SA1309: Field names should not begin with underscore +dotnet_diagnostic.SA1309.severity = none + +# SA1404: Code analysis suppressions should have justification +dotnet_diagnostic.SA1404.severity = none + +# SA1516: Elements should be separated by a blank line +dotnet_diagnostic.SA1516.severity = none + +# CA1303: Do not pass literals as localized parameters +dotnet_diagnostic.CA1303.severity = none + +# CSA1204: Static members should appear before non-static members +dotnet_diagnostic.SA1204.severity = none + +# IDE0052: Remove unread private members +dotnet_diagnostic.IDE0052.severity = warning + +# IDE0063: Use simple 'using' statement +csharp_prefer_simple_using_statement = false:suggestion + +# IDE0018: Variable declaration can be inlined +dotnet_diagnostic.IDE0018.severity = warning + +# SA1625: Element documenation should not be copied and pasted +dotnet_diagnostic.SA1625.severity = none + +# IDE0005: Using directive is unnecessary +dotnet_diagnostic.IDE0005.severity = warning + +# SA1117: Parameters should be on same line or separate lines +dotnet_diagnostic.SA1117.severity = none + +# SA1404: Code analysis suppression should have justification +dotnet_diagnostic.SA1404.severity = none + +# SA1101: Prefix local calls with this +dotnet_diagnostic.SA1101.severity = none + +# SA1633: File should have header +dotnet_diagnostic.SA1633.severity = none + +# SA1649: File name should match first type name +dotnet_diagnostic.SA1649.severity = none + +# SA1402: File may only contain a single type +dotnet_diagnostic.SA1402.severity = none + +# CA1814: Prefer jagged arrays over multidimensional +dotnet_diagnostic.CA1814.severity = none + +# RCS1194: Implement exception constructors. +dotnet_diagnostic.RCS1194.severity = none + +# CA1032: Implement standard exception constructors +dotnet_diagnostic.CA1032.severity = none + +# CA1826: Do not use Enumerable methods on indexable collections. Instead use the collection directly +dotnet_diagnostic.CA1826.severity = none + +# RCS1079: Throwing of new NotImplementedException. +dotnet_diagnostic.RCS1079.severity = warning + +# RCS1057: Add empty line between declarations. +dotnet_diagnostic.RCS1057.severity = none + +# RCS1057: Validate arguments correctly +dotnet_diagnostic.RCS1227.severity = none + +# IDE0004: Remove Unnecessary Cast +dotnet_diagnostic.IDE0004.severity = warning + +# CA1810: Initialize reference type static fields inline +dotnet_diagnostic.CA1810.severity = none + +# IDE0044: Add readonly modifier +dotnet_diagnostic.IDE0044.severity = warning + +# RCS1047: Non-asynchronous method name should not end with 'Async'. +dotnet_diagnostic.RCS1047.severity = none + +# RCS1090: Call 'ConfigureAwait(false)'. +dotnet_diagnostic.RCS1090.severity = warning # CS1591: Missing XML comment for publicly visible type or member -dotnet_diagnostic.CS1591.severity = none - -# SA1210: Using directives should be ordered alphabetically by namespace -dotnet_diagnostic.SA1210.severity = none - -# CA1034: Nested types should not be visible -dotnet_diagnostic.CA1034.severity = none - -# CA2000: Dispose objects before losing scope -dotnet_diagnostic.CA2000.severity = none - -# SA1118: Parameter should not span multiple lines -dotnet_diagnostic.SA1118.severity = none - -# CA1031: Do not catch general exception types -dotnet_diagnostic.CA1031.severity = none +dotnet_diagnostic.CS1591.severity = none \ No newline at end of file diff --git a/test/Directory.Build.props b/test/Directory.Build.props new file mode 100644 index 0000000..c6403bb --- /dev/null +++ b/test/Directory.Build.props @@ -0,0 +1,16 @@ + + + 10 + false + true + + + + + All + + + All + + + \ No newline at end of file diff --git a/test/Spectre.Console.Analyzer.Tests/CodeAnalyzerHelper.cs b/test/Spectre.Console.Analyzer.Tests/CodeAnalyzerHelper.cs new file mode 100644 index 0000000..4312995 --- /dev/null +++ b/test/Spectre.Console.Analyzer.Tests/CodeAnalyzerHelper.cs @@ -0,0 +1,12 @@ +namespace Spectre.Console.Analyzer.Tests; + +internal static class CodeAnalyzerHelper +{ + internal static ReferenceAssemblies CurrentSpectre { get; } + + static CodeAnalyzerHelper() + { + CurrentSpectre = ReferenceAssemblies.Net.Net50.AddAssemblies( + ImmutableArray.Create(typeof(AnsiConsole).Assembly.Location.Replace(".dll", string.Empty))); + } +} diff --git a/test/Spectre.Console.Analyzer.Tests/CodeFixProviderDiscovery.cs b/test/Spectre.Console.Analyzer.Tests/CodeFixProviderDiscovery.cs index 1ac69f5..9cfb44d 100644 --- a/test/Spectre.Console.Analyzer.Tests/CodeFixProviderDiscovery.cs +++ b/test/Spectre.Console.Analyzer.Tests/CodeFixProviderDiscovery.cs @@ -1,55 +1,44 @@ -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeFixes; -using Microsoft.VisualStudio.Composition; -using Spectre.Console.Analyzer.FixProviders; +namespace Spectre.Console.Analyzer.Tests; -namespace Spectre.Console.Analyzer.Tests +internal static class CodeFixProviderDiscovery { - internal static class CodeFixProviderDiscovery + private static readonly Lazy _exportProviderFactory; + + static CodeFixProviderDiscovery() { - private static readonly Lazy _exportProviderFactory; - - static CodeFixProviderDiscovery() - { - _exportProviderFactory = new Lazy( - () => - { - var discovery = new AttributedPartDiscovery(Resolver.DefaultInstance, isNonPublicSupported: true); - var parts = Task.Run(() => discovery.CreatePartsAsync(typeof(SystemConsoleToAnsiConsoleFix).Assembly)).GetAwaiter().GetResult(); - var catalog = ComposableCatalog.Create(Resolver.DefaultInstance).AddParts(parts); - - var configuration = CompositionConfiguration.Create(catalog); - var runtimeComposition = RuntimeComposition.CreateRuntimeComposition(configuration); - return runtimeComposition.CreateExportProviderFactory(); - }, - LazyThreadSafetyMode.ExecutionAndPublication); - } - - public static IEnumerable GetCodeFixProviders(string language) - { - var exportProvider = _exportProviderFactory.Value.CreateExportProvider(); - var exports = exportProvider.GetExports(); - return exports.Where(export => export.Metadata.Languages.Contains(language)).Select(export => export.Value); - } - - private class LanguageMetadata - { - public LanguageMetadata(IDictionary data) + _exportProviderFactory = new Lazy( + () => { - if (!data.TryGetValue(nameof(ExportCodeFixProviderAttribute.Languages), out var languages)) - { - languages = Array.Empty(); - } + var discovery = new AttributedPartDiscovery(Resolver.DefaultInstance, isNonPublicSupported: true); + var parts = Task.Run(() => discovery.CreatePartsAsync(typeof(SystemConsoleToAnsiConsoleFix).Assembly)).GetAwaiter().GetResult(); + var catalog = ComposableCatalog.Create(Resolver.DefaultInstance).AddParts(parts); - Languages = ((string[])languages).ToImmutableArray(); + var configuration = CompositionConfiguration.Create(catalog); + var runtimeComposition = RuntimeComposition.CreateRuntimeComposition(configuration); + return runtimeComposition.CreateExportProviderFactory(); + }, + LazyThreadSafetyMode.ExecutionAndPublication); + } + + public static IEnumerable GetCodeFixProviders(string language) + { + var exportProvider = _exportProviderFactory.Value.CreateExportProvider(); + var exports = exportProvider.GetExports(); + return exports.Where(export => export.Metadata.Languages.Contains(language)).Select(export => export.Value); + } + + private class LanguageMetadata + { + public LanguageMetadata(IDictionary data) + { + if (!data.TryGetValue(nameof(ExportCodeFixProviderAttribute.Languages), out var languages)) + { + languages = Array.Empty(); } - public ImmutableArray Languages { get; } + Languages = ((string[])languages).ToImmutableArray(); } + + public ImmutableArray Languages { get; } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Analyzer.Tests/Properties/Usings.cs b/test/Spectre.Console.Analyzer.Tests/Properties/Usings.cs new file mode 100644 index 0000000..394e6fe --- /dev/null +++ b/test/Spectre.Console.Analyzer.Tests/Properties/Usings.cs @@ -0,0 +1,15 @@ +global using System; +global using System.Collections.Generic; +global using System.Collections.Immutable; +global using System.Linq; +global using System.Threading; +global using System.Threading.Tasks; +global using Microsoft.CodeAnalysis; +global using Microsoft.CodeAnalysis.CodeFixes; +global using Microsoft.CodeAnalysis.CSharp.Testing; +global using Microsoft.CodeAnalysis.Diagnostics; +global using Microsoft.CodeAnalysis.Testing; +global using Microsoft.CodeAnalysis.Testing.Verifiers; +global using Microsoft.VisualStudio.Composition; +global using Spectre.Console.Analyzer.FixProviders; +global using Xunit; \ No newline at end of file diff --git a/test/Spectre.Console.Analyzer.Tests/Spectre.Console.Analyzer.Tests.csproj b/test/Spectre.Console.Analyzer.Tests/Spectre.Console.Analyzer.Tests.csproj index c48f3c7..3e1881a 100644 --- a/test/Spectre.Console.Analyzer.Tests/Spectre.Console.Analyzer.Tests.csproj +++ b/test/Spectre.Console.Analyzer.Tests/Spectre.Console.Analyzer.Tests.csproj @@ -5,6 +5,10 @@ false + + + + diff --git a/test/Spectre.Console.Analyzer.Tests/SpectreAnalyzerVerifier.cs b/test/Spectre.Console.Analyzer.Tests/SpectreAnalyzerVerifier.cs index fb8132b..91c503d 100644 --- a/test/Spectre.Console.Analyzer.Tests/SpectreAnalyzerVerifier.cs +++ b/test/Spectre.Console.Analyzer.Tests/SpectreAnalyzerVerifier.cs @@ -1,86 +1,63 @@ -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeFixes; -using Microsoft.CodeAnalysis.CSharp.Testing; -using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.Testing; -using Microsoft.CodeAnalysis.Testing.Verifiers; +namespace Spectre.Console.Analyzer.Tests; -namespace Spectre.Console.Analyzer.Tests +public static class SpectreAnalyzerVerifier + where TAnalyzer : DiagnosticAnalyzer, new() { - public static class SpectreAnalyzerVerifier - where TAnalyzer : DiagnosticAnalyzer, new() + public static Task VerifyCodeFixAsync(string source, DiagnosticResult expected, string fixedSource) + => VerifyCodeFixAsync(source, new[] { expected }, fixedSource); + + private static Task VerifyCodeFixAsync(string source, IEnumerable expected, string fixedSource) { - public static Task VerifyCodeFixAsync(string source, DiagnosticResult expected, string fixedSource) - => VerifyCodeFixAsync(source, new[] { expected }, fixedSource); - - private static Task VerifyCodeFixAsync(string source, IEnumerable expected, string fixedSource) + // Roslyn fixers always use \r\n for newlines, regardless of OS environment settings, so we normalize + // the source as it typically comes from multi-line strings with varying newlines. + if (Environment.NewLine != "\r\n") { - // Roslyn fixers always use \r\n for newlines, regardless of OS environment settings, so we normalize - // the source as it typically comes from multi-line strings with varying newlines. - if (Environment.NewLine != "\r\n") - { - source = source.Replace(Environment.NewLine, "\r\n"); - fixedSource = fixedSource.Replace(Environment.NewLine, "\r\n"); - } - - var test = new Test - { - TestCode = source, - FixedCode = fixedSource, - }; - - test.ExpectedDiagnostics.AddRange(expected); - return test.RunAsync(); + source = source.Replace(Environment.NewLine, "\r\n"); + fixedSource = fixedSource.Replace(Environment.NewLine, "\r\n"); } - public static Task VerifyAnalyzerAsync(string source, params DiagnosticResult[] expected) + var test = new Test { - var test = new Test - { - TestCode = source, - CompilerDiagnostics = CompilerDiagnostics.All, - }; + TestCode = source, + FixedCode = fixedSource, + }; - test.ExpectedDiagnostics.AddRange(expected); - return test.RunAsync(); + test.ExpectedDiagnostics.AddRange(expected); + return test.RunAsync(); + } + + public static Task VerifyAnalyzerAsync(string source, params DiagnosticResult[] expected) + { + var test = new Test + { + TestCode = source, + CompilerDiagnostics = CompilerDiagnostics.All, + }; + + test.ExpectedDiagnostics.AddRange(expected); + return test.RunAsync(); + } + + // Code fix tests support both analyzer and code fix testing. This test class is derived from the code fix test + // to avoid the need to maintain duplicate copies of the customization work. + private class Test : CSharpCodeFixTest + { + public Test() + { + ReferenceAssemblies = CodeAnalyzerHelper.CurrentSpectre; + TestBehaviors |= TestBehaviors.SkipGeneratedCodeCheck; } - // Code fix tests support both analyzer and code fix testing. This test class is derived from the code fix test - // to avoid the need to maintain duplicate copies of the customization work. - private class Test : CSharpCodeFixTest + protected override IEnumerable GetCodeFixProviders() { - public Test() + var analyzer = new TAnalyzer(); + foreach (var provider in CodeFixProviderDiscovery.GetCodeFixProviders(Language)) { - ReferenceAssemblies = CodeAnalyzerHelper.CurrentSpectre; - TestBehaviors |= TestBehaviors.SkipGeneratedCodeCheck; - } - - protected override IEnumerable GetCodeFixProviders() - { - var analyzer = new TAnalyzer(); - foreach (var provider in CodeFixProviderDiscovery.GetCodeFixProviders(Language)) + if (analyzer.SupportedDiagnostics.Any(diagnostic => provider.FixableDiagnosticIds.Contains(diagnostic.Id))) { - if (analyzer.SupportedDiagnostics.Any(diagnostic => provider.FixableDiagnosticIds.Contains(diagnostic.Id))) - { - yield return provider; - } + yield return provider; } } } } - - internal static class CodeAnalyzerHelper - { - internal static ReferenceAssemblies CurrentSpectre { get; } - - static CodeAnalyzerHelper() - { - CurrentSpectre = ReferenceAssemblies.Net.Net50.AddAssemblies( - ImmutableArray.Create(typeof(AnsiConsole).Assembly.Location.Replace(".dll", string.Empty))); - } - } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Analyzer.Tests/Unit/Analyzers/NoConcurrentLiveRenderablesTests.cs b/test/Spectre.Console.Analyzer.Tests/Unit/Analyzers/NoConcurrentLiveRenderablesTests.cs index 6c2a692..940bd09 100644 --- a/test/Spectre.Console.Analyzer.Tests/Unit/Analyzers/NoConcurrentLiveRenderablesTests.cs +++ b/test/Spectre.Console.Analyzer.Tests/Unit/Analyzers/NoConcurrentLiveRenderablesTests.cs @@ -1,19 +1,15 @@ -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Testing; -using Xunit; +namespace Spectre.Console.Analyzer.Tests.Unit.Analyzers; -namespace Spectre.Console.Analyzer.Tests.Unit.Analyzers +public class NoCurrentLiveRenderablesTests { - public class NoCurrentLiveRenderablesTests - { - private static readonly DiagnosticResult _expectedDiagnostics = new( - Descriptors.S1020_AvoidConcurrentCallsToMultipleLiveRenderables.Id, - DiagnosticSeverity.Warning); + private static readonly DiagnosticResult _expectedDiagnostics = new( + Descriptors.S1020_AvoidConcurrentCallsToMultipleLiveRenderables.Id, + DiagnosticSeverity.Warning); - [Fact] - public async void Status_call_within_live_call_warns() - { - const string Source = @" + [Fact] + public async void Status_call_within_live_call_warns() + { + const string Source = @" using Spectre.Console; class TestClass @@ -27,15 +23,15 @@ class TestClass } }"; - await SpectreAnalyzerVerifier - .VerifyAnalyzerAsync(Source, _expectedDiagnostics.WithLocation(10, 13)) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyAnalyzerAsync(Source, _expectedDiagnostics.WithLocation(10, 13)) + .ConfigureAwait(false); + } - [Fact] - public async void Status_call_within_live_call_warns_with_instance() - { - const string Source = @" + [Fact] + public async void Status_call_within_live_call_warns_with_instance() + { + const string Source = @" using Spectre.Console; class Child @@ -51,15 +47,15 @@ class Child } }"; - await SpectreAnalyzerVerifier - .VerifyAnalyzerAsync(Source, _expectedDiagnostics.WithLocation(12, 13)) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyAnalyzerAsync(Source, _expectedDiagnostics.WithLocation(12, 13)) + .ConfigureAwait(false); + } - [Fact] - public async void Calling_start_on_non_live_renderable_has_no_warning() - { - const string Source = @" + [Fact] + public async void Calling_start_on_non_live_renderable_has_no_warning() + { + const string Source = @" using Spectre.Console; class Program @@ -72,9 +68,8 @@ class Program static void Start() => AnsiConsole.WriteLine(""Starting...""); }"; - await SpectreAnalyzerVerifier - .VerifyAnalyzerAsync(Source) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyAnalyzerAsync(Source) + .ConfigureAwait(false); } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Analyzer.Tests/Unit/Analyzers/NoPromptsDuringLiveRenderablesTests.cs b/test/Spectre.Console.Analyzer.Tests/Unit/Analyzers/NoPromptsDuringLiveRenderablesTests.cs index 835aae3..1ddb9c9 100644 --- a/test/Spectre.Console.Analyzer.Tests/Unit/Analyzers/NoPromptsDuringLiveRenderablesTests.cs +++ b/test/Spectre.Console.Analyzer.Tests/Unit/Analyzers/NoPromptsDuringLiveRenderablesTests.cs @@ -1,20 +1,15 @@ -using System.Threading.Tasks; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Testing; -using Xunit; +namespace Spectre.Console.Analyzer.Tests.Unit.Analyzers; -namespace Spectre.Console.Analyzer.Tests.Unit.Analyzers +public class NoPromptsDuringLiveRenderablesTests { - public class NoPromptsDuringLiveRenderablesTests - { - private static readonly DiagnosticResult _expectedDiagnostics = new( - Descriptors.S1021_AvoidPromptCallsDuringLiveRenderables.Id, - DiagnosticSeverity.Warning); + private static readonly DiagnosticResult _expectedDiagnostics = new( + Descriptors.S1021_AvoidPromptCallsDuringLiveRenderables.Id, + DiagnosticSeverity.Warning); - [Fact] - public async Task Prompt_out_of_progress_does_not_warn() - { - const string Source = @" + [Fact] + public async Task Prompt_out_of_progress_does_not_warn() + { + const string Source = @" using Spectre.Console; class TestClass @@ -25,15 +20,15 @@ class TestClass } }"; - await SpectreAnalyzerVerifier - .VerifyAnalyzerAsync(Source) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyAnalyzerAsync(Source) + .ConfigureAwait(false); + } - [Fact] - public async Task Instance_variables_warn() - { - const string Source = @" + [Fact] + public async Task Instance_variables_warn() + { + const string Source = @" using Spectre.Console; class TestClass @@ -49,15 +44,15 @@ class TestClass } }"; - await SpectreAnalyzerVerifier - .VerifyAnalyzerAsync(Source, _expectedDiagnostics.WithLocation(12, 26)) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyAnalyzerAsync(Source, _expectedDiagnostics.WithLocation(12, 26)) + .ConfigureAwait(false); + } - [Fact] - public async Task Prompt_in_progress_warns() - { - const string Source = @" + [Fact] + public async Task Prompt_in_progress_warns() + { + const string Source = @" using Spectre.Console; class TestClass @@ -71,15 +66,15 @@ class TestClass } }"; - await SpectreAnalyzerVerifier - .VerifyAnalyzerAsync(Source, _expectedDiagnostics.WithLocation(10, 13)) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyAnalyzerAsync(Source, _expectedDiagnostics.WithLocation(10, 13)) + .ConfigureAwait(false); + } - [Fact] - public async Task Can_call_other_methods_from_within_renderables() - { - const string Source = @" + [Fact] + public async Task Can_call_other_methods_from_within_renderables() + { + const string Source = @" using Spectre.Console; class Program @@ -96,9 +91,8 @@ class Program static string Confirm() => string.Empty; }"; - await SpectreAnalyzerVerifier - .VerifyAnalyzerAsync(Source) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyAnalyzerAsync(Source) + .ConfigureAwait(false); } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Analyzer.Tests/Unit/Analyzers/UseInstanceAnsiConsoleTests.cs b/test/Spectre.Console.Analyzer.Tests/Unit/Analyzers/UseInstanceAnsiConsoleTests.cs index 87f535c..08e75d0 100644 --- a/test/Spectre.Console.Analyzer.Tests/Unit/Analyzers/UseInstanceAnsiConsoleTests.cs +++ b/test/Spectre.Console.Analyzer.Tests/Unit/Analyzers/UseInstanceAnsiConsoleTests.cs @@ -1,19 +1,15 @@ -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Testing; -using Xunit; +namespace Spectre.Console.Analyzer.Tests.Unit.Analyzers; -namespace Spectre.Console.Analyzer.Tests.Unit.Analyzers +public class FavorInstanceAnsiConsoleOverStaticAnalyzerTests { - public class FavorInstanceAnsiConsoleOverStaticAnalyzerTests - { - private static readonly DiagnosticResult _expectedDiagnostics = new( - Descriptors.S1010_FavorInstanceAnsiConsoleOverStatic.Id, - DiagnosticSeverity.Info); + private static readonly DiagnosticResult _expectedDiagnostics = new( + Descriptors.S1010_FavorInstanceAnsiConsoleOverStatic.Id, + DiagnosticSeverity.Info); - [Fact] - public async void Should_only_warn_within_methods() - { - const string Source = @" + [Fact] + public async void Should_only_warn_within_methods() + { + const string Source = @" using Spectre.Console; internal sealed class Foo @@ -27,15 +23,15 @@ internal sealed class Foo } "; - await SpectreAnalyzerVerifier - .VerifyAnalyzerAsync(Source) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyAnalyzerAsync(Source) + .ConfigureAwait(false); + } - [Fact] - public async void Instance_console_has_no_warnings() - { - const string Source = @" + [Fact] + public async void Instance_console_has_no_warnings() + { + const string Source = @" using Spectre.Console; class TestClass @@ -48,15 +44,15 @@ class TestClass } }"; - await SpectreAnalyzerVerifier - .VerifyAnalyzerAsync(Source) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyAnalyzerAsync(Source) + .ConfigureAwait(false); + } - [Fact] - public async void Static_console_with_no_instance_variables_has_no_warnings() - { - const string Source = @" + [Fact] + public async void Static_console_with_no_instance_variables_has_no_warnings() + { + const string Source = @" using Spectre.Console; class TestClass @@ -67,15 +63,15 @@ class TestClass } }"; - await SpectreAnalyzerVerifier - .VerifyAnalyzerAsync(Source) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyAnalyzerAsync(Source) + .ConfigureAwait(false); + } - [Fact] - public async void Console_Write_Has_Warning() - { - const string Source = @" + [Fact] + public async void Console_Write_Has_Warning() + { + const string Source = @" using Spectre.Console; class TestClass @@ -89,9 +85,8 @@ class TestClass } }"; - await SpectreAnalyzerVerifier - .VerifyAnalyzerAsync(Source, _expectedDiagnostics.WithLocation(11, 9)) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyAnalyzerAsync(Source, _expectedDiagnostics.WithLocation(11, 9)) + .ConfigureAwait(false); } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Analyzer.Tests/Unit/Analyzers/UseSpectreInsteadOfSystemConsoleAnalyzerTests.cs b/test/Spectre.Console.Analyzer.Tests/Unit/Analyzers/UseSpectreInsteadOfSystemConsoleAnalyzerTests.cs index cdd996c..aebabbf 100644 --- a/test/Spectre.Console.Analyzer.Tests/Unit/Analyzers/UseSpectreInsteadOfSystemConsoleAnalyzerTests.cs +++ b/test/Spectre.Console.Analyzer.Tests/Unit/Analyzers/UseSpectreInsteadOfSystemConsoleAnalyzerTests.cs @@ -1,19 +1,15 @@ -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Testing; -using Xunit; +namespace Spectre.Console.Analyzer.Tests.Unit.Analyzers; -namespace Spectre.Console.Analyzer.Tests.Unit.Analyzers +public class UseSpectreInsteadOfSystemConsoleAnalyzerTests { - public class UseSpectreInsteadOfSystemConsoleAnalyzerTests - { - private static readonly DiagnosticResult _expectedDiagnostics = new( - Descriptors.S1000_UseAnsiConsoleOverSystemConsole.Id, - DiagnosticSeverity.Warning); + private static readonly DiagnosticResult _expectedDiagnostics = new( + Descriptors.S1000_UseAnsiConsoleOverSystemConsole.Id, + DiagnosticSeverity.Warning); - [Fact] - public async void Non_configured_SystemConsole_methods_report_no_warnings() - { - const string Source = @" + [Fact] + public async void Non_configured_SystemConsole_methods_report_no_warnings() + { + const string Source = @" using System; class TestClass { @@ -23,15 +19,15 @@ class TestClass { } }"; - await SpectreAnalyzerVerifier - .VerifyAnalyzerAsync(Source) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyAnalyzerAsync(Source) + .ConfigureAwait(false); + } - [Fact] - public async void Console_Write_Has_Warning() - { - const string Source = @" + [Fact] + public async void Console_Write_Has_Warning() + { + const string Source = @" using System; class TestClass { @@ -41,15 +37,15 @@ class TestClass { } }"; - await SpectreAnalyzerVerifier - .VerifyAnalyzerAsync(Source, _expectedDiagnostics.WithLocation(7, 9)) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyAnalyzerAsync(Source, _expectedDiagnostics.WithLocation(7, 9)) + .ConfigureAwait(false); + } - [Fact] - public async void Console_WriteLine_Has_Warning() - { - const string Source = @" + [Fact] + public async void Console_WriteLine_Has_Warning() + { + const string Source = @" using System; class TestClass @@ -59,9 +55,8 @@ class TestClass } }"; - await SpectreAnalyzerVerifier - .VerifyAnalyzerAsync(Source, _expectedDiagnostics.WithLocation(7, 9)) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyAnalyzerAsync(Source, _expectedDiagnostics.WithLocation(7, 9)) + .ConfigureAwait(false); } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Analyzer.Tests/Unit/Fixes/UseInstanceOfStaticAnsiConsoleTests.cs b/test/Spectre.Console.Analyzer.Tests/Unit/Fixes/UseInstanceOfStaticAnsiConsoleTests.cs index 4137129..c308eaf 100644 --- a/test/Spectre.Console.Analyzer.Tests/Unit/Fixes/UseInstanceOfStaticAnsiConsoleTests.cs +++ b/test/Spectre.Console.Analyzer.Tests/Unit/Fixes/UseInstanceOfStaticAnsiConsoleTests.cs @@ -1,20 +1,15 @@ -using System.Threading.Tasks; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Testing; -using Xunit; +namespace Spectre.Console.Analyzer.Tests.Unit.Fixes; -namespace Spectre.Console.Analyzer.Tests.Unit.Fixes +public class UseInstanceOfStaticAnsiConsoleTests { - public class UseInstanceOfStaticAnsiConsoleTests - { - private static readonly DiagnosticResult _expectedDiagnostic = new( - Descriptors.S1010_FavorInstanceAnsiConsoleOverStatic.Id, - DiagnosticSeverity.Info); + private static readonly DiagnosticResult _expectedDiagnostic = new( + Descriptors.S1010_FavorInstanceAnsiConsoleOverStatic.Id, + DiagnosticSeverity.Info); - [Fact] - public async Task Static_call_replaced_with_field_call() - { - const string Source = @" + [Fact] + public async Task Static_call_replaced_with_field_call() + { + const string Source = @" using Spectre.Console; class TestClass @@ -28,7 +23,7 @@ class TestClass } }"; - const string FixedSource = @" + const string FixedSource = @" using Spectre.Console; class TestClass @@ -42,15 +37,15 @@ class TestClass } }"; - await SpectreAnalyzerVerifier - .VerifyCodeFixAsync(Source, _expectedDiagnostic.WithLocation(11, 9), FixedSource) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyCodeFixAsync(Source, _expectedDiagnostic.WithLocation(11, 9), FixedSource) + .ConfigureAwait(false); + } - [Fact] - public async Task Static_call_replaced_with_field_call_Should_Preserve_Trivia() - { - const string Source = @" + [Fact] + public async Task Static_call_replaced_with_field_call_Should_Preserve_Trivia() + { + const string Source = @" using Spectre.Console; class TestClass @@ -66,7 +61,7 @@ class TestClass } }"; - const string FixedSource = @" + const string FixedSource = @" using Spectre.Console; class TestClass @@ -82,15 +77,15 @@ class TestClass } }"; - await SpectreAnalyzerVerifier - .VerifyCodeFixAsync(Source, _expectedDiagnostic.WithLocation(12, 9), FixedSource) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyCodeFixAsync(Source, _expectedDiagnostic.WithLocation(12, 9), FixedSource) + .ConfigureAwait(false); + } - [Fact] - public async Task Static_call_replaced_with_parameter_call() - { - const string Source = @" + [Fact] + public async Task Static_call_replaced_with_parameter_call() + { + const string Source = @" using Spectre.Console; class TestClass @@ -101,7 +96,7 @@ class TestClass } }"; - const string FixedSource = @" + const string FixedSource = @" using Spectre.Console; class TestClass @@ -112,15 +107,15 @@ class TestClass } }"; - await SpectreAnalyzerVerifier - .VerifyCodeFixAsync(Source, _expectedDiagnostic.WithLocation(8, 9), FixedSource) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyCodeFixAsync(Source, _expectedDiagnostic.WithLocation(8, 9), FixedSource) + .ConfigureAwait(false); + } - [Fact] - public async Task Static_call_replaced_with_static_field_if_valid() - { - const string Source = @" + [Fact] + public async Task Static_call_replaced_with_static_field_if_valid() + { + const string Source = @" using Spectre.Console; class TestClass @@ -134,7 +129,7 @@ class TestClass } }"; - const string FixedSource = @" + const string FixedSource = @" using Spectre.Console; class TestClass @@ -148,9 +143,8 @@ class TestClass } }"; - await SpectreAnalyzerVerifier - .VerifyCodeFixAsync(Source, _expectedDiagnostic.WithLocation(11, 9), FixedSource) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyCodeFixAsync(Source, _expectedDiagnostic.WithLocation(11, 9), FixedSource) + .ConfigureAwait(false); } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Analyzer.Tests/Unit/Fixes/UseSpectreInsteadOfSystemConsoleFixTests.cs b/test/Spectre.Console.Analyzer.Tests/Unit/Fixes/UseSpectreInsteadOfSystemConsoleFixTests.cs index 3719b60..3e2a7e3 100644 --- a/test/Spectre.Console.Analyzer.Tests/Unit/Fixes/UseSpectreInsteadOfSystemConsoleFixTests.cs +++ b/test/Spectre.Console.Analyzer.Tests/Unit/Fixes/UseSpectreInsteadOfSystemConsoleFixTests.cs @@ -1,20 +1,15 @@ -using System.Threading.Tasks; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Testing; -using Xunit; +namespace Spectre.Console.Analyzer.Tests.Unit.Fixes; -namespace Spectre.Console.Analyzer.Tests.Unit.Fixes +public class UseSpectreInsteadOfSystemConsoleFixTests { - public class UseSpectreInsteadOfSystemConsoleFixTests - { - private static readonly DiagnosticResult _expectedDiagnostic = new( - Descriptors.S1000_UseAnsiConsoleOverSystemConsole.Id, - DiagnosticSeverity.Warning); + private static readonly DiagnosticResult _expectedDiagnostic = new( + Descriptors.S1000_UseAnsiConsoleOverSystemConsole.Id, + DiagnosticSeverity.Warning); - [Fact] - public async Task SystemConsole_replaced_with_AnsiConsole() - { - const string Source = @" + [Fact] + public async Task SystemConsole_replaced_with_AnsiConsole() + { + const string Source = @" using System; class TestClass @@ -25,7 +20,7 @@ class TestClass } }"; - const string FixedSource = @" + const string FixedSource = @" using System; using Spectre.Console; @@ -37,15 +32,15 @@ class TestClass } }"; - await SpectreAnalyzerVerifier - .VerifyCodeFixAsync(Source, _expectedDiagnostic.WithLocation(8, 9), FixedSource) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyCodeFixAsync(Source, _expectedDiagnostic.WithLocation(8, 9), FixedSource) + .ConfigureAwait(false); + } - [Fact] - public async Task SystemConsole_replaced_with_imported_AnsiConsole() - { - const string Source = @" + [Fact] + public async Task SystemConsole_replaced_with_imported_AnsiConsole() + { + const string Source = @" using System; class TestClass @@ -56,7 +51,7 @@ class TestClass } }"; - const string FixedSource = @" + const string FixedSource = @" using System; using Spectre.Console; @@ -68,15 +63,15 @@ class TestClass } }"; - await SpectreAnalyzerVerifier - .VerifyCodeFixAsync(Source, _expectedDiagnostic.WithLocation(8, 9), FixedSource) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyCodeFixAsync(Source, _expectedDiagnostic.WithLocation(8, 9), FixedSource) + .ConfigureAwait(false); + } - [Fact] - public async Task SystemConsole_replaced_with_field_AnsiConsole() - { - const string Source = @" + [Fact] + public async Task SystemConsole_replaced_with_field_AnsiConsole() + { + const string Source = @" using System; using Spectre.Console; @@ -90,7 +85,7 @@ class TestClass } }"; - const string FixedSource = @" + const string FixedSource = @" using System; using Spectre.Console; @@ -104,15 +99,15 @@ class TestClass } }"; - await SpectreAnalyzerVerifier - .VerifyCodeFixAsync(Source, _expectedDiagnostic.WithLocation(11, 9), FixedSource) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyCodeFixAsync(Source, _expectedDiagnostic.WithLocation(11, 9), FixedSource) + .ConfigureAwait(false); + } - [Fact] - public async Task SystemConsole_replaced_with_static_field_AnsiConsole() - { - const string Source = @" + [Fact] + public async Task SystemConsole_replaced_with_static_field_AnsiConsole() + { + const string Source = @" using System; using Spectre.Console; @@ -126,7 +121,7 @@ class TestClass } }"; - const string FixedSource = @" + const string FixedSource = @" using System; using Spectre.Console; @@ -140,9 +135,8 @@ class TestClass } }"; - await SpectreAnalyzerVerifier - .VerifyCodeFixAsync(Source, _expectedDiagnostic.WithLocation(11, 9), FixedSource) - .ConfigureAwait(false); - } + await SpectreAnalyzerVerifier + .VerifyCodeFixAsync(Source, _expectedDiagnostic.WithLocation(11, 9), FixedSource) + .ConfigureAwait(false); } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Constants.cs b/test/Spectre.Console.Tests/Constants.cs index 7edf4ce..33af244 100644 --- a/test/Spectre.Console.Tests/Constants.cs +++ b/test/Spectre.Console.Tests/Constants.cs @@ -1,21 +1,18 @@ -using Spectre.Console.Cli; +namespace Spectre.Console.Tests; -namespace Spectre.Console.Tests +public static class Constants { - public static class Constants - { - public static string[] VersionCommand { get; } = - new[] - { + public static string[] VersionCommand { get; } = + new[] + { CliConstants.Commands.Branch, CliConstants.Commands.Version, - }; + }; - public static string[] XmlDocCommand { get; } = - new[] - { + public static string[] XmlDocCommand { get; } = + new[] + { CliConstants.Commands.Branch, CliConstants.Commands.XmlDoc, - }; - } -} \ No newline at end of file + }; +} diff --git a/test/Spectre.Console.Tests/Data/Commands/AnimalCommand.cs b/test/Spectre.Console.Tests/Data/Commands/AnimalCommand.cs index 3101f52..0419ec6 100644 --- a/test/Spectre.Console.Tests/Data/Commands/AnimalCommand.cs +++ b/test/Spectre.Console.Tests/Data/Commands/AnimalCommand.cs @@ -1,49 +1,45 @@ -using System; -using System.Linq; -using Spectre.Console.Cli; using SystemConsole = System.Console; -namespace Spectre.Console.Tests.Data +namespace Spectre.Console.Tests.Data; + +public abstract class AnimalCommand : Command + where TSettings : CommandSettings { - public abstract class AnimalCommand : Command - where TSettings : CommandSettings + protected void DumpSettings(CommandContext context, TSettings settings) { - protected void DumpSettings(CommandContext context, TSettings settings) + if (context == null) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } - - var properties = settings.GetType().GetProperties(); - foreach (var group in properties.GroupBy(x => x.DeclaringType).Reverse()) - { - SystemConsole.WriteLine(); - SystemConsole.ForegroundColor = ConsoleColor.Yellow; - SystemConsole.WriteLine(group.Key.FullName); - SystemConsole.ResetColor(); - - foreach (var property in group) - { - SystemConsole.WriteLine($" {property.Name} = {property.GetValue(settings)}"); - } - } - - if (context.Remaining.Raw.Count > 0) - { - SystemConsole.WriteLine(); - SystemConsole.ForegroundColor = ConsoleColor.Yellow; - SystemConsole.WriteLine("Remaining:"); - SystemConsole.ResetColor(); - SystemConsole.WriteLine(string.Join(", ", context.Remaining)); - } - - SystemConsole.WriteLine(); + throw new ArgumentNullException(nameof(context)); } + + if (settings == null) + { + throw new ArgumentNullException(nameof(settings)); + } + + var properties = settings.GetType().GetProperties(); + foreach (var group in properties.GroupBy(x => x.DeclaringType).Reverse()) + { + SystemConsole.WriteLine(); + SystemConsole.ForegroundColor = ConsoleColor.Yellow; + SystemConsole.WriteLine(group.Key.FullName); + SystemConsole.ResetColor(); + + foreach (var property in group) + { + SystemConsole.WriteLine($" {property.Name} = {property.GetValue(settings)}"); + } + } + + if (context.Remaining.Raw.Count > 0) + { + SystemConsole.WriteLine(); + SystemConsole.ForegroundColor = ConsoleColor.Yellow; + SystemConsole.WriteLine("Remaining:"); + SystemConsole.ResetColor(); + SystemConsole.WriteLine(string.Join(", ", context.Remaining)); + } + + SystemConsole.WriteLine(); } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Data/Commands/CatCommand.cs b/test/Spectre.Console.Tests/Data/Commands/CatCommand.cs index d0ca715..7e756e7 100644 --- a/test/Spectre.Console.Tests/Data/Commands/CatCommand.cs +++ b/test/Spectre.Console.Tests/Data/Commands/CatCommand.cs @@ -1,13 +1,10 @@ -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public class CatCommand : AnimalCommand { - public class CatCommand : AnimalCommand + public override int Execute(CommandContext context, CatSettings settings) { - public override int Execute(CommandContext context, CatSettings settings) - { - DumpSettings(context, settings); - return 0; - } + DumpSettings(context, settings); + return 0; } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Data/Commands/DogCommand.cs b/test/Spectre.Console.Tests/Data/Commands/DogCommand.cs index fb37c1d..3b6ed69 100644 --- a/test/Spectre.Console.Tests/Data/Commands/DogCommand.cs +++ b/test/Spectre.Console.Tests/Data/Commands/DogCommand.cs @@ -1,36 +1,31 @@ -using System.ComponentModel; -using System.Linq; -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +[Description("The dog command.")] +public class DogCommand : AnimalCommand { - [Description("The dog command.")] - public class DogCommand : AnimalCommand + public override ValidationResult Validate(CommandContext context, DogSettings settings) { - public override ValidationResult Validate(CommandContext context, DogSettings settings) + if (context is null) { - if (context is null) - { - throw new System.ArgumentNullException(nameof(context)); - } - - if (settings is null) - { - throw new System.ArgumentNullException(nameof(settings)); - } - - if (settings.Age > 100 && !context.Remaining.Raw.Contains("zombie")) - { - return ValidationResult.Error("Dog is too old..."); - } - - return base.Validate(context, settings); + throw new System.ArgumentNullException(nameof(context)); } - public override int Execute(CommandContext context, DogSettings settings) + if (settings is null) { - DumpSettings(context, settings); - return 0; + throw new System.ArgumentNullException(nameof(settings)); } + + if (settings.Age > 100 && !context.Remaining.Raw.Contains("zombie")) + { + return ValidationResult.Error("Dog is too old..."); + } + + return base.Validate(context, settings); } -} \ No newline at end of file + + public override int Execute(CommandContext context, DogSettings settings) + { + DumpSettings(context, settings); + return 0; + } +} diff --git a/test/Spectre.Console.Tests/Data/Commands/DumpRemainingCommand.cs b/test/Spectre.Console.Tests/Data/Commands/DumpRemainingCommand.cs index 2d3dcf3..c769c01 100644 --- a/test/Spectre.Console.Tests/Data/Commands/DumpRemainingCommand.cs +++ b/test/Spectre.Console.Tests/Data/Commands/DumpRemainingCommand.cs @@ -1,39 +1,34 @@ -using System.Diagnostics.CodeAnalysis; -using System.Linq; -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public sealed class DumpRemainingCommand : Command { - public sealed class DumpRemainingCommand : Command + private readonly IAnsiConsole _console; + + public DumpRemainingCommand(IAnsiConsole console) { - private readonly IAnsiConsole _console; - - public DumpRemainingCommand(IAnsiConsole console) - { - _console = console; - } - - public override int Execute([NotNull] CommandContext context, [NotNull] EmptyCommandSettings settings) - { - if (context.Remaining.Raw.Count > 0) - { - _console.WriteLine("# Raw"); - foreach (var item in context.Remaining.Raw) - { - _console.WriteLine(item); - } - } - - if (context.Remaining.Parsed.Count > 0) - { - _console.WriteLine("# Parsed"); - foreach (var item in context.Remaining.Parsed) - { - _console.WriteLine(string.Format("{0}={1}", item.Key, string.Join(",", item.Select(x => x)))); - } - } - - return 0; - } + _console = console; } -} \ No newline at end of file + + public override int Execute([NotNull] CommandContext context, [NotNull] EmptyCommandSettings settings) + { + if (context.Remaining.Raw.Count > 0) + { + _console.WriteLine("# Raw"); + foreach (var item in context.Remaining.Raw) + { + _console.WriteLine(item); + } + } + + if (context.Remaining.Parsed.Count > 0) + { + _console.WriteLine("# Parsed"); + foreach (var item in context.Remaining.Parsed) + { + _console.WriteLine(string.Format("{0}={1}", item.Key, string.Join(",", item.Select(x => x)))); + } + } + + return 0; + } +} diff --git a/test/Spectre.Console.Tests/Data/Commands/EmptyCommand.cs b/test/Spectre.Console.Tests/Data/Commands/EmptyCommand.cs index 89c772f..6ab3390 100644 --- a/test/Spectre.Console.Tests/Data/Commands/EmptyCommand.cs +++ b/test/Spectre.Console.Tests/Data/Commands/EmptyCommand.cs @@ -1,12 +1,9 @@ -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public sealed class EmptyCommand : Command { - public sealed class EmptyCommand : Command + public override int Execute(CommandContext context, EmptyCommandSettings settings) { - public override int Execute(CommandContext context, EmptyCommandSettings settings) - { - return 0; - } + return 0; } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Data/Commands/GenericCommand.cs b/test/Spectre.Console.Tests/Data/Commands/GenericCommand.cs index dae87f1..a0ae21c 100644 --- a/test/Spectre.Console.Tests/Data/Commands/GenericCommand.cs +++ b/test/Spectre.Console.Tests/Data/Commands/GenericCommand.cs @@ -1,13 +1,10 @@ -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public sealed class GenericCommand : Command + where TSettings : CommandSettings { - public sealed class GenericCommand : Command - where TSettings : CommandSettings + public override int Execute(CommandContext context, TSettings settings) { - public override int Execute(CommandContext context, TSettings settings) - { - return 0; - } + return 0; } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Data/Commands/GiraffeCommand.cs b/test/Spectre.Console.Tests/Data/Commands/GiraffeCommand.cs index 5d207f1..87d0f04 100644 --- a/test/Spectre.Console.Tests/Data/Commands/GiraffeCommand.cs +++ b/test/Spectre.Console.Tests/Data/Commands/GiraffeCommand.cs @@ -1,14 +1,10 @@ -using System.ComponentModel; -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +[Description("The giraffe command.")] +public sealed class GiraffeCommand : Command { - [Description("The giraffe command.")] - public sealed class GiraffeCommand : Command + public override int Execute(CommandContext context, GiraffeSettings settings) { - public override int Execute(CommandContext context, GiraffeSettings settings) - { - return 0; - } + return 0; } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Data/Commands/HiddenOptionsCommand.cs b/test/Spectre.Console.Tests/Data/Commands/HiddenOptionsCommand.cs index 2f50764..dded24c 100644 --- a/test/Spectre.Console.Tests/Data/Commands/HiddenOptionsCommand.cs +++ b/test/Spectre.Console.Tests/Data/Commands/HiddenOptionsCommand.cs @@ -1,12 +1,9 @@ -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public sealed class HiddenOptionsCommand : Command { - public sealed class HiddenOptionsCommand : Command + public override int Execute(CommandContext context, HiddenOptionSettings settings) { - public override int Execute(CommandContext context, HiddenOptionSettings settings) - { - return 0; - } + return 0; } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Data/Commands/HorseCommand.cs b/test/Spectre.Console.Tests/Data/Commands/HorseCommand.cs index ccaa4d5..4b10806 100644 --- a/test/Spectre.Console.Tests/Data/Commands/HorseCommand.cs +++ b/test/Spectre.Console.Tests/Data/Commands/HorseCommand.cs @@ -1,15 +1,11 @@ -using System.ComponentModel; -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +[Description("The horse command.")] +public class HorseCommand : AnimalCommand { - [Description("The horse command.")] - public class HorseCommand : AnimalCommand + public override int Execute(CommandContext context, MammalSettings settings) { - public override int Execute(CommandContext context, MammalSettings settings) - { - DumpSettings(context, settings); - return 0; - } + DumpSettings(context, settings); + return 0; } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Data/Commands/InvalidCommand.cs b/test/Spectre.Console.Tests/Data/Commands/InvalidCommand.cs index 361172a..27ee205 100644 --- a/test/Spectre.Console.Tests/Data/Commands/InvalidCommand.cs +++ b/test/Spectre.Console.Tests/Data/Commands/InvalidCommand.cs @@ -1,12 +1,9 @@ -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public sealed class InvalidCommand : Command { - public sealed class InvalidCommand : Command + public override int Execute(CommandContext context, InvalidSettings settings) { - public override int Execute(CommandContext context, InvalidSettings settings) - { - return 0; - } + return 0; } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Data/Commands/LionCommand.cs b/test/Spectre.Console.Tests/Data/Commands/LionCommand.cs index f63bcf0..eb7dfa5 100644 --- a/test/Spectre.Console.Tests/Data/Commands/LionCommand.cs +++ b/test/Spectre.Console.Tests/Data/Commands/LionCommand.cs @@ -1,14 +1,10 @@ -using System.ComponentModel; -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +[Description("The lion command.")] +public class LionCommand : AnimalCommand { - [Description("The lion command.")] - public class LionCommand : AnimalCommand + public override int Execute(CommandContext context, LionSettings settings) { - public override int Execute(CommandContext context, LionSettings settings) - { - return 0; - } + return 0; } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Data/Commands/NoDescriptionCommand.cs b/test/Spectre.Console.Tests/Data/Commands/NoDescriptionCommand.cs index 09c9ddf..8cb86b6 100644 --- a/test/Spectre.Console.Tests/Data/Commands/NoDescriptionCommand.cs +++ b/test/Spectre.Console.Tests/Data/Commands/NoDescriptionCommand.cs @@ -1,16 +1,12 @@ -using System.Diagnostics.CodeAnalysis; -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public sealed class NoDescriptionCommand : Command { - public sealed class NoDescriptionCommand : Command - { - [CommandOption("-f|--foo ")] - public int Foo { get; set; } + [CommandOption("-f|--foo ")] + public int Foo { get; set; } - public override int Execute([NotNull] CommandContext context, [NotNull] EmptyCommandSettings settings) - { - return 0; - } + public override int Execute([NotNull] CommandContext context, [NotNull] EmptyCommandSettings settings) + { + return 0; } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Data/Commands/OptionVectorCommand.cs b/test/Spectre.Console.Tests/Data/Commands/OptionVectorCommand.cs index a10bda2..a892881 100644 --- a/test/Spectre.Console.Tests/Data/Commands/OptionVectorCommand.cs +++ b/test/Spectre.Console.Tests/Data/Commands/OptionVectorCommand.cs @@ -1,12 +1,9 @@ -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public class OptionVectorCommand : Command { - public class OptionVectorCommand : Command + public override int Execute(CommandContext context, OptionVectorSettings settings) { - public override int Execute(CommandContext context, OptionVectorSettings settings) - { - return 0; - } + return 0; } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Data/Commands/ThrowingCommand.cs b/test/Spectre.Console.Tests/Data/Commands/ThrowingCommand.cs index 5ebe084..686bf4a 100644 --- a/test/Spectre.Console.Tests/Data/Commands/ThrowingCommand.cs +++ b/test/Spectre.Console.Tests/Data/Commands/ThrowingCommand.cs @@ -1,17 +1,13 @@ -using System; -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public sealed class ThrowingCommand : Command { - public sealed class ThrowingCommand : Command + public override int Execute(CommandContext context, ThrowingCommandSettings settings) { - public override int Execute(CommandContext context, ThrowingCommandSettings settings) - { - throw new InvalidOperationException("W00t?"); - } + throw new InvalidOperationException("W00t?"); } +} - public sealed class ThrowingCommandSettings : CommandSettings - { - } -} \ No newline at end of file +public sealed class ThrowingCommandSettings : CommandSettings +{ +} diff --git a/test/Spectre.Console.Tests/Data/Converters/CatAgilityConverter.cs b/test/Spectre.Console.Tests/Data/Converters/CatAgilityConverter.cs index c6535ef..043b82c 100644 --- a/test/Spectre.Console.Tests/Data/Converters/CatAgilityConverter.cs +++ b/test/Spectre.Console.Tests/Data/Converters/CatAgilityConverter.cs @@ -1,18 +1,14 @@ -using System.ComponentModel; -using System.Globalization; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public sealed class CatAgilityConverter : TypeConverter { - public sealed class CatAgilityConverter : TypeConverter + public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + if (value is string stringValue) { - if (value is string stringValue) - { - return stringValue.Length; - } - - return base.ConvertFrom(context, culture, value); + return stringValue.Length; } + + return base.ConvertFrom(context, culture, value); } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Data/Converters/StringToIntegerConverter.cs b/test/Spectre.Console.Tests/Data/Converters/StringToIntegerConverter.cs index 934eaee..dc30c09 100644 --- a/test/Spectre.Console.Tests/Data/Converters/StringToIntegerConverter.cs +++ b/test/Spectre.Console.Tests/Data/Converters/StringToIntegerConverter.cs @@ -1,18 +1,14 @@ -using System.ComponentModel; -using System.Globalization; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public sealed class StringToIntegerConverter : TypeConverter { - public sealed class StringToIntegerConverter : TypeConverter + public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + if (value is string stringValue) { - if (value is string stringValue) - { - return int.Parse(stringValue, CultureInfo.InvariantCulture); - } - - return base.ConvertFrom(context, culture, value); + return int.Parse(stringValue, CultureInfo.InvariantCulture); } + + return base.ConvertFrom(context, culture, value); } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Data/Exceptions.cs b/test/Spectre.Console.Tests/Data/Exceptions.cs index ee0b787..eebf59c 100644 --- a/test/Spectre.Console.Tests/Data/Exceptions.cs +++ b/test/Spectre.Console.Tests/Data/Exceptions.cs @@ -1,35 +1,32 @@ -using System; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public static class TestExceptions { - public static class TestExceptions + public static bool MethodThatThrows(int? number) => throw new InvalidOperationException("Throwing!"); + + public static bool GenericMethodThatThrows(int? number) => throw new InvalidOperationException("Throwing!"); + + public static void ThrowWithInnerException() { - public static bool MethodThatThrows(int? number) => throw new InvalidOperationException("Throwing!"); - - public static bool GenericMethodThatThrows(int? number) => throw new InvalidOperationException("Throwing!"); - - public static void ThrowWithInnerException() + try { - try - { - MethodThatThrows(null); - } - catch (Exception ex) - { - throw new InvalidOperationException("Something threw!", ex); - } + MethodThatThrows(null); } - - public static void ThrowWithGenericInnerException() + catch (Exception ex) { - try - { - GenericMethodThatThrows(null); - } - catch (Exception ex) - { - throw new InvalidOperationException("Something threw!", ex); - } + throw new InvalidOperationException("Something threw!", ex); } } -} \ No newline at end of file + + public static void ThrowWithGenericInnerException() + { + try + { + GenericMethodThatThrows(null); + } + catch (Exception ex) + { + throw new InvalidOperationException("Something threw!", ex); + } + } +} diff --git a/test/Spectre.Console.Tests/Data/Settings/AnimalSettings.cs b/test/Spectre.Console.Tests/Data/Settings/AnimalSettings.cs index 8e81d7e..0e077a4 100644 --- a/test/Spectre.Console.Tests/Data/Settings/AnimalSettings.cs +++ b/test/Spectre.Console.Tests/Data/Settings/AnimalSettings.cs @@ -1,18 +1,14 @@ -using System.ComponentModel; -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public abstract class AnimalSettings : CommandSettings { - public abstract class AnimalSettings : CommandSettings - { - [CommandOption("-a|--alive|--not-dead")] - [Description("Indicates whether or not the animal is alive.")] - public bool IsAlive { get; set; } + [CommandOption("-a|--alive|--not-dead")] + [Description("Indicates whether or not the animal is alive.")] + public bool IsAlive { get; set; } - [CommandArgument(1, "[LEGS]")] - [Description("The number of legs.")] - [EvenNumberValidator("Animals must have an even number of legs.")] - [PositiveNumberValidator("Number of legs must be greater than 0.")] - public int Legs { get; set; } - } -} \ No newline at end of file + [CommandArgument(1, "[LEGS]")] + [Description("The number of legs.")] + [EvenNumberValidator("Animals must have an even number of legs.")] + [PositiveNumberValidator("Number of legs must be greater than 0.")] + public int Legs { get; set; } +} diff --git a/test/Spectre.Console.Tests/Data/Settings/ArgumentOrderSettings.cs b/test/Spectre.Console.Tests/Data/Settings/ArgumentOrderSettings.cs index d8650c7..cc56b91 100644 --- a/test/Spectre.Console.Tests/Data/Settings/ArgumentOrderSettings.cs +++ b/test/Spectre.Console.Tests/Data/Settings/ArgumentOrderSettings.cs @@ -1,22 +1,19 @@ -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public sealed class ArgumentOrderSettings : CommandSettings { - public sealed class ArgumentOrderSettings : CommandSettings - { - [CommandArgument(0, "[QUX]")] - public int Qux { get; set; } + [CommandArgument(0, "[QUX]")] + public int Qux { get; set; } - [CommandArgument(3, "")] - public int Corgi { get; set; } + [CommandArgument(3, "")] + public int Corgi { get; set; } - [CommandArgument(1, "")] - public int Bar { get; set; } + [CommandArgument(1, "")] + public int Bar { get; set; } - [CommandArgument(2, "")] - public int Baz { get; set; } + [CommandArgument(2, "")] + public int Baz { get; set; } - [CommandArgument(0, "")] - public int Foo { get; set; } - } -} \ No newline at end of file + [CommandArgument(0, "")] + public int Foo { get; set; } +} diff --git a/test/Spectre.Console.Tests/Data/Settings/ArgumentVectorSettings.cs b/test/Spectre.Console.Tests/Data/Settings/ArgumentVectorSettings.cs index c68ab34..63b7f48 100644 --- a/test/Spectre.Console.Tests/Data/Settings/ArgumentVectorSettings.cs +++ b/test/Spectre.Console.Tests/Data/Settings/ArgumentVectorSettings.cs @@ -1,10 +1,7 @@ -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public class ArgumentVectorSettings : CommandSettings { - public class ArgumentVectorSettings : CommandSettings - { - [CommandArgument(0, "")] - public string[] Foo { get; set; } - } -} \ No newline at end of file + [CommandArgument(0, "")] + public string[] Foo { get; set; } +} diff --git a/test/Spectre.Console.Tests/Data/Settings/BarCommandSettings.cs b/test/Spectre.Console.Tests/Data/Settings/BarCommandSettings.cs index 8b116db..27f94d5 100644 --- a/test/Spectre.Console.Tests/Data/Settings/BarCommandSettings.cs +++ b/test/Spectre.Console.Tests/Data/Settings/BarCommandSettings.cs @@ -1,12 +1,8 @@ -using System.ComponentModel; -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public class BarCommandSettings : FooCommandSettings { - public class BarCommandSettings : FooCommandSettings - { - [CommandArgument(0, "")] - [Description("The corgi value.")] - public string Corgi { get; set; } - } -} \ No newline at end of file + [CommandArgument(0, "")] + [Description("The corgi value.")] + public string Corgi { get; set; } +} diff --git a/test/Spectre.Console.Tests/Data/Settings/CatSettings.cs b/test/Spectre.Console.Tests/Data/Settings/CatSettings.cs index 2677c73..64c911b 100644 --- a/test/Spectre.Console.Tests/Data/Settings/CatSettings.cs +++ b/test/Spectre.Console.Tests/Data/Settings/CatSettings.cs @@ -1,15 +1,11 @@ -using System.ComponentModel; -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public class CatSettings : MammalSettings { - public class CatSettings : MammalSettings - { - [CommandOption("--agility ")] - [TypeConverter(typeof(CatAgilityConverter))] - [DefaultValue(10)] - [Description("The agility between 0 and 100.")] - [PositiveNumberValidator("Agility cannot be negative.")] - public int Agility { get; set; } - } -} \ No newline at end of file + [CommandOption("--agility ")] + [TypeConverter(typeof(CatAgilityConverter))] + [DefaultValue(10)] + [Description("The agility between 0 and 100.")] + [PositiveNumberValidator("Agility cannot be negative.")] + public int Agility { get; set; } +} diff --git a/test/Spectre.Console.Tests/Data/Settings/DogSettings.cs b/test/Spectre.Console.Tests/Data/Settings/DogSettings.cs index aa79c6f..b5c3cf8 100644 --- a/test/Spectre.Console.Tests/Data/Settings/DogSettings.cs +++ b/test/Spectre.Console.Tests/Data/Settings/DogSettings.cs @@ -1,23 +1,20 @@ -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public sealed class DogSettings : MammalSettings { - public sealed class DogSettings : MammalSettings + [CommandArgument(0, "")] + public int Age { get; set; } + + [CommandOption("-g|--good-boy")] + public bool GoodBoy { get; set; } + + public override ValidationResult Validate() { - [CommandArgument(0, "")] - public int Age { get; set; } - - [CommandOption("-g|--good-boy")] - public bool GoodBoy { get; set; } - - public override ValidationResult Validate() + if (Name == "Tiger") { - if (Name == "Tiger") - { - return ValidationResult.Error("Tiger is not a dog name!"); - } - - return ValidationResult.Success(); + return ValidationResult.Error("Tiger is not a dog name!"); } + + return ValidationResult.Success(); } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Data/Settings/EmptySettings.cs b/test/Spectre.Console.Tests/Data/Settings/EmptySettings.cs index 200d60f..c42baf3 100644 --- a/test/Spectre.Console.Tests/Data/Settings/EmptySettings.cs +++ b/test/Spectre.Console.Tests/Data/Settings/EmptySettings.cs @@ -1,8 +1,5 @@ -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public sealed class EmptySettings : CommandSettings { - public sealed class EmptySettings : CommandSettings - { - } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Data/Settings/FooSettings.cs b/test/Spectre.Console.Tests/Data/Settings/FooSettings.cs index 602618a..542f205 100644 --- a/test/Spectre.Console.Tests/Data/Settings/FooSettings.cs +++ b/test/Spectre.Console.Tests/Data/Settings/FooSettings.cs @@ -1,12 +1,8 @@ -using System.ComponentModel; -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public class FooCommandSettings : CommandSettings { - public class FooCommandSettings : CommandSettings - { - [CommandArgument(0, "[QUX]")] - [Description("The qux value.")] - public string Qux { get; set; } - } -} \ No newline at end of file + [CommandArgument(0, "[QUX]")] + [Description("The qux value.")] + public string Qux { get; set; } +} diff --git a/test/Spectre.Console.Tests/Data/Settings/GiraffeSettings.cs b/test/Spectre.Console.Tests/Data/Settings/GiraffeSettings.cs index a308b88..c46e521 100644 --- a/test/Spectre.Console.Tests/Data/Settings/GiraffeSettings.cs +++ b/test/Spectre.Console.Tests/Data/Settings/GiraffeSettings.cs @@ -1,12 +1,8 @@ -using System.ComponentModel; -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public sealed class GiraffeSettings : MammalSettings { - public sealed class GiraffeSettings : MammalSettings - { - [CommandArgument(0, "")] - [Description("The option description.")] - public int Length { get; set; } - } -} \ No newline at end of file + [CommandArgument(0, "")] + [Description("The option description.")] + public int Length { get; set; } +} diff --git a/test/Spectre.Console.Tests/Data/Settings/HiddenOptionSettings.cs b/test/Spectre.Console.Tests/Data/Settings/HiddenOptionSettings.cs index 878949b..209d56b 100644 --- a/test/Spectre.Console.Tests/Data/Settings/HiddenOptionSettings.cs +++ b/test/Spectre.Console.Tests/Data/Settings/HiddenOptionSettings.cs @@ -1,20 +1,16 @@ -using System.ComponentModel; -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public sealed class HiddenOptionSettings : CommandSettings { - public sealed class HiddenOptionSettings : CommandSettings - { - [CommandArgument(0, "")] - [Description("Dummy argument FOO")] - public int Foo { get; set; } + [CommandArgument(0, "")] + [Description("Dummy argument FOO")] + public int Foo { get; set; } - [CommandOption("--bar", IsHidden = true)] - [Description("You should not be able to read this unless you used the 'cli explain' command with the '--hidden' option")] - public int Bar { get; set; } + [CommandOption("--bar", IsHidden = true)] + [Description("You should not be able to read this unless you used the 'cli explain' command with the '--hidden' option")] + public int Bar { get; set; } - [CommandOption("--baz")] - [Description("Dummy option BAZ")] - public int Baz { get; set; } - } -} \ No newline at end of file + [CommandOption("--baz")] + [Description("Dummy option BAZ")] + public int Baz { get; set; } +} diff --git a/test/Spectre.Console.Tests/Data/Settings/InvalidSettings.cs b/test/Spectre.Console.Tests/Data/Settings/InvalidSettings.cs index 73ba15b..4191838 100644 --- a/test/Spectre.Console.Tests/Data/Settings/InvalidSettings.cs +++ b/test/Spectre.Console.Tests/Data/Settings/InvalidSettings.cs @@ -1,10 +1,7 @@ -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public sealed class InvalidSettings : CommandSettings { - public sealed class InvalidSettings : CommandSettings - { - [CommandOption("-f|--foo [BAR]")] - public string Value { get; set; } - } -} \ No newline at end of file + [CommandOption("-f|--foo [BAR]")] + public string Value { get; set; } +} diff --git a/test/Spectre.Console.Tests/Data/Settings/LionSettings.cs b/test/Spectre.Console.Tests/Data/Settings/LionSettings.cs index 301bd5c..19aa6f2 100644 --- a/test/Spectre.Console.Tests/Data/Settings/LionSettings.cs +++ b/test/Spectre.Console.Tests/Data/Settings/LionSettings.cs @@ -1,16 +1,12 @@ -using System.ComponentModel; -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public class LionSettings : CatSettings { - public class LionSettings : CatSettings - { - [CommandArgument(0, "")] - [Description("The number of teeth the lion has.")] - public int Teeth { get; set; } + [CommandArgument(0, "")] + [Description("The number of teeth the lion has.")] + public int Teeth { get; set; } - [CommandOption("-c ")] - [Description("The number of children the lion has.")] - public int Children { get; set; } - } -} \ No newline at end of file + [CommandOption("-c ")] + [Description("The number of children the lion has.")] + public int Children { get; set; } +} diff --git a/test/Spectre.Console.Tests/Data/Settings/MammalSettings.cs b/test/Spectre.Console.Tests/Data/Settings/MammalSettings.cs index 79a2018..7b1c455 100644 --- a/test/Spectre.Console.Tests/Data/Settings/MammalSettings.cs +++ b/test/Spectre.Console.Tests/Data/Settings/MammalSettings.cs @@ -1,10 +1,7 @@ -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public class MammalSettings : AnimalSettings { - public class MammalSettings : AnimalSettings - { - [CommandOption("-n|-p|--name|--pet-name ")] - public string Name { get; set; } - } -} \ No newline at end of file + [CommandOption("-n|-p|--name|--pet-name ")] + public string Name { get; set; } +} diff --git a/test/Spectre.Console.Tests/Data/Settings/MultipleArgumentVectorSettings.cs b/test/Spectre.Console.Tests/Data/Settings/MultipleArgumentVectorSettings.cs index 6a97b15..2dda29c 100644 --- a/test/Spectre.Console.Tests/Data/Settings/MultipleArgumentVectorSettings.cs +++ b/test/Spectre.Console.Tests/Data/Settings/MultipleArgumentVectorSettings.cs @@ -1,22 +1,19 @@ -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public class MultipleArgumentVectorSettings : CommandSettings { - public class MultipleArgumentVectorSettings : CommandSettings - { - [CommandArgument(0, "")] - public string[] Foo { get; set; } + [CommandArgument(0, "")] + public string[] Foo { get; set; } - [CommandArgument(0, "")] - public string[] Bar { get; set; } - } + [CommandArgument(0, "")] + public string[] Bar { get; set; } +} - public class MultipleArgumentVectorSpecifiedFirstSettings : CommandSettings - { - [CommandArgument(1, "[Bar]")] - public string Bar { get; set; } +public class MultipleArgumentVectorSpecifiedFirstSettings : CommandSettings +{ + [CommandArgument(1, "[Bar]")] + public string Bar { get; set; } - [CommandArgument(0, "")] - public string[] Foo { get; set; } - } -} \ No newline at end of file + [CommandArgument(0, "")] + public string[] Foo { get; set; } +} diff --git a/test/Spectre.Console.Tests/Data/Settings/OptionVectorSettings.cs b/test/Spectre.Console.Tests/Data/Settings/OptionVectorSettings.cs index 44cbbe0..138b359 100644 --- a/test/Spectre.Console.Tests/Data/Settings/OptionVectorSettings.cs +++ b/test/Spectre.Console.Tests/Data/Settings/OptionVectorSettings.cs @@ -1,13 +1,10 @@ -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public class OptionVectorSettings : CommandSettings { - public class OptionVectorSettings : CommandSettings - { - [CommandOption("--foo")] - public string[] Foo { get; set; } + [CommandOption("--foo")] + public string[] Foo { get; set; } - [CommandOption("--bar")] - public int[] Bar { get; set; } - } -} \ No newline at end of file + [CommandOption("--bar")] + public int[] Bar { get; set; } +} diff --git a/test/Spectre.Console.Tests/Data/Settings/OptionalArgumentWithDefaultValueSettings.cs b/test/Spectre.Console.Tests/Data/Settings/OptionalArgumentWithDefaultValueSettings.cs index d6d82de..d5167b0 100644 --- a/test/Spectre.Console.Tests/Data/Settings/OptionalArgumentWithDefaultValueSettings.cs +++ b/test/Spectre.Console.Tests/Data/Settings/OptionalArgumentWithDefaultValueSettings.cs @@ -1,40 +1,35 @@ -using System; -using System.ComponentModel; -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public sealed class OptionalArgumentWithDefaultValueSettings : CommandSettings { - public sealed class OptionalArgumentWithDefaultValueSettings : CommandSettings - { - [CommandArgument(0, "[GREETING]")] - [DefaultValue("Hello World")] - public string Greeting { get; set; } - } + [CommandArgument(0, "[GREETING]")] + [DefaultValue("Hello World")] + public string Greeting { get; set; } +} - public sealed class OptionalArgumentWithPropertyInitializerSettings : CommandSettings - { - [CommandArgument(0, "[NAMES]")] - public string[] Names { get; set; } = Array.Empty(); +public sealed class OptionalArgumentWithPropertyInitializerSettings : CommandSettings +{ + [CommandArgument(0, "[NAMES]")] + public string[] Names { get; set; } = Array.Empty(); - [CommandOption("-c")] - public int Count { get; set; } = 1; + [CommandOption("-c")] + public int Count { get; set; } = 1; - [CommandOption("-v")] - public int Value { get; set; } = 0; - } + [CommandOption("-v")] + public int Value { get; set; } = 0; +} - public sealed class OptionalArgumentWithDefaultValueAndTypeConverterSettings : CommandSettings - { - [CommandArgument(0, "[GREETING]")] - [DefaultValue("5")] - [TypeConverter(typeof(StringToIntegerConverter))] - public int Greeting { get; set; } - } +public sealed class OptionalArgumentWithDefaultValueAndTypeConverterSettings : CommandSettings +{ + [CommandArgument(0, "[GREETING]")] + [DefaultValue("5")] + [TypeConverter(typeof(StringToIntegerConverter))] + public int Greeting { get; set; } +} - public sealed class RequiredArgumentWithDefaultValueSettings : CommandSettings - { - [CommandArgument(0, "")] - [DefaultValue("Hello World")] - public string Greeting { get; set; } - } -} \ No newline at end of file +public sealed class RequiredArgumentWithDefaultValueSettings : CommandSettings +{ + [CommandArgument(0, "")] + [DefaultValue("Hello World")] + public string Greeting { get; set; } +} diff --git a/test/Spectre.Console.Tests/Data/Settings/StringOptionSettings.cs b/test/Spectre.Console.Tests/Data/Settings/StringOptionSettings.cs index ca7afff..272383d 100644 --- a/test/Spectre.Console.Tests/Data/Settings/StringOptionSettings.cs +++ b/test/Spectre.Console.Tests/Data/Settings/StringOptionSettings.cs @@ -1,10 +1,7 @@ -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +public sealed class StringOptionSettings : CommandSettings { - public sealed class StringOptionSettings : CommandSettings - { - [CommandOption("-f|--foo")] - public string Foo { get; set; } - } -} \ No newline at end of file + [CommandOption("-f|--foo")] + public string Foo { get; set; } +} diff --git a/test/Spectre.Console.Tests/Data/Validators/EvenNumberValidatorAttribute.cs b/test/Spectre.Console.Tests/Data/Validators/EvenNumberValidatorAttribute.cs index f19b6e8..01601f4 100644 --- a/test/Spectre.Console.Tests/Data/Validators/EvenNumberValidatorAttribute.cs +++ b/test/Spectre.Console.Tests/Data/Validators/EvenNumberValidatorAttribute.cs @@ -1,29 +1,25 @@ -using System; -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] +public sealed class EvenNumberValidatorAttribute : ParameterValidationAttribute { - [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] - public sealed class EvenNumberValidatorAttribute : ParameterValidationAttribute + public EvenNumberValidatorAttribute(string errorMessage) + : base(errorMessage) { - public EvenNumberValidatorAttribute(string errorMessage) - : base(errorMessage) - { - } + } - public override ValidationResult Validate(CommandParameterContext context) + public override ValidationResult Validate(CommandParameterContext context) + { + if (context.Value is int integer) { - if (context.Value is int integer) + if (integer % 2 == 0) { - if (integer % 2 == 0) - { - return ValidationResult.Success(); - } - - return ValidationResult.Error($"Number is not even ({context.Parameter.PropertyName})."); + return ValidationResult.Success(); } - throw new InvalidOperationException($"Parameter is not a number ({context.Parameter.PropertyName})."); + return ValidationResult.Error($"Number is not even ({context.Parameter.PropertyName})."); } + + throw new InvalidOperationException($"Parameter is not a number ({context.Parameter.PropertyName})."); } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Data/Validators/PositiveNumberValidatorAttribute.cs b/test/Spectre.Console.Tests/Data/Validators/PositiveNumberValidatorAttribute.cs index afb329a..94bab60 100644 --- a/test/Spectre.Console.Tests/Data/Validators/PositiveNumberValidatorAttribute.cs +++ b/test/Spectre.Console.Tests/Data/Validators/PositiveNumberValidatorAttribute.cs @@ -1,29 +1,25 @@ -using System; -using Spectre.Console.Cli; +namespace Spectre.Console.Tests.Data; -namespace Spectre.Console.Tests.Data +[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] +public sealed class PositiveNumberValidatorAttribute : ParameterValidationAttribute { - [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] - public sealed class PositiveNumberValidatorAttribute : ParameterValidationAttribute + public PositiveNumberValidatorAttribute(string errorMessage) + : base(errorMessage) { - public PositiveNumberValidatorAttribute(string errorMessage) - : base(errorMessage) - { - } + } - public override ValidationResult Validate(CommandParameterContext context) + public override ValidationResult Validate(CommandParameterContext context) + { + if (context.Value is int integer) { - if (context.Value is int integer) + if (integer > 0) { - if (integer > 0) - { - return ValidationResult.Success(); - } - - return ValidationResult.Error($"Number is not greater than 0 ({context.Parameter.PropertyName})."); + return ValidationResult.Success(); } - throw new InvalidOperationException($"Parameter is not a number ({context.Parameter.PropertyName})."); + return ValidationResult.Error($"Number is not greater than 0 ({context.Parameter.PropertyName})."); } + + throw new InvalidOperationException($"Parameter is not a number ({context.Parameter.PropertyName})."); } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Properties/Usings.cs b/test/Spectre.Console.Tests/Properties/Usings.cs new file mode 100644 index 0000000..a76e400 --- /dev/null +++ b/test/Spectre.Console.Tests/Properties/Usings.cs @@ -0,0 +1,24 @@ +global using System; +global using System.Collections.Generic; +global using System.ComponentModel; +global using System.Diagnostics; +global using System.Diagnostics.CodeAnalysis; +global using System.Globalization; +global using System.IO; +global using System.Linq; +global using System.Reflection; +global using System.Runtime.CompilerServices; +global using System.Text.RegularExpressions; +global using System.Threading; +global using System.Threading.Tasks; +global using Shouldly; +global using Spectre.Console.Advanced; +global using Spectre.Console.Cli; +global using Spectre.Console.Cli.Unsafe; +global using Spectre.Console.Rendering; +global using Spectre.Console.Testing; +global using Spectre.Console.Tests.Data; +global using Spectre.Verify.Extensions; +global using VerifyTests; +global using VerifyXunit; +global using Xunit; \ No newline at end of file diff --git a/test/Spectre.Console.Tests/Spectre.Console.Tests.csproj b/test/Spectre.Console.Tests/Spectre.Console.Tests.csproj index d3e5802..dddacfc 100644 --- a/test/Spectre.Console.Tests/Spectre.Console.Tests.csproj +++ b/test/Spectre.Console.Tests/Spectre.Console.Tests.csproj @@ -1,9 +1,12 @@ + + + + net6.0;net5.0;net48 net6.0;net5.0 - 9.0 diff --git a/test/Spectre.Console.Tests/Unit/AlternateScreenTests.cs b/test/Spectre.Console.Tests/Unit/AlternateScreenTests.cs index d20e8b6..696a9e7 100644 --- a/test/Spectre.Console.Tests/Unit/AlternateScreenTests.cs +++ b/test/Spectre.Console.Tests/Unit/AlternateScreenTests.cs @@ -1,79 +1,71 @@ -using System.Threading.Tasks; -using Shouldly; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("AlternateScreen")] +public sealed class AlternateScreenTests { - [UsesVerify] - [ExpectationPath("AlternateScreen")] - public sealed class AlternateScreenTests + [Fact] + public void Should_Throw_If_Alternative_Buffer_Is_Not_Supported_By_Terminal() { - [Fact] - public void Should_Throw_If_Alternative_Buffer_Is_Not_Supported_By_Terminal() + // Given + var console = new TestConsole(); + console.Profile.Capabilities.AlternateBuffer = false; + + // When + var result = Record.Exception(() => { - // Given - var console = new TestConsole(); - console.Profile.Capabilities.AlternateBuffer = false; - - // When - var result = Record.Exception(() => - { - console.WriteLine("Foo"); - console.AlternateScreen(() => - { - console.WriteLine("Bar"); - }); - }); - - // Then - result.ShouldNotBeNull(); - result.Message.ShouldBe("Alternate buffers are not supported by your terminal."); - } - - [Fact] - public void Should_Throw_If_Ansi_Is_Not_Supported_By_Terminal() - { - // Given - var console = new TestConsole(); - console.Profile.Capabilities.Ansi = false; - console.Profile.Capabilities.AlternateBuffer = true; - - // When - var result = Record.Exception(() => - { - console.WriteLine("Foo"); - console.AlternateScreen(() => - { - console.WriteLine("Bar"); - }); - }); - - // Then - result.ShouldNotBeNull(); - result.Message.ShouldBe("Alternate buffers are not supported since your terminal does not support ANSI."); - } - - [Fact] - [Expectation("Show")] - public async Task Should_Write_To_Alternate_Screen() - { - // Given - var console = new TestConsole(); - console.EmitAnsiSequences = true; - console.Profile.Capabilities.AlternateBuffer = true; - - // When console.WriteLine("Foo"); console.AlternateScreen(() => { console.WriteLine("Bar"); }); + }); - // Then - await Verifier.Verify(console.Output); - } + // Then + result.ShouldNotBeNull(); + result.Message.ShouldBe("Alternate buffers are not supported by your terminal."); } -} \ No newline at end of file + + [Fact] + public void Should_Throw_If_Ansi_Is_Not_Supported_By_Terminal() + { + // Given + var console = new TestConsole(); + console.Profile.Capabilities.Ansi = false; + console.Profile.Capabilities.AlternateBuffer = true; + + // When + var result = Record.Exception(() => + { + console.WriteLine("Foo"); + console.AlternateScreen(() => + { + console.WriteLine("Bar"); + }); + }); + + // Then + result.ShouldNotBeNull(); + result.Message.ShouldBe("Alternate buffers are not supported since your terminal does not support ANSI."); + } + + [Fact] + [Expectation("Show")] + public async Task Should_Write_To_Alternate_Screen() + { + // Given + var console = new TestConsole(); + console.EmitAnsiSequences = true; + console.Profile.Capabilities.AlternateBuffer = true; + + // When + console.WriteLine("Foo"); + console.AlternateScreen(() => + { + console.WriteLine("Bar"); + }); + + // Then + await Verifier.Verify(console.Output); + } +} diff --git a/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Advanced.cs b/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Advanced.cs index 94943a0..9c1282c 100644 --- a/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Advanced.cs +++ b/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Advanced.cs @@ -1,61 +1,55 @@ -using Shouldly; -using Spectre.Console.Advanced; -using Spectre.Console.Testing; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +public sealed partial class AnsiConsoleTests { - public sealed partial class AnsiConsoleTests + public sealed class Advanced { - public sealed class Advanced + [Fact] + public void Should_Write_Ansi_Codes_To_Console_If_Supported() { - [Fact] - public void Should_Write_Ansi_Codes_To_Console_If_Supported() - { - // Given - var console = new TestConsole() - .SupportsAnsi(true) - .Colors(ColorSystem.Standard) - .EmitAnsiSequences(); + // Given + var console = new TestConsole() + .SupportsAnsi(true) + .Colors(ColorSystem.Standard) + .EmitAnsiSequences(); - // When - console.WriteAnsi("Hello"); + // When + console.WriteAnsi("Hello"); - // Then - console.Output.NormalizeLineEndings() - .ShouldBe("Hello"); - } + // Then + console.Output.NormalizeLineEndings() + .ShouldBe("Hello"); + } - [Fact] - public void Should_Not_Write_Ansi_Codes_To_Console_If_Not_Supported() - { - // Given - var console = new TestConsole() - .SupportsAnsi(false) - .Colors(ColorSystem.Standard) - .EmitAnsiSequences(); + [Fact] + public void Should_Not_Write_Ansi_Codes_To_Console_If_Not_Supported() + { + // Given + var console = new TestConsole() + .SupportsAnsi(false) + .Colors(ColorSystem.Standard) + .EmitAnsiSequences(); - // When - console.WriteAnsi("Hello"); + // When + console.WriteAnsi("Hello"); - // Then - console.Output.NormalizeLineEndings() - .ShouldBeEmpty(); - } + // Then + console.Output.NormalizeLineEndings() + .ShouldBeEmpty(); + } - [Fact] - public void Should_Return_Ansi_For_Renderable() - { - // Given - var console = new TestConsole().Colors(ColorSystem.TrueColor); - var markup = new Console.Markup("[yellow]Hello [blue]World[/]![/]"); + [Fact] + public void Should_Return_Ansi_For_Renderable() + { + // Given + var console = new TestConsole().Colors(ColorSystem.TrueColor); + var markup = new Console.Markup("[yellow]Hello [blue]World[/]![/]"); - // When - var result = console.ToAnsi(markup); + // When + var result = console.ToAnsi(markup); - // Then - result.ShouldBe("Hello World!"); - } + // Then + result.ShouldBe("Hello World!"); } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Colors.cs b/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Colors.cs index 28fb0cc..329d09d 100644 --- a/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Colors.cs +++ b/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Colors.cs @@ -1,248 +1,242 @@ -using System.IO; -using Shouldly; -using Spectre.Console.Testing; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +public partial class AnsiConsoleTests { - public partial class AnsiConsoleTests + [Theory] + [InlineData(ColorSystemSupport.NoColors, ColorSystem.NoColors)] + [InlineData(ColorSystemSupport.Legacy, ColorSystem.Legacy)] + [InlineData(ColorSystemSupport.Standard, ColorSystem.Standard)] + [InlineData(ColorSystemSupport.EightBit, ColorSystem.EightBit)] + [InlineData(ColorSystemSupport.TrueColor, ColorSystem.TrueColor)] + public void Should_Create_Console_With_Requested_ColorSystem(ColorSystemSupport requested, ColorSystem expected) + { + // Given, When + var console = AnsiConsole.Create(new AnsiConsoleSettings + { + ColorSystem = requested, + Out = new AnsiConsoleOutput(new StringWriter()), + }); + + // Then + console.Profile.Capabilities.ColorSystem.ShouldBe(expected); + } + + public sealed class TrueColor { [Theory] - [InlineData(ColorSystemSupport.NoColors, ColorSystem.NoColors)] - [InlineData(ColorSystemSupport.Legacy, ColorSystem.Legacy)] - [InlineData(ColorSystemSupport.Standard, ColorSystem.Standard)] - [InlineData(ColorSystemSupport.EightBit, ColorSystem.EightBit)] - [InlineData(ColorSystemSupport.TrueColor, ColorSystem.TrueColor)] - public void Should_Create_Console_With_Requested_ColorSystem(ColorSystemSupport requested, ColorSystem expected) + [InlineData(true, "\u001b[38;2;128;0;128mHello\u001b[0m")] + [InlineData(false, "\u001b[48;2;128;0;128mHello\u001b[0m")] + public void Should_Return_Correct_Code(bool foreground, string expected) { - // Given, When - var console = AnsiConsole.Create(new AnsiConsoleSettings - { - ColorSystem = requested, - Out = new AnsiConsoleOutput(new StringWriter()), - }); + // Given + var console = new TestConsole() + .Colors(ColorSystem.TrueColor) + .EmitAnsiSequences(); + + // When + console.Write("Hello", new Style().SetColor(new Color(128, 0, 128), foreground)); // Then - console.Profile.Capabilities.ColorSystem.ShouldBe(expected); + console.Output.ShouldBe(expected); } - public sealed class TrueColor + [Theory] + [InlineData(true, "\u001b[38;5;5mHello\u001b[0m")] + [InlineData(false, "\u001b[48;5;5mHello\u001b[0m")] + public void Should_Return_Eight_Bit_Ansi_Code_For_Known_Colors(bool foreground, string expected) { - [Theory] - [InlineData(true, "\u001b[38;2;128;0;128mHello\u001b[0m")] - [InlineData(false, "\u001b[48;2;128;0;128mHello\u001b[0m")] - public void Should_Return_Correct_Code(bool foreground, string expected) - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.TrueColor) - .EmitAnsiSequences(); + // Given + var console = new TestConsole() + .Colors(ColorSystem.TrueColor) + .EmitAnsiSequences(); - // When - console.Write("Hello", new Style().SetColor(new Color(128, 0, 128), foreground)); + // When + console.Write("Hello", new Style().SetColor(Color.Purple, foreground)); - // Then - console.Output.ShouldBe(expected); - } - - [Theory] - [InlineData(true, "\u001b[38;5;5mHello\u001b[0m")] - [InlineData(false, "\u001b[48;5;5mHello\u001b[0m")] - public void Should_Return_Eight_Bit_Ansi_Code_For_Known_Colors(bool foreground, string expected) - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.TrueColor) - .EmitAnsiSequences(); - - // When - console.Write("Hello", new Style().SetColor(Color.Purple, foreground)); - - // Then - console.Output.ShouldBe(expected); - } - } - - public sealed class EightBit - { - [Theory] - [InlineData(true, "\u001b[38;5;3mHello\u001b[0m")] - [InlineData(false, "\u001b[48;5;3mHello\u001b[0m")] - public void Should_Return_Correct_Code_For_Known_Color(bool foreground, string expected) - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.EightBit) - .EmitAnsiSequences(); - - // When - console.Write("Hello", new Style().SetColor(Color.Olive, foreground)); - - // Then - console.Output.ShouldBe(expected); - } - - [Theory] - [InlineData(true, "\u001b[38;5;3mHello\u001b[0m")] - [InlineData(false, "\u001b[48;5;3mHello\u001b[0m")] - public void Should_Map_TrueColor_To_Nearest_Eight_Bit_Color_If_Possible(bool foreground, string expected) - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.EightBit) - .EmitAnsiSequences(); - - // When - console.Write("Hello", new Style().SetColor(new Color(128, 128, 0), foreground)); - - // Then - console.Output.ShouldBe(expected); - } - - [Theory] - [InlineData(true, "\u001b[38;5;3mHello\u001b[0m")] - [InlineData(false, "\u001b[48;5;3mHello\u001b[0m")] - public void Should_Estimate_TrueColor_To_Nearest_Eight_Bit_Color(bool foreground, string expected) - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.EightBit) - .EmitAnsiSequences(); - - // When - console.Write("Hello", new Style().SetColor(new Color(126, 127, 0), foreground)); - - // Then - console.Output.ShouldBe(expected); - } - } - - public sealed class Standard - { - [Theory] - [InlineData(true, "\u001b[33mHello\u001b[0m")] - [InlineData(false, "\u001b[43mHello\u001b[0m")] - public void Should_Return_Correct_Code_For_Known_Color(bool foreground, string expected) - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.Standard) - .EmitAnsiSequences(); - - // When - console.Write("Hello", new Style().SetColor(Color.Olive, foreground)); - - // Then - console.Output.ShouldBe(expected); - } - - [Theory] - [InlineData(true, 128, 128, 128, "\u001b[90mHello\u001b[0m")] - [InlineData(false, 128, 128, 128, "\u001b[100mHello\u001b[0m")] - [InlineData(true, 0, 128, 0, "\u001b[32mHello\u001b[0m")] - [InlineData(false, 0, 128, 0, "\u001b[42mHello\u001b[0m")] - public void Should_Map_TrueColor_To_Nearest_Four_Bit_Color_If_Possible( - bool foreground, - byte r, byte g, byte b, - string expected) - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.Standard) - .EmitAnsiSequences(); - - // When - console.Write("Hello", new Style().SetColor(new Color(r, g, b), foreground)); - - // Then - console.Output.ShouldBe(expected); - } - - [Theory] - [InlineData(true, 112, 120, 128, "\u001b[90mHello\u001b[0m")] - [InlineData(false, 112, 120, 128, "\u001b[100mHello\u001b[0m")] - [InlineData(true, 0, 120, 12, "\u001b[32mHello\u001b[0m")] - [InlineData(false, 0, 120, 12, "\u001b[42mHello\u001b[0m")] - public void Should_Estimate_TrueColor_To_Nearest_Four_Bit_Color( - bool foreground, - byte r, byte g, byte b, - string expected) - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.Standard) - .EmitAnsiSequences(); - - // When - console.Write("Hello", new Style().SetColor(new Color(r, g, b), foreground)); - - // Then - console.Output.ShouldBe(expected); - } - } - - public sealed class Legacy - { - [Theory] - [InlineData(true, "\u001b[33mHello\u001b[0m")] - [InlineData(false, "\u001b[43mHello\u001b[0m")] - public void Should_Return_Correct_Code_For_Known_Color(bool foreground, string expected) - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.Legacy) - .EmitAnsiSequences(); - - // When - console.Write("Hello", new Style().SetColor(Color.Olive, foreground)); - - // Then - console.Output.ShouldBe(expected); - } - - [Theory] - [InlineData(true, 128, 128, 128, "\u001b[37mHello\u001b[0m")] - [InlineData(false, 128, 128, 128, "\u001b[47mHello\u001b[0m")] - [InlineData(true, 0, 128, 0, "\u001b[32mHello\u001b[0m")] - [InlineData(false, 0, 128, 0, "\u001b[42mHello\u001b[0m")] - public void Should_Map_TrueColor_To_Nearest_Three_Bit_Color_If_Possible( - bool foreground, - byte r, byte g, byte b, - string expected) - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.Legacy) - .EmitAnsiSequences(); - - // When - console.Write("Hello", new Style().SetColor(new Color(r, g, b), foreground)); - - // Then - console.Output.ShouldBe(expected); - } - - [Theory] - [InlineData(true, 112, 120, 128, "\u001b[36mHello\u001b[0m")] - [InlineData(false, 112, 120, 128, "\u001b[46mHello\u001b[0m")] - [InlineData(true, 0, 120, 12, "\u001b[32mHello\u001b[0m")] - [InlineData(false, 0, 120, 12, "\u001b[42mHello\u001b[0m")] - public void Should_Estimate_TrueColor_To_Nearest_Three_Bit_Color( - bool foreground, - byte r, byte g, byte b, - string expected) - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.Legacy) - .EmitAnsiSequences(); - - // When - console.Write("Hello", new Style().SetColor(new Color(r, g, b), foreground)); - - // Then - console.Output.ShouldBe(expected); - } + // Then + console.Output.ShouldBe(expected); } } -} \ No newline at end of file + + public sealed class EightBit + { + [Theory] + [InlineData(true, "\u001b[38;5;3mHello\u001b[0m")] + [InlineData(false, "\u001b[48;5;3mHello\u001b[0m")] + public void Should_Return_Correct_Code_For_Known_Color(bool foreground, string expected) + { + // Given + var console = new TestConsole() + .Colors(ColorSystem.EightBit) + .EmitAnsiSequences(); + + // When + console.Write("Hello", new Style().SetColor(Color.Olive, foreground)); + + // Then + console.Output.ShouldBe(expected); + } + + [Theory] + [InlineData(true, "\u001b[38;5;3mHello\u001b[0m")] + [InlineData(false, "\u001b[48;5;3mHello\u001b[0m")] + public void Should_Map_TrueColor_To_Nearest_Eight_Bit_Color_If_Possible(bool foreground, string expected) + { + // Given + var console = new TestConsole() + .Colors(ColorSystem.EightBit) + .EmitAnsiSequences(); + + // When + console.Write("Hello", new Style().SetColor(new Color(128, 128, 0), foreground)); + + // Then + console.Output.ShouldBe(expected); + } + + [Theory] + [InlineData(true, "\u001b[38;5;3mHello\u001b[0m")] + [InlineData(false, "\u001b[48;5;3mHello\u001b[0m")] + public void Should_Estimate_TrueColor_To_Nearest_Eight_Bit_Color(bool foreground, string expected) + { + // Given + var console = new TestConsole() + .Colors(ColorSystem.EightBit) + .EmitAnsiSequences(); + + // When + console.Write("Hello", new Style().SetColor(new Color(126, 127, 0), foreground)); + + // Then + console.Output.ShouldBe(expected); + } + } + + public sealed class Standard + { + [Theory] + [InlineData(true, "\u001b[33mHello\u001b[0m")] + [InlineData(false, "\u001b[43mHello\u001b[0m")] + public void Should_Return_Correct_Code_For_Known_Color(bool foreground, string expected) + { + // Given + var console = new TestConsole() + .Colors(ColorSystem.Standard) + .EmitAnsiSequences(); + + // When + console.Write("Hello", new Style().SetColor(Color.Olive, foreground)); + + // Then + console.Output.ShouldBe(expected); + } + + [Theory] + [InlineData(true, 128, 128, 128, "\u001b[90mHello\u001b[0m")] + [InlineData(false, 128, 128, 128, "\u001b[100mHello\u001b[0m")] + [InlineData(true, 0, 128, 0, "\u001b[32mHello\u001b[0m")] + [InlineData(false, 0, 128, 0, "\u001b[42mHello\u001b[0m")] + public void Should_Map_TrueColor_To_Nearest_Four_Bit_Color_If_Possible( + bool foreground, + byte r, byte g, byte b, + string expected) + { + // Given + var console = new TestConsole() + .Colors(ColorSystem.Standard) + .EmitAnsiSequences(); + + // When + console.Write("Hello", new Style().SetColor(new Color(r, g, b), foreground)); + + // Then + console.Output.ShouldBe(expected); + } + + [Theory] + [InlineData(true, 112, 120, 128, "\u001b[90mHello\u001b[0m")] + [InlineData(false, 112, 120, 128, "\u001b[100mHello\u001b[0m")] + [InlineData(true, 0, 120, 12, "\u001b[32mHello\u001b[0m")] + [InlineData(false, 0, 120, 12, "\u001b[42mHello\u001b[0m")] + public void Should_Estimate_TrueColor_To_Nearest_Four_Bit_Color( + bool foreground, + byte r, byte g, byte b, + string expected) + { + // Given + var console = new TestConsole() + .Colors(ColorSystem.Standard) + .EmitAnsiSequences(); + + // When + console.Write("Hello", new Style().SetColor(new Color(r, g, b), foreground)); + + // Then + console.Output.ShouldBe(expected); + } + } + + public sealed class Legacy + { + [Theory] + [InlineData(true, "\u001b[33mHello\u001b[0m")] + [InlineData(false, "\u001b[43mHello\u001b[0m")] + public void Should_Return_Correct_Code_For_Known_Color(bool foreground, string expected) + { + // Given + var console = new TestConsole() + .Colors(ColorSystem.Legacy) + .EmitAnsiSequences(); + + // When + console.Write("Hello", new Style().SetColor(Color.Olive, foreground)); + + // Then + console.Output.ShouldBe(expected); + } + + [Theory] + [InlineData(true, 128, 128, 128, "\u001b[37mHello\u001b[0m")] + [InlineData(false, 128, 128, 128, "\u001b[47mHello\u001b[0m")] + [InlineData(true, 0, 128, 0, "\u001b[32mHello\u001b[0m")] + [InlineData(false, 0, 128, 0, "\u001b[42mHello\u001b[0m")] + public void Should_Map_TrueColor_To_Nearest_Three_Bit_Color_If_Possible( + bool foreground, + byte r, byte g, byte b, + string expected) + { + // Given + var console = new TestConsole() + .Colors(ColorSystem.Legacy) + .EmitAnsiSequences(); + + // When + console.Write("Hello", new Style().SetColor(new Color(r, g, b), foreground)); + + // Then + console.Output.ShouldBe(expected); + } + + [Theory] + [InlineData(true, 112, 120, 128, "\u001b[36mHello\u001b[0m")] + [InlineData(false, 112, 120, 128, "\u001b[46mHello\u001b[0m")] + [InlineData(true, 0, 120, 12, "\u001b[32mHello\u001b[0m")] + [InlineData(false, 0, 120, 12, "\u001b[42mHello\u001b[0m")] + public void Should_Estimate_TrueColor_To_Nearest_Three_Bit_Color( + bool foreground, + byte r, byte g, byte b, + string expected) + { + // Given + var console = new TestConsole() + .Colors(ColorSystem.Legacy) + .EmitAnsiSequences(); + + // When + console.Write("Hello", new Style().SetColor(new Color(r, g, b), foreground)); + + // Then + console.Output.ShouldBe(expected); + } + } +} diff --git a/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Cursor.cs b/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Cursor.cs index b0bf600..6fe8e41 100644 --- a/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Cursor.cs +++ b/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Cursor.cs @@ -1,52 +1,47 @@ -using Shouldly; -using Spectre.Console.Testing; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +public partial class AnsiConsoleTests { - public partial class AnsiConsoleTests + public sealed class Cursor { - public sealed class Cursor + public sealed class TheMoveMethod { - public sealed class TheMoveMethod + [Theory] + [InlineData(CursorDirection.Up, "HelloWorld")] + [InlineData(CursorDirection.Down, "HelloWorld")] + [InlineData(CursorDirection.Right, "HelloWorld")] + [InlineData(CursorDirection.Left, "HelloWorld")] + public void Should_Return_Correct_Ansi_Code(CursorDirection direction, string expected) { - [Theory] - [InlineData(CursorDirection.Up, "HelloWorld")] - [InlineData(CursorDirection.Down, "HelloWorld")] - [InlineData(CursorDirection.Right, "HelloWorld")] - [InlineData(CursorDirection.Left, "HelloWorld")] - public void Should_Return_Correct_Ansi_Code(CursorDirection direction, string expected) - { - // Given - var console = new TestConsole().EmitAnsiSequences(); + // Given + var console = new TestConsole().EmitAnsiSequences(); - // When - console.Write("Hello"); - console.Cursor.Move(direction, 2); - console.Write("World"); + // When + console.Write("Hello"); + console.Cursor.Move(direction, 2); + console.Write("World"); - // Then - console.Output.ShouldBe(expected); - } + // Then + console.Output.ShouldBe(expected); } + } - public sealed class TheSetPositionMethod + public sealed class TheSetPositionMethod + { + [Fact] + public void Should_Return_Correct_Ansi_Code() { - [Fact] - public void Should_Return_Correct_Ansi_Code() - { - // Given - var console = new TestConsole().EmitAnsiSequences(); + // Given + var console = new TestConsole().EmitAnsiSequences(); - // When - console.Write("Hello"); - console.Cursor.SetPosition(5, 3); - console.Write("World"); + // When + console.Write("Hello"); + console.Cursor.SetPosition(5, 3); + console.Write("World"); - // Then - console.Output.ShouldBe("HelloWorld"); - } + // Then + console.Output.ShouldBe("HelloWorld"); } } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Markup.cs b/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Markup.cs index beb694d..10c57e3 100644 --- a/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Markup.cs +++ b/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Markup.cs @@ -1,120 +1,114 @@ -using System; -using Shouldly; -using Spectre.Console.Testing; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +public partial class AnsiConsoleTests { - public partial class AnsiConsoleTests + public sealed class Markup { - public sealed class Markup + [Theory] + [InlineData("[yellow]Hello[/]", "Hello")] + [InlineData("[yellow]Hello [italic]World[/]![/]", "Hello World!")] + public void Should_Output_Expected_Ansi_For_Markup(string markup, string expected) { - [Theory] - [InlineData("[yellow]Hello[/]", "Hello")] - [InlineData("[yellow]Hello [italic]World[/]![/]", "Hello World!")] - public void Should_Output_Expected_Ansi_For_Markup(string markup, string expected) - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.Standard) - .EmitAnsiSequences(); + // Given + var console = new TestConsole() + .Colors(ColorSystem.Standard) + .EmitAnsiSequences(); - // When - console.Markup(markup); + // When + console.Markup(markup); - // Then - console.Output.ShouldBe(expected); - } + // Then + console.Output.ShouldBe(expected); + } - [Fact] - public void Should_Output_Expected_Ansi_For_Link_With_Url_And_Text() - { - // Given - var console = new TestConsole() - .EmitAnsiSequences(); + [Fact] + public void Should_Output_Expected_Ansi_For_Link_With_Url_And_Text() + { + // Given + var console = new TestConsole() + .EmitAnsiSequences(); - // When - console.Markup("[link=https://patriksvensson.se]Click to visit my blog[/]"); + // When + console.Markup("[link=https://patriksvensson.se]Click to visit my blog[/]"); - // Then - console.Output.ShouldMatch("]8;id=[0-9]*;https:\\/\\/patriksvensson\\.se\\\\Click to visit my blog]8;;\\\\"); - } + // Then + console.Output.ShouldMatch("]8;id=[0-9]*;https:\\/\\/patriksvensson\\.se\\\\Click to visit my blog]8;;\\\\"); + } - [Fact] - public void Should_Output_Expected_Ansi_For_Link_With_Only_Url() - { - // Given - var console = new TestConsole() - .EmitAnsiSequences(); + [Fact] + public void Should_Output_Expected_Ansi_For_Link_With_Only_Url() + { + // Given + var console = new TestConsole() + .EmitAnsiSequences(); - // When - console.Markup("[link]https://patriksvensson.se[/]"); + // When + console.Markup("[link]https://patriksvensson.se[/]"); - // Then - console.Output.ShouldMatch("]8;id=[0-9]*;https:\\/\\/patriksvensson\\.se\\\\https:\\/\\/patriksvensson\\.se]8;;\\\\"); - } + // Then + console.Output.ShouldMatch("]8;id=[0-9]*;https:\\/\\/patriksvensson\\.se\\\\https:\\/\\/patriksvensson\\.se]8;;\\\\"); + } - [Theory] - [InlineData("[yellow]Hello [[ World[/]", "Hello [ World")] - public void Should_Be_Able_To_Escape_Tags(string markup, string expected) - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.Standard) - .EmitAnsiSequences(); + [Theory] + [InlineData("[yellow]Hello [[ World[/]", "Hello [ World")] + public void Should_Be_Able_To_Escape_Tags(string markup, string expected) + { + // Given + var console = new TestConsole() + .Colors(ColorSystem.Standard) + .EmitAnsiSequences(); - // When - console.Markup(markup); + // When + console.Markup(markup); - // Then - console.Output.ShouldBe(expected); - } + // Then + console.Output.ShouldBe(expected); + } - [Theory] - [InlineData("[yellow]Hello[", "Encountered malformed markup tag at position 14.")] - [InlineData("[yellow]Hello[/", "Encountered malformed markup tag at position 15.")] - [InlineData("[yellow]Hello[/foo", "Encountered malformed markup tag at position 15.")] - [InlineData("[yellow Hello", "Encountered malformed markup tag at position 13.")] - public void Should_Throw_If_Encounters_Malformed_Tag(string markup, string expected) - { - // Given - var console = new TestConsole(); + [Theory] + [InlineData("[yellow]Hello[", "Encountered malformed markup tag at position 14.")] + [InlineData("[yellow]Hello[/", "Encountered malformed markup tag at position 15.")] + [InlineData("[yellow]Hello[/foo", "Encountered malformed markup tag at position 15.")] + [InlineData("[yellow Hello", "Encountered malformed markup tag at position 13.")] + public void Should_Throw_If_Encounters_Malformed_Tag(string markup, string expected) + { + // Given + var console = new TestConsole(); - // When - var result = Record.Exception(() => console.Markup(markup)); + // When + var result = Record.Exception(() => console.Markup(markup)); - // Then - result.ShouldBeOfType() - .Message.ShouldBe(expected); - } + // Then + result.ShouldBeOfType() + .Message.ShouldBe(expected); + } - [Fact] - public void Should_Throw_If_Tags_Are_Unbalanced() - { - // Given - var console = new TestConsole(); + [Fact] + public void Should_Throw_If_Tags_Are_Unbalanced() + { + // Given + var console = new TestConsole(); - // When - var result = Record.Exception(() => console.Markup("[yellow][blue]Hello[/]")); + // When + var result = Record.Exception(() => console.Markup("[yellow][blue]Hello[/]")); - // Then - result.ShouldBeOfType() - .Message.ShouldBe("Unbalanced markup stack. Did you forget to close a tag?"); - } + // Then + result.ShouldBeOfType() + .Message.ShouldBe("Unbalanced markup stack. Did you forget to close a tag?"); + } - [Fact] - public void Should_Throw_If_Encounters_Closing_Tag() - { - // Given - var console = new TestConsole(); + [Fact] + public void Should_Throw_If_Encounters_Closing_Tag() + { + // Given + var console = new TestConsole(); - // When - var result = Record.Exception(() => console.Markup("Hello[/]World")); + // When + var result = Record.Exception(() => console.Markup("Hello[/]World")); - // Then - result.ShouldBeOfType() - .Message.ShouldBe("Encountered closing tag when none was expected near position 5."); - } + // Then + result.ShouldBeOfType() + .Message.ShouldBe("Encountered closing tag when none was expected near position 5."); } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Prompt.cs b/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Prompt.cs index 161e084..9ec084e 100644 --- a/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Prompt.cs +++ b/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Prompt.cs @@ -1,29 +1,23 @@ -using System; -using Shouldly; -using Spectre.Console.Testing; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +public partial class AnsiConsoleTests { - public partial class AnsiConsoleTests + public sealed class Prompt { - public sealed class Prompt + [Theory] + [InlineData(true, true)] + [InlineData(false, false)] + public void Should_Return_Default_Value_If_Nothing_Is_Entered(bool expected, bool defaultValue) { - [Theory] - [InlineData(true, true)] - [InlineData(false, false)] - public void Should_Return_Default_Value_If_Nothing_Is_Entered(bool expected, bool defaultValue) - { - // Given - var console = new TestConsole().EmitAnsiSequences(); - console.Input.PushKey(ConsoleKey.Enter); + // Given + var console = new TestConsole().EmitAnsiSequences(); + console.Input.PushKey(ConsoleKey.Enter); - // When - var result = console.Confirm("Want some prompt?", defaultValue); + // When + var result = console.Confirm("Want some prompt?", defaultValue); - // Then - result.ShouldBe(expected); - } + // Then + result.ShouldBe(expected); } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Style.cs b/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Style.cs index a7b61f2..93504a1 100644 --- a/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Style.cs +++ b/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.Style.cs @@ -1,48 +1,43 @@ -using Shouldly; -using Spectre.Console.Testing; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +public partial class AnsiConsoleTests { - public partial class AnsiConsoleTests + [Theory] + [InlineData(Decoration.Bold, "\u001b[1mHello World")] + [InlineData(Decoration.Dim, "\u001b[2mHello World")] + [InlineData(Decoration.Italic, "\u001b[3mHello World")] + [InlineData(Decoration.Underline, "\u001b[4mHello World")] + [InlineData(Decoration.Invert, "\u001b[7mHello World")] + [InlineData(Decoration.Conceal, "\u001b[8mHello World")] + [InlineData(Decoration.SlowBlink, "\u001b[5mHello World")] + [InlineData(Decoration.RapidBlink, "\u001b[6mHello World")] + [InlineData(Decoration.Strikethrough, "\u001b[9mHello World")] + public void Should_Write_Decorated_Text_Correctly(Decoration decoration, string expected) { - [Theory] - [InlineData(Decoration.Bold, "\u001b[1mHello World")] - [InlineData(Decoration.Dim, "\u001b[2mHello World")] - [InlineData(Decoration.Italic, "\u001b[3mHello World")] - [InlineData(Decoration.Underline, "\u001b[4mHello World")] - [InlineData(Decoration.Invert, "\u001b[7mHello World")] - [InlineData(Decoration.Conceal, "\u001b[8mHello World")] - [InlineData(Decoration.SlowBlink, "\u001b[5mHello World")] - [InlineData(Decoration.RapidBlink, "\u001b[6mHello World")] - [InlineData(Decoration.Strikethrough, "\u001b[9mHello World")] - public void Should_Write_Decorated_Text_Correctly(Decoration decoration, string expected) - { - // Given - var console = new TestConsole() - .EmitAnsiSequences(); + // Given + var console = new TestConsole() + .EmitAnsiSequences(); - // When - console.Write("Hello World", new Style().Decoration(decoration)); + // When + console.Write("Hello World", new Style().Decoration(decoration)); - // Then - console.Output.ShouldBe(expected); - } - - [Theory] - [InlineData(Decoration.Bold | Decoration.Underline, "\u001b[1;4mHello World")] - [InlineData(Decoration.Bold | Decoration.Underline | Decoration.Conceal, "\u001b[1;4;8mHello World")] - public void Should_Write_Text_With_Multiple_Decorations_Correctly(Decoration decoration, string expected) - { - // Given - var console = new TestConsole() - .EmitAnsiSequences(); - - // When - console.Write("Hello World", new Style().Decoration(decoration)); - - // Then - console.Output.ShouldBe(expected); - } + // Then + console.Output.ShouldBe(expected); } -} \ No newline at end of file + + [Theory] + [InlineData(Decoration.Bold | Decoration.Underline, "\u001b[1;4mHello World")] + [InlineData(Decoration.Bold | Decoration.Underline | Decoration.Conceal, "\u001b[1;4;8mHello World")] + public void Should_Write_Text_With_Multiple_Decorations_Correctly(Decoration decoration, string expected) + { + // Given + var console = new TestConsole() + .EmitAnsiSequences(); + + // When + console.Write("Hello World", new Style().Decoration(decoration)); + + // Then + console.Output.ShouldBe(expected); + } +} diff --git a/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.cs b/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.cs index c589608..4ef4163 100644 --- a/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.cs +++ b/test/Spectre.Console.Tests/Unit/AnsiConsoleTests.cs @@ -1,151 +1,145 @@ -using System; -using Shouldly; -using Spectre.Console.Testing; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +public partial class AnsiConsoleTests { - public partial class AnsiConsoleTests + public sealed class Clear { - public sealed class Clear + [Theory] + [InlineData(false, "HelloWorld")] + [InlineData(true, "HelloWorld")] + public void Should_Clear_Screen(bool home, string expected) { - [Theory] - [InlineData(false, "HelloWorld")] - [InlineData(true, "HelloWorld")] - public void Should_Clear_Screen(bool home, string expected) - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.Standard) - .EmitAnsiSequences(); + // Given + var console = new TestConsole() + .Colors(ColorSystem.Standard) + .EmitAnsiSequences(); - // When - console.Write("Hello"); - console.Clear(home); - console.Write("World"); + // When + console.Write("Hello"); + console.Clear(home); + console.Write("World"); - // Then - console.Output.ShouldBe(expected); - } - } - - public sealed class Write - { - [Fact] - public void Should_Combine_Decoration_And_Colors() - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.Standard) - .EmitAnsiSequences(); - - // When - console.Write( - "Hello", - new Style() - .Foreground(Color.RoyalBlue1) - .Background(Color.NavajoWhite1) - .Decoration(Decoration.Italic)); - - // Then - console.Output.ShouldBe("\u001b[3;90;47mHello\u001b[0m"); - } - - [Fact] - public void Should_Not_Include_Foreground_If_Set_To_Default_Color() - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.Standard) - .EmitAnsiSequences(); - - // When - console.Write( - "Hello", - new Style() - .Foreground(Color.Default) - .Background(Color.NavajoWhite1) - .Decoration(Decoration.Italic)); - - // Then - console.Output.ShouldBe("\u001b[3;47mHello\u001b[0m"); - } - - [Fact] - public void Should_Not_Include_Background_If_Set_To_Default_Color() - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.Standard) - .EmitAnsiSequences(); - - // When - console.Write( - "Hello", - new Style() - .Foreground(Color.RoyalBlue1) - .Background(Color.Default) - .Decoration(Decoration.Italic)); - - // Then - console.Output.ShouldBe("\u001b[3;90mHello\u001b[0m"); - } - - [Fact] - public void Should_Not_Include_Decoration_If_Set_To_None() - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.Standard) - .EmitAnsiSequences(); - - // When - console.Write( - "Hello", - new Style() - .Foreground(Color.RoyalBlue1) - .Background(Color.NavajoWhite1) - .Decoration(Decoration.None)); - - // Then - console.Output.ShouldBe("\u001b[90;47mHello\u001b[0m"); - } - } - - public sealed class WriteLine - { - [Fact] - public void Should_Reset_Colors_Correctly_After_Line_Break() - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.Standard) - .EmitAnsiSequences(); - - // When - console.WriteLine("Hello", new Style().Background(ConsoleColor.Red)); - console.WriteLine("World", new Style().Background(ConsoleColor.Green)); - - // Then - console.Output.NormalizeLineEndings() - .ShouldBe("Hello\nWorld\n"); - } - - [Fact] - public void Should_Reset_Colors_Correctly_After_Line_Break_In_Text() - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.Standard) - .EmitAnsiSequences(); - - // When - console.WriteLine("Hello\nWorld", new Style().Background(ConsoleColor.Red)); - - // Then - console.Output.NormalizeLineEndings() - .ShouldBe("Hello\nWorld\n"); - } + // Then + console.Output.ShouldBe(expected); } } -} \ No newline at end of file + + public sealed class Write + { + [Fact] + public void Should_Combine_Decoration_And_Colors() + { + // Given + var console = new TestConsole() + .Colors(ColorSystem.Standard) + .EmitAnsiSequences(); + + // When + console.Write( + "Hello", + new Style() + .Foreground(Color.RoyalBlue1) + .Background(Color.NavajoWhite1) + .Decoration(Decoration.Italic)); + + // Then + console.Output.ShouldBe("\u001b[3;90;47mHello\u001b[0m"); + } + + [Fact] + public void Should_Not_Include_Foreground_If_Set_To_Default_Color() + { + // Given + var console = new TestConsole() + .Colors(ColorSystem.Standard) + .EmitAnsiSequences(); + + // When + console.Write( + "Hello", + new Style() + .Foreground(Color.Default) + .Background(Color.NavajoWhite1) + .Decoration(Decoration.Italic)); + + // Then + console.Output.ShouldBe("\u001b[3;47mHello\u001b[0m"); + } + + [Fact] + public void Should_Not_Include_Background_If_Set_To_Default_Color() + { + // Given + var console = new TestConsole() + .Colors(ColorSystem.Standard) + .EmitAnsiSequences(); + + // When + console.Write( + "Hello", + new Style() + .Foreground(Color.RoyalBlue1) + .Background(Color.Default) + .Decoration(Decoration.Italic)); + + // Then + console.Output.ShouldBe("\u001b[3;90mHello\u001b[0m"); + } + + [Fact] + public void Should_Not_Include_Decoration_If_Set_To_None() + { + // Given + var console = new TestConsole() + .Colors(ColorSystem.Standard) + .EmitAnsiSequences(); + + // When + console.Write( + "Hello", + new Style() + .Foreground(Color.RoyalBlue1) + .Background(Color.NavajoWhite1) + .Decoration(Decoration.None)); + + // Then + console.Output.ShouldBe("\u001b[90;47mHello\u001b[0m"); + } + } + + public sealed class WriteLine + { + [Fact] + public void Should_Reset_Colors_Correctly_After_Line_Break() + { + // Given + var console = new TestConsole() + .Colors(ColorSystem.Standard) + .EmitAnsiSequences(); + + // When + console.WriteLine("Hello", new Style().Background(ConsoleColor.Red)); + console.WriteLine("World", new Style().Background(ConsoleColor.Green)); + + // Then + console.Output.NormalizeLineEndings() + .ShouldBe("Hello\nWorld\n"); + } + + [Fact] + public void Should_Reset_Colors_Correctly_After_Line_Break_In_Text() + { + // Given + var console = new TestConsole() + .Colors(ColorSystem.Standard) + .EmitAnsiSequences(); + + // When + console.WriteLine("Hello\nWorld", new Style().Background(ConsoleColor.Red)); + + // Then + console.Output.NormalizeLineEndings() + .ShouldBe("Hello\nWorld\n"); + } + } +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/Annotations/CommandArgumentAttributeTests.Rendering.cs b/test/Spectre.Console.Tests/Unit/Cli/Annotations/CommandArgumentAttributeTests.Rendering.cs index 1a9706a..8664fc2 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/Annotations/CommandArgumentAttributeTests.Rendering.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/Annotations/CommandArgumentAttributeTests.Rendering.cs @@ -1,97 +1,88 @@ -using System.Threading.Tasks; -using Spectre.Console.Cli; -using Spectre.Console.Testing; -using Spectre.Console.Tests.Data; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli.Annotations; -namespace Spectre.Console.Tests.Unit.Cli.Annotations +[ExpectationPath("Cli/Arguments")] +public sealed partial class CommandArgumentAttributeTests { - [ExpectationPath("Cli/Arguments")] - public sealed partial class CommandArgumentAttributeTests + [UsesVerify] + public sealed class ArgumentCannotContainOptions { - [UsesVerify] - public sealed class ArgumentCannotContainOptions + public sealed class Settings : CommandSettings { - public sealed class Settings : CommandSettings - { - [CommandArgument(0, "--foo ")] - public string Foo { get; set; } - } - - [Fact] - [Expectation("ArgumentCannotContainOptions")] - public Task Should_Return_Correct_Text() - { - // Given, When - var result = Fixture.Run(); - - // Then - return Verifier.Verify(result); - } + [CommandArgument(0, "--foo ")] + public string Foo { get; set; } } - [UsesVerify] - public sealed class MultipleValuesAreNotSupported + [Fact] + [Expectation("ArgumentCannotContainOptions")] + public Task Should_Return_Correct_Text() { - public sealed class Settings : CommandSettings - { - [CommandArgument(0, " ")] - public string Foo { get; set; } - } + // Given, When + var result = Fixture.Run(); - [Fact] - [Expectation("MultipleValuesAreNotSupported")] - public Task Should_Return_Correct_Text() - { - // Given, When - var result = Fixture.Run(); + // Then + return Verifier.Verify(result); + } + } - // Then - return Verifier.Verify(result); - } + [UsesVerify] + public sealed class MultipleValuesAreNotSupported + { + public sealed class Settings : CommandSettings + { + [CommandArgument(0, " ")] + public string Foo { get; set; } } - [UsesVerify] - public sealed class ValuesMustHaveName + [Fact] + [Expectation("MultipleValuesAreNotSupported")] + public Task Should_Return_Correct_Text() { - public sealed class Settings : CommandSettings - { - [CommandArgument(0, "<>")] - public string Foo { get; set; } - } + // Given, When + var result = Fixture.Run(); - [Fact] - [Expectation("ValuesMustHaveName")] - public Task Should_Return_Correct_Text() - { - // Given, When - var result = Fixture.Run(); + // Then + return Verifier.Verify(result); + } + } - // Then - return Verifier.Verify(result); - } + [UsesVerify] + public sealed class ValuesMustHaveName + { + public sealed class Settings : CommandSettings + { + [CommandArgument(0, "<>")] + public string Foo { get; set; } } - private static class Fixture + [Fact] + [Expectation("ValuesMustHaveName")] + public Task Should_Return_Correct_Text() { - public static string Run(params string[] args) - where TSettings : CommandSettings - { - using (var writer = new TestConsole()) - { - var app = new CommandApp(); - app.Configure(c => c.ConfigureConsole(writer)); - app.Configure(c => c.AddCommand>("foo")); - app.Run(args); + // Given, When + var result = Fixture.Run(); - return writer.Output - .NormalizeLineEndings() - .TrimLines() - .Trim(); - } + // Then + return Verifier.Verify(result); + } + } + + private static class Fixture + { + public static string Run(params string[] args) + where TSettings : CommandSettings + { + using (var writer = new TestConsole()) + { + var app = new CommandApp(); + app.Configure(c => c.ConfigureConsole(writer)); + app.Configure(c => c.AddCommand>("foo")); + app.Run(args); + + return writer.Output + .NormalizeLineEndings() + .TrimLines() + .Trim(); } } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/Annotations/CommandArgumentAttributeTests.cs b/test/Spectre.Console.Tests/Unit/Cli/Annotations/CommandArgumentAttributeTests.cs index 444ca03..6b39c1e 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/Annotations/CommandArgumentAttributeTests.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/Annotations/CommandArgumentAttributeTests.cs @@ -1,64 +1,59 @@ -using Shouldly; -using Spectre.Console.Cli; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli.Annotations; -namespace Spectre.Console.Tests.Unit.Cli.Annotations +public sealed partial class CommandArgumentAttributeTests { - public sealed partial class CommandArgumentAttributeTests + [Fact] + public void Should_Not_Contain_Options() { - [Fact] - public void Should_Not_Contain_Options() - { - // Given, When - var result = Record.Exception(() => new CommandArgumentAttribute(0, "--foo ")); + // Given, When + var result = Record.Exception(() => new CommandArgumentAttribute(0, "--foo ")); - // Then - result.ShouldNotBe(null); - result.ShouldBeOfType().And(exception => - exception.Message.ShouldBe("Arguments can not contain options.")); - } - - [Theory] - [InlineData(" ")] - [InlineData("[FOO] [BAR]")] - [InlineData("[FOO] ")] - [InlineData(" [BAR]")] - public void Should_Not_Contain_Multiple_Value_Names(string template) - { - // Given, When - var result = Record.Exception(() => new CommandArgumentAttribute(0, template)); - - // Then - result.ShouldNotBe(null); - result.ShouldBeOfType().And(exception => - exception.Message.ShouldBe("Multiple values are not supported.")); - } - - [Theory] - [InlineData("<>")] - [InlineData("[]")] - public void Should_Not_Contain_Empty_Value_Name(string template) - { - // Given, When - var result = Record.Exception(() => new CommandArgumentAttribute(0, template)); - - // Then - result.ShouldNotBe(null); - result.ShouldBeOfType().And(exception => - exception.Message.ShouldBe("Values without name are not allowed.")); - } - - [Theory] - [InlineData("", true)] - [InlineData("[FOO]", false)] - public void Should_Parse_Valid_Options(string template, bool required) - { - // Given, When - var result = new CommandArgumentAttribute(0, template); - - // Then - result.ValueName.ShouldBe("FOO"); - result.IsRequired.ShouldBe(required); - } + // Then + result.ShouldNotBe(null); + result.ShouldBeOfType().And(exception => + exception.Message.ShouldBe("Arguments can not contain options.")); } -} \ No newline at end of file + + [Theory] + [InlineData(" ")] + [InlineData("[FOO] [BAR]")] + [InlineData("[FOO] ")] + [InlineData(" [BAR]")] + public void Should_Not_Contain_Multiple_Value_Names(string template) + { + // Given, When + var result = Record.Exception(() => new CommandArgumentAttribute(0, template)); + + // Then + result.ShouldNotBe(null); + result.ShouldBeOfType().And(exception => + exception.Message.ShouldBe("Multiple values are not supported.")); + } + + [Theory] + [InlineData("<>")] + [InlineData("[]")] + public void Should_Not_Contain_Empty_Value_Name(string template) + { + // Given, When + var result = Record.Exception(() => new CommandArgumentAttribute(0, template)); + + // Then + result.ShouldNotBe(null); + result.ShouldBeOfType().And(exception => + exception.Message.ShouldBe("Values without name are not allowed.")); + } + + [Theory] + [InlineData("", true)] + [InlineData("[FOO]", false)] + public void Should_Parse_Valid_Options(string template, bool required) + { + // Given, When + var result = new CommandArgumentAttribute(0, template); + + // Then + result.ValueName.ShouldBe("FOO"); + result.IsRequired.ShouldBe(required); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/Annotations/CommandOptionAttributeTests.Rendering.cs b/test/Spectre.Console.Tests/Unit/Cli/Annotations/CommandOptionAttributeTests.Rendering.cs index 6fa663d..ae7a857 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/Annotations/CommandOptionAttributeTests.Rendering.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/Annotations/CommandOptionAttributeTests.Rendering.cs @@ -1,250 +1,240 @@ -using System.Threading.Tasks; -using Shouldly; -using Spectre.Console.Cli; -using Spectre.Console.Testing; -using Spectre.Console.Tests.Data; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli.Annotations; -namespace Spectre.Console.Tests.Unit.Cli.Annotations +[ExpectationPath("Cli/Arguments")] +public sealed partial class CommandOptionAttributeTests { - [ExpectationPath("Cli/Arguments")] - public sealed partial class CommandOptionAttributeTests + [UsesVerify] + public sealed class UnexpectedCharacter { - [UsesVerify] - public sealed class UnexpectedCharacter + public sealed class Settings : CommandSettings { - public sealed class Settings : CommandSettings - { - [CommandOption(" $ ")] - public string Foo { get; set; } - } - - [Fact] - [Expectation("UnexpectedCharacter")] - public Task Should_Return_Correct_Text() - { - // Given, When - var result = Fixture.Run(); - - // Then - result.Exception.Message.ShouldBe("Encountered unexpected character '$'."); - return Verifier.Verify(result.Output); - } + [CommandOption(" $ ")] + public string Foo { get; set; } } - [UsesVerify] - public sealed class UnterminatedValueName + [Fact] + [Expectation("UnexpectedCharacter")] + public Task Should_Return_Correct_Text() { - public sealed class Settings : CommandSettings - { - [CommandOption("--foo|-f (); - [Fact] - [Expectation("UnterminatedValueName")] - public Task Should_Return_Correct_Text() - { - // Given, When - var result = Fixture.Run(); - - // Then - result.Exception.Message.ShouldBe("Encountered unterminated value name 'BAR'."); - return Verifier.Verify(result.Output); - } - } - - [UsesVerify] - public sealed class OptionsMustHaveName - { - public sealed class Settings : CommandSettings - { - [CommandOption("--foo|-")] - public string Foo { get; set; } - } - - [Fact] - [Expectation("OptionsMustHaveName")] - public Task Should_Return_Correct_Text() - { - // Given, When - var result = Fixture.Run(); - - // Then - result.Exception.Message.ShouldBe("Options without name are not allowed."); - return Verifier.Verify(result.Output); - } - } - - [UsesVerify] - public sealed class OptionNamesCannotStartWithDigit - { - public sealed class Settings : CommandSettings - { - [CommandOption("--1foo")] - public string Foo { get; set; } - } - - [Fact] - [Expectation("OptionNamesCannotStartWithDigit")] - public Task Should_Return_Correct_Text() - { - // Given, When - var result = Fixture.Run(); - - // Then - result.Exception.Message.ShouldBe("Option names cannot start with a digit."); - return Verifier.Verify(result.Output); - } - } - - [UsesVerify] - public sealed class InvalidCharacterInOptionName - { - public sealed class Settings : CommandSettings - { - [CommandOption("--f$oo")] - public string Foo { get; set; } - } - - [Fact] - [Expectation("InvalidCharacterInOptionName")] - public Task Should_Return_Correct_Text() - { - // Given, When - var result = Fixture.Run(); - - // Then - result.Exception.Message.ShouldBe("Encountered invalid character '$' in option name."); - return Verifier.Verify(result.Output); - } - } - - [UsesVerify] - public sealed class LongOptionMustHaveMoreThanOneCharacter - { - public sealed class Settings : CommandSettings - { - [CommandOption("--f")] - public string Foo { get; set; } - } - - [Fact] - [Expectation("LongOptionMustHaveMoreThanOneCharacter")] - public Task Should_Return_Correct_Text() - { - // Given, When - var result = Fixture.Run(); - - // Then - result.Exception.Message.ShouldBe("Long option names must consist of more than one character."); - return Verifier.Verify(result.Output); - } - } - - [UsesVerify] - public sealed class ShortOptionMustOnlyBeOneCharacter - { - public sealed class Settings : CommandSettings - { - [CommandOption("--foo|-bar")] - public string Foo { get; set; } - } - - [Fact] - [Expectation("ShortOptionMustOnlyBeOneCharacter")] - public Task Should_Return_Correct_Text() - { - // Given, When - var result = Fixture.Run(); - - // Then - result.Exception.Message.ShouldBe("Short option names can not be longer than one character."); - return Verifier.Verify(result.Output); - } - } - - [UsesVerify] - public sealed class MultipleOptionValuesAreNotSupported - { - public sealed class Settings : CommandSettings - { - [CommandOption("-f|--foo ")] - public string Foo { get; set; } - } - - [Fact] - [Expectation("MultipleOptionValuesAreNotSupported")] - public Task Should_Return_Correct_Text() - { - // Given, When - var result = Fixture.Run(); - - // Then - result.Exception.Message.ShouldBe("Multiple option values are not supported."); - return Verifier.Verify(result.Output); - } - } - - [UsesVerify] - public sealed class InvalidCharacterInValueName - { - public sealed class Settings : CommandSettings - { - [CommandOption("-f|--foo ")] - public string Foo { get; set; } - } - - [Fact] - [Expectation("InvalidCharacterInValueName")] - public Task Should_Return_Correct_Text() - { - // Given, When - var result = Fixture.Run(); - - // Then - result.Exception.Message.ShouldBe("Encountered invalid character '$' in value name."); - return Verifier.Verify(result.Output); - } - } - - [UsesVerify] - public sealed class MissingLongAndShortName - { - public sealed class Settings : CommandSettings - { - [CommandOption("")] - public string Foo { get; set; } - } - - [Fact] - [Expectation("MissingLongAndShortName")] - public Task Should_Return_Correct_Text() - { - // Given, When - var result = Fixture.Run(); - - // Then - result.Exception.Message.ShouldBe("No long or short name for option has been specified."); - return Verifier.Verify(result.Output); - } - } - - private static class Fixture - { - public static CommandAppFailure Run(params string[] args) - where TSettings : CommandSettings - { - var app = new CommandAppTester(); - app.Configure(c => - { - c.AddCommand>("foo"); - }); - - return app.RunAndCatch(args); - } + // Then + result.Exception.Message.ShouldBe("Encountered unexpected character '$'."); + return Verifier.Verify(result.Output); } } -} \ No newline at end of file + + [UsesVerify] + public sealed class UnterminatedValueName + { + public sealed class Settings : CommandSettings + { + [CommandOption("--foo|-f (); + + // Then + result.Exception.Message.ShouldBe("Encountered unterminated value name 'BAR'."); + return Verifier.Verify(result.Output); + } + } + + [UsesVerify] + public sealed class OptionsMustHaveName + { + public sealed class Settings : CommandSettings + { + [CommandOption("--foo|-")] + public string Foo { get; set; } + } + + [Fact] + [Expectation("OptionsMustHaveName")] + public Task Should_Return_Correct_Text() + { + // Given, When + var result = Fixture.Run(); + + // Then + result.Exception.Message.ShouldBe("Options without name are not allowed."); + return Verifier.Verify(result.Output); + } + } + + [UsesVerify] + public sealed class OptionNamesCannotStartWithDigit + { + public sealed class Settings : CommandSettings + { + [CommandOption("--1foo")] + public string Foo { get; set; } + } + + [Fact] + [Expectation("OptionNamesCannotStartWithDigit")] + public Task Should_Return_Correct_Text() + { + // Given, When + var result = Fixture.Run(); + + // Then + result.Exception.Message.ShouldBe("Option names cannot start with a digit."); + return Verifier.Verify(result.Output); + } + } + + [UsesVerify] + public sealed class InvalidCharacterInOptionName + { + public sealed class Settings : CommandSettings + { + [CommandOption("--f$oo")] + public string Foo { get; set; } + } + + [Fact] + [Expectation("InvalidCharacterInOptionName")] + public Task Should_Return_Correct_Text() + { + // Given, When + var result = Fixture.Run(); + + // Then + result.Exception.Message.ShouldBe("Encountered invalid character '$' in option name."); + return Verifier.Verify(result.Output); + } + } + + [UsesVerify] + public sealed class LongOptionMustHaveMoreThanOneCharacter + { + public sealed class Settings : CommandSettings + { + [CommandOption("--f")] + public string Foo { get; set; } + } + + [Fact] + [Expectation("LongOptionMustHaveMoreThanOneCharacter")] + public Task Should_Return_Correct_Text() + { + // Given, When + var result = Fixture.Run(); + + // Then + result.Exception.Message.ShouldBe("Long option names must consist of more than one character."); + return Verifier.Verify(result.Output); + } + } + + [UsesVerify] + public sealed class ShortOptionMustOnlyBeOneCharacter + { + public sealed class Settings : CommandSettings + { + [CommandOption("--foo|-bar")] + public string Foo { get; set; } + } + + [Fact] + [Expectation("ShortOptionMustOnlyBeOneCharacter")] + public Task Should_Return_Correct_Text() + { + // Given, When + var result = Fixture.Run(); + + // Then + result.Exception.Message.ShouldBe("Short option names can not be longer than one character."); + return Verifier.Verify(result.Output); + } + } + + [UsesVerify] + public sealed class MultipleOptionValuesAreNotSupported + { + public sealed class Settings : CommandSettings + { + [CommandOption("-f|--foo ")] + public string Foo { get; set; } + } + + [Fact] + [Expectation("MultipleOptionValuesAreNotSupported")] + public Task Should_Return_Correct_Text() + { + // Given, When + var result = Fixture.Run(); + + // Then + result.Exception.Message.ShouldBe("Multiple option values are not supported."); + return Verifier.Verify(result.Output); + } + } + + [UsesVerify] + public sealed class InvalidCharacterInValueName + { + public sealed class Settings : CommandSettings + { + [CommandOption("-f|--foo ")] + public string Foo { get; set; } + } + + [Fact] + [Expectation("InvalidCharacterInValueName")] + public Task Should_Return_Correct_Text() + { + // Given, When + var result = Fixture.Run(); + + // Then + result.Exception.Message.ShouldBe("Encountered invalid character '$' in value name."); + return Verifier.Verify(result.Output); + } + } + + [UsesVerify] + public sealed class MissingLongAndShortName + { + public sealed class Settings : CommandSettings + { + [CommandOption("")] + public string Foo { get; set; } + } + + [Fact] + [Expectation("MissingLongAndShortName")] + public Task Should_Return_Correct_Text() + { + // Given, When + var result = Fixture.Run(); + + // Then + result.Exception.Message.ShouldBe("No long or short name for option has been specified."); + return Verifier.Verify(result.Output); + } + } + + private static class Fixture + { + public static CommandAppFailure Run(params string[] args) + where TSettings : CommandSettings + { + var app = new CommandAppTester(); + app.Configure(c => + { + c.AddCommand>("foo"); + }); + + return app.RunAndCatch(args); + } + } +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/Annotations/CommandOptionAttributeTests.cs b/test/Spectre.Console.Tests/Unit/Cli/Annotations/CommandOptionAttributeTests.cs index 8d5867e..c3108e6 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/Annotations/CommandOptionAttributeTests.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/Annotations/CommandOptionAttributeTests.cs @@ -1,217 +1,212 @@ -using Shouldly; -using Spectre.Console.Cli; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli.Annotations; -namespace Spectre.Console.Tests.Unit.Cli.Annotations +public sealed partial class CommandOptionAttributeTests { - public sealed partial class CommandOptionAttributeTests + [Fact] + public void Should_Parse_Short_Name_Correctly() { - [Fact] - public void Should_Parse_Short_Name_Correctly() - { - // Given, When - var option = new CommandOptionAttribute("-o|--option "); + // Given, When + var option = new CommandOptionAttribute("-o|--option "); - // Then - option.ShortNames.ShouldContain("o"); - } - - [Fact] - public void Should_Parse_Long_Name_Correctly() - { - // Given, When - var option = new CommandOptionAttribute("-o|--option "); - - // Then - option.LongNames.ShouldContain("option"); - } - - [Theory] - [InlineData("")] - public void Should_Parse_Value_Correctly(string value) - { - // Given, When - var option = new CommandOptionAttribute($"-o|--option {value}"); - - // Then - option.ValueName.ShouldBe("VALUE"); - } - - [Fact] - public void Should_Parse_Only_Short_Name() - { - // Given, When - var option = new CommandOptionAttribute("-o"); - - // Then - option.ShortNames.ShouldContain("o"); - } - - [Fact] - public void Should_Parse_Only_Long_Name() - { - // Given, When - var option = new CommandOptionAttribute("--option"); - - // Then - option.LongNames.ShouldContain("option"); - } - - [Theory] - [InlineData("")] - [InlineData("")] - public void Should_Throw_If_Template_Is_Empty(string value) - { - // Given, When - var option = Record.Exception(() => new CommandOptionAttribute(value)); - - // Then - option.ShouldBeOfType().And(e => - e.Message.ShouldBe("No long or short name for option has been specified.")); - } - - [Theory] - [InlineData("--bar|-foo")] - [InlineData("--bar|-f-b")] - public void Should_Throw_If_Short_Name_Is_Invalid(string value) - { - // Given, When - var option = Record.Exception(() => new CommandOptionAttribute(value)); - - // Then - option.ShouldBeOfType().And(e => - e.Message.ShouldBe("Short option names can not be longer than one character.")); - } - - [Theory] - [InlineData("--o")] - public void Should_Throw_If_Long_Name_Is_Invalid(string value) - { - // Given, When - var option = Record.Exception(() => new CommandOptionAttribute(value)); - - // Then - option.ShouldBeOfType().And(e => - e.Message.ShouldBe("Long option names must consist of more than one character.")); - } - - [Theory] - [InlineData("-")] - [InlineData("--")] - public void Should_Throw_If_Option_Have_No_Name(string template) - { - // Given, When - var option = Record.Exception(() => new CommandOptionAttribute(template)); - - // Then - option.ShouldBeOfType().And(e => - e.Message.ShouldBe("Options without name are not allowed.")); - } - - [Theory] - [InlineData("--foo|-foo[b", '[')] - [InlineData("--foo|-f€b", '€')] - [InlineData("--foo|-foo@b", '@')] - public void Should_Throw_If_Option_Contains_Invalid_Name(string template, char invalid) - { - // Given, When - var result = Record.Exception(() => new CommandOptionAttribute(template)); - - // Then - result.ShouldBeOfType().And(e => - { - e.Message.ShouldBe($"Encountered invalid character '{invalid}' in option name."); - e.Template.ShouldBe(template); - }); - } - - [Theory] - [InlineData("--foo ", "HELLO-WORLD")] - [InlineData("--foo ", "HELLO_WORLD")] - public void Should_Accept_Dash_And_Underscore_In_Value_Name(string template, string name) - { - // Given, When - var result = new CommandOptionAttribute(template); - - // Then - result.ValueName.ShouldBe(name); - } - - [Theory] - [InlineData("--foo|-1")] - public void Should_Throw_If_First_Letter_Of_An_Option_Name_Is_A_Digit(string template) - { - // Given, When - var result = Record.Exception(() => new CommandOptionAttribute(template)); - - // Then - result.ShouldBeOfType().And(e => - { - e.Message.ShouldBe("Option names cannot start with a digit."); - e.Template.ShouldBe(template); - }); - } - - [Fact] - public void Multiple_Short_Options_Are_Supported() - { - // Given, When - var result = new CommandOptionAttribute("-f|-b"); - - // Then - result.ShortNames.Count.ShouldBe(2); - result.ShortNames.ShouldContain("f"); - result.ShortNames.ShouldContain("b"); - } - - [Fact] - public void Multiple_Long_Options_Are_Supported() - { - // Given, When - var result = new CommandOptionAttribute("--foo|--bar"); - - // Then - result.LongNames.Count.ShouldBe(2); - result.LongNames.ShouldContain("foo"); - result.LongNames.ShouldContain("bar"); - } - - [Theory] - [InlineData("-f|--foo ")] - [InlineData("--foo|-f ")] - [InlineData(" --foo|-f")] - [InlineData(" -f|--foo")] - [InlineData("-f --foo")] - [InlineData("--foo -f")] - public void Template_Parts_Can_Appear_In_Any_Order(string template) - { - // Given, When - var result = new CommandOptionAttribute(template); - - // Then - result.LongNames.ShouldContain("foo"); - result.ShortNames.ShouldContain("f"); - result.ValueName.ShouldBe("BAR"); - } - - [Fact] - public void Is_Not_Hidden_From_Help_By_Default() - { - // Given, When - var result = new CommandOptionAttribute("--foo"); - - // Then - result.IsHidden.ShouldBeFalse(); - } - - [Fact] - public void Can_Indicate_That_It_Must_Be_Hidden_From_Help_Text() - { - // Given, When - var result = new CommandOptionAttribute("--foo") { IsHidden = true }; - - // Then - result.IsHidden.ShouldBeTrue(); - } + // Then + option.ShortNames.ShouldContain("o"); } -} \ No newline at end of file + + [Fact] + public void Should_Parse_Long_Name_Correctly() + { + // Given, When + var option = new CommandOptionAttribute("-o|--option "); + + // Then + option.LongNames.ShouldContain("option"); + } + + [Theory] + [InlineData("")] + public void Should_Parse_Value_Correctly(string value) + { + // Given, When + var option = new CommandOptionAttribute($"-o|--option {value}"); + + // Then + option.ValueName.ShouldBe("VALUE"); + } + + [Fact] + public void Should_Parse_Only_Short_Name() + { + // Given, When + var option = new CommandOptionAttribute("-o"); + + // Then + option.ShortNames.ShouldContain("o"); + } + + [Fact] + public void Should_Parse_Only_Long_Name() + { + // Given, When + var option = new CommandOptionAttribute("--option"); + + // Then + option.LongNames.ShouldContain("option"); + } + + [Theory] + [InlineData("")] + [InlineData("")] + public void Should_Throw_If_Template_Is_Empty(string value) + { + // Given, When + var option = Record.Exception(() => new CommandOptionAttribute(value)); + + // Then + option.ShouldBeOfType().And(e => + e.Message.ShouldBe("No long or short name for option has been specified.")); + } + + [Theory] + [InlineData("--bar|-foo")] + [InlineData("--bar|-f-b")] + public void Should_Throw_If_Short_Name_Is_Invalid(string value) + { + // Given, When + var option = Record.Exception(() => new CommandOptionAttribute(value)); + + // Then + option.ShouldBeOfType().And(e => + e.Message.ShouldBe("Short option names can not be longer than one character.")); + } + + [Theory] + [InlineData("--o")] + public void Should_Throw_If_Long_Name_Is_Invalid(string value) + { + // Given, When + var option = Record.Exception(() => new CommandOptionAttribute(value)); + + // Then + option.ShouldBeOfType().And(e => + e.Message.ShouldBe("Long option names must consist of more than one character.")); + } + + [Theory] + [InlineData("-")] + [InlineData("--")] + public void Should_Throw_If_Option_Have_No_Name(string template) + { + // Given, When + var option = Record.Exception(() => new CommandOptionAttribute(template)); + + // Then + option.ShouldBeOfType().And(e => + e.Message.ShouldBe("Options without name are not allowed.")); + } + + [Theory] + [InlineData("--foo|-foo[b", '[')] + [InlineData("--foo|-f€b", '€')] + [InlineData("--foo|-foo@b", '@')] + public void Should_Throw_If_Option_Contains_Invalid_Name(string template, char invalid) + { + // Given, When + var result = Record.Exception(() => new CommandOptionAttribute(template)); + + // Then + result.ShouldBeOfType().And(e => + { + e.Message.ShouldBe($"Encountered invalid character '{invalid}' in option name."); + e.Template.ShouldBe(template); + }); + } + + [Theory] + [InlineData("--foo ", "HELLO-WORLD")] + [InlineData("--foo ", "HELLO_WORLD")] + public void Should_Accept_Dash_And_Underscore_In_Value_Name(string template, string name) + { + // Given, When + var result = new CommandOptionAttribute(template); + + // Then + result.ValueName.ShouldBe(name); + } + + [Theory] + [InlineData("--foo|-1")] + public void Should_Throw_If_First_Letter_Of_An_Option_Name_Is_A_Digit(string template) + { + // Given, When + var result = Record.Exception(() => new CommandOptionAttribute(template)); + + // Then + result.ShouldBeOfType().And(e => + { + e.Message.ShouldBe("Option names cannot start with a digit."); + e.Template.ShouldBe(template); + }); + } + + [Fact] + public void Multiple_Short_Options_Are_Supported() + { + // Given, When + var result = new CommandOptionAttribute("-f|-b"); + + // Then + result.ShortNames.Count.ShouldBe(2); + result.ShortNames.ShouldContain("f"); + result.ShortNames.ShouldContain("b"); + } + + [Fact] + public void Multiple_Long_Options_Are_Supported() + { + // Given, When + var result = new CommandOptionAttribute("--foo|--bar"); + + // Then + result.LongNames.Count.ShouldBe(2); + result.LongNames.ShouldContain("foo"); + result.LongNames.ShouldContain("bar"); + } + + [Theory] + [InlineData("-f|--foo ")] + [InlineData("--foo|-f ")] + [InlineData(" --foo|-f")] + [InlineData(" -f|--foo")] + [InlineData("-f --foo")] + [InlineData("--foo -f")] + public void Template_Parts_Can_Appear_In_Any_Order(string template) + { + // Given, When + var result = new CommandOptionAttribute(template); + + // Then + result.LongNames.ShouldContain("foo"); + result.ShortNames.ShouldContain("f"); + result.ValueName.ShouldBe("BAR"); + } + + [Fact] + public void Is_Not_Hidden_From_Help_By_Default() + { + // Given, When + var result = new CommandOptionAttribute("--foo"); + + // Then + result.IsHidden.ShouldBeFalse(); + } + + [Fact] + public void Can_Indicate_That_It_Must_Be_Hidden_From_Help_Text() + { + // Given, When + var result = new CommandOptionAttribute("--foo") { IsHidden = true }; + + // Then + result.IsHidden.ShouldBeTrue(); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Constructor.cs b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Constructor.cs index fa261cd..96d329a 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Constructor.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Constructor.cs @@ -1,110 +1,104 @@ -using Shouldly; -using Spectre.Console.Cli; -using Spectre.Console.Testing; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli; -namespace Spectre.Console.Tests.Unit.Cli +public sealed partial class CommandAppTests { - public sealed partial class CommandAppTests + public class NullableSettings : CommandSettings { - public class NullableSettings : CommandSettings + public NullableSettings(bool? detailed, string[] extra) { - public NullableSettings(bool? detailed, string[] extra) - { - Detailed = detailed; - Extra = extra; - } - - [CommandOption("-d")] - public bool? Detailed { get; } - - [CommandArgument(0, "[extra]")] - public string[] Extra { get; } + Detailed = detailed; + Extra = extra; } - public class NullableWithInitSettings : CommandSettings - { - [CommandOption("-d")] - public bool? Detailed { get; init; } + [CommandOption("-d")] + public bool? Detailed { get; } - [CommandArgument(0, "[extra]")] - public string[] Extra { get; init; } - } - - public class NullableCommand : Command - { - public override int Execute(CommandContext context, NullableSettings settings) => 0; - } - - public class NullableWithInitCommand : Command - { - public override int Execute(CommandContext context, NullableWithInitSettings settings) => 0; - } - - [Fact] - public void Should_Populate_Nullable_Objects_In_Settings() - { - // Given - var fixture = new CommandAppTester(); - fixture.Configure(configurator => - { - configurator.SetApplicationName("myapp"); - configurator.AddCommand("null"); - }); - - // When - var result = fixture.Run("null"); - - // Then - result.Settings.ShouldBeOfType().And(settings => - { - settings.Detailed.ShouldBeNull(); - settings.Extra.ShouldBeNull(); - }); - } - - [Fact] - public void Should_Populate_Nullable_Objects_With_Init_In_Settings() - { - // Given - var fixture = new CommandAppTester(); - fixture.Configure(configurator => - { - configurator.SetApplicationName("myapp"); - configurator.AddCommand("null"); - }); - - // When - var result = fixture.Run("null"); - - // Then - result.Settings.ShouldBeOfType().And(settings => - { - settings.Detailed.ShouldBeNull(); - settings.Extra.ShouldBeNull(); - }); - } - - [Fact] - public void Should_Populate_Regular_Settings() - { - // Given - var fixture = new CommandAppTester(); - fixture.Configure(configurator => - { - configurator.SetApplicationName("myapp"); - configurator.AddCommand("null"); - }); - - // When - var result = fixture.Run("null", "-d", "true", "first-item"); - - // Then - result.Settings.ShouldBeOfType().And(settings => - { - settings.Detailed.ShouldBe(true); - settings.Extra.ShouldBe(new[] { "first-item" }); - }); - } + [CommandArgument(0, "[extra]")] + public string[] Extra { get; } } -} \ No newline at end of file + + public class NullableWithInitSettings : CommandSettings + { + [CommandOption("-d")] + public bool? Detailed { get; init; } + + [CommandArgument(0, "[extra]")] + public string[] Extra { get; init; } + } + + public class NullableCommand : Command + { + public override int Execute(CommandContext context, NullableSettings settings) => 0; + } + + public class NullableWithInitCommand : Command + { + public override int Execute(CommandContext context, NullableWithInitSettings settings) => 0; + } + + [Fact] + public void Should_Populate_Nullable_Objects_In_Settings() + { + // Given + var fixture = new CommandAppTester(); + fixture.Configure(configurator => + { + configurator.SetApplicationName("myapp"); + configurator.AddCommand("null"); + }); + + // When + var result = fixture.Run("null"); + + // Then + result.Settings.ShouldBeOfType().And(settings => + { + settings.Detailed.ShouldBeNull(); + settings.Extra.ShouldBeNull(); + }); + } + + [Fact] + public void Should_Populate_Nullable_Objects_With_Init_In_Settings() + { + // Given + var fixture = new CommandAppTester(); + fixture.Configure(configurator => + { + configurator.SetApplicationName("myapp"); + configurator.AddCommand("null"); + }); + + // When + var result = fixture.Run("null"); + + // Then + result.Settings.ShouldBeOfType().And(settings => + { + settings.Detailed.ShouldBeNull(); + settings.Extra.ShouldBeNull(); + }); + } + + [Fact] + public void Should_Populate_Regular_Settings() + { + // Given + var fixture = new CommandAppTester(); + fixture.Configure(configurator => + { + configurator.SetApplicationName("myapp"); + configurator.AddCommand("null"); + }); + + // When + var result = fixture.Run("null", "-d", "true", "first-item"); + + // Then + result.Settings.ShouldBeOfType().And(settings => + { + settings.Detailed.ShouldBe(true); + settings.Extra.ShouldBe(new[] { "first-item" }); + }); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Exceptions.cs b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Exceptions.cs index 2563b5e..61c326a 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Exceptions.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Exceptions.cs @@ -1,100 +1,92 @@ -using System; -using Shouldly; -using Spectre.Console.Cli; -using Spectre.Console.Testing; -using Spectre.Console.Tests.Data; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli; -namespace Spectre.Console.Tests.Unit.Cli +public sealed partial class CommandAppTests { - public sealed partial class CommandAppTests + public sealed class Exception_Handling { - public sealed class Exception_Handling + [Fact] + public void Should_Not_Propagate_Runtime_Exceptions_If_Not_Explicitly_Told_To_Do_So() { - [Fact] - public void Should_Not_Propagate_Runtime_Exceptions_If_Not_Explicitly_Told_To_Do_So() + // Given + var app = new CommandAppTester(); + app.Configure(config => { - // Given - var app = new CommandAppTester(); - app.Configure(config => + config.AddBranch("animal", animal => { - config.AddBranch("animal", animal => - { - animal.AddCommand("dog"); - animal.AddCommand("horse"); - }); + animal.AddCommand("dog"); + animal.AddCommand("horse"); }); + }); - // When - var result = app.Run(new[] { "animal", "4", "dog", "101", "--name", "Rufus" }); + // When + var result = app.Run(new[] { "animal", "4", "dog", "101", "--name", "Rufus" }); - // Then - result.ExitCode.ShouldBe(-1); - } + // Then + result.ExitCode.ShouldBe(-1); + } - [Fact] - public void Should_Not_Propagate_Exceptions_If_Not_Explicitly_Told_To_Do_So() + [Fact] + public void Should_Not_Propagate_Exceptions_If_Not_Explicitly_Told_To_Do_So() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.AddCommand("throw"); - }); + config.AddCommand("throw"); + }); - // When - var result = app.Run(new[] { "throw" }); + // When + var result = app.Run(new[] { "throw" }); - // Then - result.ExitCode.ShouldBe(-1); - } + // Then + result.ExitCode.ShouldBe(-1); + } - [Fact] - public void Should_Handle_Exceptions_If_ExceptionHandler_Is_Set_Using_Action() + [Fact] + public void Should_Handle_Exceptions_If_ExceptionHandler_Is_Set_Using_Action() + { + // Given + var exceptionHandled = false; + var app = new CommandAppTester(); + app.Configure(config => { - // Given - var exceptionHandled = false; - var app = new CommandAppTester(); - app.Configure(config => + config.AddCommand("throw"); + config.SetExceptionHandler(_ => { - config.AddCommand("throw"); - config.SetExceptionHandler(_ => - { - exceptionHandled = true; - }); + exceptionHandled = true; }); + }); - // When - var result = app.Run(new[] { "throw" }); + // When + var result = app.Run(new[] { "throw" }); - // Then - result.ExitCode.ShouldBe(-1); - exceptionHandled.ShouldBeTrue(); - } + // Then + result.ExitCode.ShouldBe(-1); + exceptionHandled.ShouldBeTrue(); + } - [Fact] - public void Should_Handle_Exceptions_If_ExceptionHandler_Is_Set_Using_Function() + [Fact] + public void Should_Handle_Exceptions_If_ExceptionHandler_Is_Set_Using_Function() + { + // Given + var exceptionHandled = false; + var app = new CommandAppTester(); + app.Configure(config => { - // Given - var exceptionHandled = false; - var app = new CommandAppTester(); - app.Configure(config => + config.AddCommand("throw"); + config.SetExceptionHandler(_ => { - config.AddCommand("throw"); - config.SetExceptionHandler(_ => - { - exceptionHandled = true; - return -99; - }); + exceptionHandled = true; + return -99; }); + }); - // When - var result = app.Run(new[] { "throw" }); + // When + var result = app.Run(new[] { "throw" }); - // Then - result.ExitCode.ShouldBe(-99); - exceptionHandled.ShouldBeTrue(); - } + // Then + result.ExitCode.ShouldBe(-99); + exceptionHandled.ShouldBeTrue(); } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.FlagValues.cs b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.FlagValues.cs index b713c5f..65745be 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.FlagValues.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.FlagValues.cs @@ -1,223 +1,214 @@ -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; -using Shouldly; -using Spectre.Console.Cli; -using Spectre.Console.Testing; -using Spectre.Console.Tests.Data; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli; -namespace Spectre.Console.Tests.Unit.Cli +public sealed partial class CommandAppTests { - public sealed partial class CommandAppTests + public sealed class FlagValues { - public sealed class FlagValues + [SuppressMessage("Performance", "CA1812", Justification = "It's OK")] + private sealed class FlagSettings : CommandSettings { - [SuppressMessage("Performance", "CA1812", Justification = "It's OK")] - private sealed class FlagSettings : CommandSettings + [CommandOption("--serve [PORT]")] + public FlagValue Serve { get; set; } + } + + [SuppressMessage("Performance", "CA1812", Justification = "It's OK")] + private sealed class FlagSettingsWithNullableValueType : CommandSettings + { + [CommandOption("--serve [PORT]")] + public FlagValue Serve { get; set; } + } + + [SuppressMessage("Performance", "CA1812", Justification = "It's OK")] + private sealed class FlagSettingsWithOptionalOptionButNoFlagValue : CommandSettings + { + [CommandOption("--serve [PORT]")] + public int Serve { get; set; } + } + + [SuppressMessage("Performance", "CA1812", Justification = "It's OK")] + private sealed class FlagSettingsWithDefaultValue : CommandSettings + { + [CommandOption("--serve [PORT]")] + [DefaultValue(987)] + public FlagValue Serve { get; set; } + } + + [Fact] + public void Should_Throw_If_Command_Option_Value_Is_Optional_But_Type_Is_Not_A_Flag_Value() + { + // Given + var app = new CommandApp(); + app.Configure(config => { - [CommandOption("--serve [PORT]")] - public FlagValue Serve { get; set; } - } + config.PropagateExceptions(); + config.AddCommand>("foo"); + }); - [SuppressMessage("Performance", "CA1812", Justification = "It's OK")] - private sealed class FlagSettingsWithNullableValueType : CommandSettings + // When + var result = Record.Exception(() => app.Run(new[] { "foo", "--serve", "123" })); + + // Then + result.ShouldBeOfType().And(ex => { - [CommandOption("--serve [PORT]")] - public FlagValue Serve { get; set; } - } + ex.Message.ShouldBe("The option 'serve' has an optional value but does not implement IFlagValue."); + }); + } - [SuppressMessage("Performance", "CA1812", Justification = "It's OK")] - private sealed class FlagSettingsWithOptionalOptionButNoFlagValue : CommandSettings + [Fact] + public void Should_Set_Flag_And_Value_If_Both_Were_Provided() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => { - [CommandOption("--serve [PORT]")] - public int Serve { get; set; } - } + config.PropagateExceptions(); + config.AddCommand>("foo"); + }); - [SuppressMessage("Performance", "CA1812", Justification = "It's OK")] - private sealed class FlagSettingsWithDefaultValue : CommandSettings + // When + var result = app.Run(new[] { "foo", "--serve", "123", }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(flag => { - [CommandOption("--serve [PORT]")] - [DefaultValue(987)] - public FlagValue Serve { get; set; } - } + flag.Serve.IsSet.ShouldBeTrue(); + flag.Serve.Value.ShouldBe(123); + }); + } - [Fact] - public void Should_Throw_If_Command_Option_Value_Is_Optional_But_Type_Is_Not_A_Flag_Value() + [Fact] + public void Should_Only_Set_Flag_If_No_Value_Was_Provided() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => { - // Given - var app = new CommandApp(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddCommand>("foo"); - }); + config.PropagateExceptions(); + config.AddCommand>("foo"); + }); - // When - var result = Record.Exception(() => app.Run(new[] { "foo", "--serve", "123" })); + // When + var result = app.Run(new[] { "foo", "--serve" }); - // Then - result.ShouldBeOfType().And(ex => - { - ex.Message.ShouldBe("The option 'serve' has an optional value but does not implement IFlagValue."); - }); - } - - [Fact] - public void Should_Set_Flag_And_Value_If_Both_Were_Provided() + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(flag => { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddCommand>("foo"); - }); + flag.Serve.IsSet.ShouldBeTrue(); + flag.Serve.Value.ShouldBe(0); + }); + } - // When - var result = app.Run(new[] { "foo", "--serve", "123", }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(flag => - { - flag.Serve.IsSet.ShouldBeTrue(); - flag.Serve.Value.ShouldBe(123); - }); - } - - [Fact] - public void Should_Only_Set_Flag_If_No_Value_Was_Provided() + [Fact] + public void Should_Set_Value_To_Default_Value_If_None_Was_Explicitly_Set() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddCommand>("foo"); - }); + config.PropagateExceptions(); + config.AddCommand>("foo"); + }); - // When - var result = app.Run(new[] { "foo", "--serve" }); + // When + var result = app.Run(new[] { "foo", "--serve" }); - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(flag => - { - flag.Serve.IsSet.ShouldBeTrue(); - flag.Serve.Value.ShouldBe(0); - }); - } - - [Fact] - public void Should_Set_Value_To_Default_Value_If_None_Was_Explicitly_Set() + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(flag => { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddCommand>("foo"); - }); + flag.Serve.IsSet.ShouldBeTrue(); + flag.Serve.Value.ShouldBe(987); + }); + } - // When - var result = app.Run(new[] { "foo", "--serve" }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(flag => - { - flag.Serve.IsSet.ShouldBeTrue(); - flag.Serve.Value.ShouldBe(987); - }); - } - - [Fact] - public void Should_Create_Unset_Instance_If_Flag_Was_Not_Set() + [Fact] + public void Should_Create_Unset_Instance_If_Flag_Was_Not_Set() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddCommand>("foo"); - }); + config.PropagateExceptions(); + config.AddCommand>("foo"); + }); - // When - var result = app.Run(new[] { "foo" }); + // When + var result = app.Run(new[] { "foo" }); - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(flag => - { - flag.Serve.IsSet.ShouldBeFalse(); - flag.Serve.Value.ShouldBe(0); - }); - } - - [Fact] - public void Should_Create_Unset_Instance_With_Null_For_Nullable_Value_Type_If_Flag_Was_Not_Set() + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(flag => { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddCommand>("foo"); - }); + flag.Serve.IsSet.ShouldBeFalse(); + flag.Serve.Value.ShouldBe(0); + }); + } - // When - var result = app.Run(new[] { "foo" }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(flag => - { - flag.Serve.IsSet.ShouldBeFalse(); - flag.Serve.Value.ShouldBeNull(); - }); - } - - [Theory] - [InlineData("Foo", true, "Set=True, Value=Foo")] - [InlineData("Bar", false, "Set=False, Value=Bar")] - public void Should_Return_Correct_String_Representation_From_ToString( - string value, - bool isSet, - string expected) + [Fact] + public void Should_Create_Unset_Instance_With_Null_For_Nullable_Value_Type_If_Flag_Was_Not_Set() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => { - // Given - var flag = new FlagValue - { - Value = value, - IsSet = isSet, - }; + config.PropagateExceptions(); + config.AddCommand>("foo"); + }); - // When - var result = flag.ToString(); + // When + var result = app.Run(new[] { "foo" }); - // Then - result.ShouldBe(expected); - } - - [Theory] - [InlineData(true, "Set=True")] - [InlineData(false, "Set=False")] - public void Should_Return_Correct_String_Representation_From_ToString_If_Value_Is_Not_Set( - bool isSet, - string expected) + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(flag => { - // Given - var flag = new FlagValue - { - IsSet = isSet, - }; + flag.Serve.IsSet.ShouldBeFalse(); + flag.Serve.Value.ShouldBeNull(); + }); + } - // When - var result = flag.ToString(); + [Theory] + [InlineData("Foo", true, "Set=True, Value=Foo")] + [InlineData("Bar", false, "Set=False, Value=Bar")] + public void Should_Return_Correct_String_Representation_From_ToString( + string value, + bool isSet, + string expected) + { + // Given + var flag = new FlagValue + { + Value = value, + IsSet = isSet, + }; - // Then - result.ShouldBe(expected); - } + // When + var result = flag.ToString(); + + // Then + result.ShouldBe(expected); + } + + [Theory] + [InlineData(true, "Set=True")] + [InlineData(false, "Set=False")] + public void Should_Return_Correct_String_Representation_From_ToString_If_Value_Is_Not_Set( + bool isSet, + string expected) + { + // Given + var flag = new FlagValue + { + IsSet = isSet, + }; + + // When + var result = flag.ToString(); + + // Then + result.ShouldBe(expected); } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Help.cs b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Help.cs index d2d5670..a014e39 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Help.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Help.cs @@ -1,302 +1,293 @@ -using System.Threading.Tasks; -using Spectre.Console.Cli; -using Spectre.Console.Testing; -using Spectre.Console.Tests.Data; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli; -namespace Spectre.Console.Tests.Unit.Cli +public sealed partial class CommandAppTests { - public sealed partial class CommandAppTests + [UsesVerify] + [ExpectationPath("Cli/Help")] + public class Help { - [UsesVerify] - [ExpectationPath("Cli/Help")] - public class Help + [Fact] + [Expectation("Root")] + public Task Should_Output_Root_Correctly() { - [Fact] - [Expectation("Root")] - public Task Should_Output_Root_Correctly() + // Given + var fixture = new CommandAppTester(); + fixture.Configure(configurator => { - // Given - var fixture = new CommandAppTester(); - fixture.Configure(configurator => - { - configurator.SetApplicationName("myapp"); - configurator.AddCommand("dog"); - configurator.AddCommand("horse"); - configurator.AddCommand("giraffe"); - }); + configurator.SetApplicationName("myapp"); + configurator.AddCommand("dog"); + configurator.AddCommand("horse"); + configurator.AddCommand("giraffe"); + }); - // When - var result = fixture.Run("--help"); + // When + var result = fixture.Run("--help"); - // Then - return Verifier.Verify(result.Output); - } + // Then + return Verifier.Verify(result.Output); + } - [Fact] - [Expectation("Hidden_Commands")] - public Task Should_Skip_Hidden_Commands() + [Fact] + [Expectation("Hidden_Commands")] + public Task Should_Skip_Hidden_Commands() + { + // Given + var fixture = new CommandAppTester(); + fixture.Configure(configurator => { - // Given - var fixture = new CommandAppTester(); - fixture.Configure(configurator => - { - configurator.SetApplicationName("myapp"); - configurator.AddCommand("dog"); - configurator.AddCommand("horse"); - configurator.AddCommand("giraffe") - .WithExample(new[] { "giraffe", "123" }) - .IsHidden(); - }); + configurator.SetApplicationName("myapp"); + configurator.AddCommand("dog"); + configurator.AddCommand("horse"); + configurator.AddCommand("giraffe") + .WithExample(new[] { "giraffe", "123" }) + .IsHidden(); + }); - // When - var result = fixture.Run("--help"); + // When + var result = fixture.Run("--help"); - // Then - return Verifier.Verify(result.Output); - } + // Then + return Verifier.Verify(result.Output); + } - [Fact] - [Expectation("Command")] - public Task Should_Output_Command_Correctly() + [Fact] + [Expectation("Command")] + public Task Should_Output_Command_Correctly() + { + // Given + var fixture = new CommandAppTester(); + fixture.Configure(configurator => { - // Given - var fixture = new CommandAppTester(); - fixture.Configure(configurator => + configurator.SetApplicationName("myapp"); + configurator.AddBranch("cat", animal => { - configurator.SetApplicationName("myapp"); - configurator.AddBranch("cat", animal => - { - animal.SetDescription("Contains settings for a cat."); - animal.AddCommand("lion"); - }); + animal.SetDescription("Contains settings for a cat."); + animal.AddCommand("lion"); }); + }); - // When - var result = fixture.Run("cat", "--help"); + // When + var result = fixture.Run("cat", "--help"); - // Then - return Verifier.Verify(result.Output); - } + // Then + return Verifier.Verify(result.Output); + } - [Fact] - [Expectation("Leaf")] - public Task Should_Output_Leaf_Correctly() + [Fact] + [Expectation("Leaf")] + public Task Should_Output_Leaf_Correctly() + { + // Given + var fixture = new CommandAppTester(); + fixture.Configure(configurator => { - // Given - var fixture = new CommandAppTester(); - fixture.Configure(configurator => + configurator.SetApplicationName("myapp"); + configurator.AddBranch("cat", animal => { - configurator.SetApplicationName("myapp"); - configurator.AddBranch("cat", animal => - { - animal.SetDescription("Contains settings for a cat."); - animal.AddCommand("lion"); - }); + animal.SetDescription("Contains settings for a cat."); + animal.AddCommand("lion"); }); + }); - // When - var result = fixture.Run("cat", "lion", "--help"); + // When + var result = fixture.Run("cat", "lion", "--help"); - // Then - return Verifier.Verify(result.Output); - } + // Then + return Verifier.Verify(result.Output); + } - [Fact] - [Expectation("Default")] - public Task Should_Output_Default_Command_Correctly() + [Fact] + [Expectation("Default")] + public Task Should_Output_Default_Command_Correctly() + { + // Given + var fixture = new CommandAppTester(); + fixture.SetDefaultCommand(); + fixture.Configure(configurator => { - // Given - var fixture = new CommandAppTester(); - fixture.SetDefaultCommand(); - fixture.Configure(configurator => - { - configurator.SetApplicationName("myapp"); - }); + configurator.SetApplicationName("myapp"); + }); - // When - var result = fixture.Run("--help"); + // When + var result = fixture.Run("--help"); - // Then - return Verifier.Verify(result.Output); - } + // Then + return Verifier.Verify(result.Output); + } - [Fact] - [Expectation("RootExamples")] - public Task Should_Output_Root_Examples_Defined_On_Root() + [Fact] + [Expectation("RootExamples")] + public Task Should_Output_Root_Examples_Defined_On_Root() + { + // Given + var fixture = new CommandAppTester(); + fixture.Configure(configurator => { - // Given - var fixture = new CommandAppTester(); - fixture.Configure(configurator => - { - configurator.SetApplicationName("myapp"); - configurator.AddExample(new[] { "dog", "--name", "Rufus", "--age", "12", "--good-boy" }); - configurator.AddExample(new[] { "horse", "--name", "Brutus" }); - configurator.AddCommand("dog"); - configurator.AddCommand("horse"); - }); + configurator.SetApplicationName("myapp"); + configurator.AddExample(new[] { "dog", "--name", "Rufus", "--age", "12", "--good-boy" }); + configurator.AddExample(new[] { "horse", "--name", "Brutus" }); + configurator.AddCommand("dog"); + configurator.AddCommand("horse"); + }); - // When - var result = fixture.Run("--help"); + // When + var result = fixture.Run("--help"); - // Then - return Verifier.Verify(result.Output); - } + // Then + return Verifier.Verify(result.Output); + } - [Fact] - [Expectation("RootExamples_Children")] - public Task Should_Output_Root_Examples_Defined_On_Direct_Children_If_Root_Have_No_Examples() + [Fact] + [Expectation("RootExamples_Children")] + public Task Should_Output_Root_Examples_Defined_On_Direct_Children_If_Root_Have_No_Examples() + { + // Given + var fixture = new CommandAppTester(); + fixture.Configure(configurator => { - // Given - var fixture = new CommandAppTester(); - fixture.Configure(configurator => - { - configurator.SetApplicationName("myapp"); - configurator.AddCommand("dog") - .WithExample(new[] { "dog", "--name", "Rufus", "--age", "12", "--good-boy" }); - configurator.AddCommand("horse") - .WithExample(new[] { "horse", "--name", "Brutus" }); - }); + configurator.SetApplicationName("myapp"); + configurator.AddCommand("dog") + .WithExample(new[] { "dog", "--name", "Rufus", "--age", "12", "--good-boy" }); + configurator.AddCommand("horse") + .WithExample(new[] { "horse", "--name", "Brutus" }); + }); - // When - var result = fixture.Run("--help"); + // When + var result = fixture.Run("--help"); - // Then - return Verifier.Verify(result.Output); - } + // Then + return Verifier.Verify(result.Output); + } - [Fact] - [Expectation("RootExamples_Leafs")] - public Task Should_Output_Root_Examples_Defined_On_Leaves_If_No_Other_Examples_Are_Found() + [Fact] + [Expectation("RootExamples_Leafs")] + public Task Should_Output_Root_Examples_Defined_On_Leaves_If_No_Other_Examples_Are_Found() + { + // Given + var fixture = new CommandAppTester(); + fixture.Configure(configurator => { - // Given - var fixture = new CommandAppTester(); - fixture.Configure(configurator => + configurator.SetApplicationName("myapp"); + configurator.AddBranch("animal", animal => { - configurator.SetApplicationName("myapp"); - configurator.AddBranch("animal", animal => - { - animal.SetDescription("The animal command."); - animal.AddCommand("dog") - .WithExample(new[] { "animal", "dog", "--name", "Rufus", "--age", "12", "--good-boy" }); - animal.AddCommand("horse") - .WithExample(new[] { "animal", "horse", "--name", "Brutus" }); - }); + animal.SetDescription("The animal command."); + animal.AddCommand("dog") + .WithExample(new[] { "animal", "dog", "--name", "Rufus", "--age", "12", "--good-boy" }); + animal.AddCommand("horse") + .WithExample(new[] { "animal", "horse", "--name", "Brutus" }); }); + }); - // When - var result = fixture.Run("--help"); + // When + var result = fixture.Run("--help"); - // Then - return Verifier.Verify(result.Output); - } + // Then + return Verifier.Verify(result.Output); + } - [Fact] - [Expectation("CommandExamples")] - public Task Should_Only_Output_Command_Examples_Defined_On_Command() + [Fact] + [Expectation("CommandExamples")] + public Task Should_Only_Output_Command_Examples_Defined_On_Command() + { + // Given + var fixture = new CommandAppTester(); + fixture.Configure(configurator => { - // Given - var fixture = new CommandAppTester(); - fixture.Configure(configurator => + configurator.SetApplicationName("myapp"); + configurator.AddBranch("animal", animal => { - configurator.SetApplicationName("myapp"); - configurator.AddBranch("animal", animal => - { - animal.SetDescription("The animal command."); - animal.AddExample(new[] { "animal", "--help" }); + animal.SetDescription("The animal command."); + animal.AddExample(new[] { "animal", "--help" }); - animal.AddCommand("dog") - .WithExample(new[] { "animal", "dog", "--name", "Rufus", "--age", "12", "--good-boy" }); - animal.AddCommand("horse") - .WithExample(new[] { "animal", "horse", "--name", "Brutus" }); - }); + animal.AddCommand("dog") + .WithExample(new[] { "animal", "dog", "--name", "Rufus", "--age", "12", "--good-boy" }); + animal.AddCommand("horse") + .WithExample(new[] { "animal", "horse", "--name", "Brutus" }); }); + }); - // When - var result = fixture.Run("animal", "--help"); + // When + var result = fixture.Run("animal", "--help"); - // Then - return Verifier.Verify(result.Output); - } + // Then + return Verifier.Verify(result.Output); + } - [Fact] - [Expectation("DefaultExamples")] - public Task Should_Output_Root_Examples_If_Default_Command_Is_Specified() + [Fact] + [Expectation("DefaultExamples")] + public Task Should_Output_Root_Examples_If_Default_Command_Is_Specified() + { + // Given + var fixture = new CommandAppTester(); + fixture.SetDefaultCommand(); + fixture.Configure(configurator => { - // Given - var fixture = new CommandAppTester(); - fixture.SetDefaultCommand(); - fixture.Configure(configurator => - { - configurator.SetApplicationName("myapp"); - configurator.AddExample(new[] { "12", "-c", "3" }); - }); + configurator.SetApplicationName("myapp"); + configurator.AddExample(new[] { "12", "-c", "3" }); + }); - // When - var result = fixture.Run("--help"); + // When + var result = fixture.Run("--help"); - // Then - return Verifier.Verify(result.Output); - } + // Then + return Verifier.Verify(result.Output); + } - [Fact] - [Expectation("NoDescription")] - public Task Should_Not_Show_Truncated_Command_Table_If_Commands_Are_Missing_Description() + [Fact] + [Expectation("NoDescription")] + public Task Should_Not_Show_Truncated_Command_Table_If_Commands_Are_Missing_Description() + { + // Given + var fixture = new CommandAppTester(); + fixture.Configure(configurator => { - // Given - var fixture = new CommandAppTester(); - fixture.Configure(configurator => - { - configurator.SetApplicationName("myapp"); - configurator.AddCommand("bar"); - }); + configurator.SetApplicationName("myapp"); + configurator.AddCommand("bar"); + }); - // When - var result = fixture.Run("--help"); + // When + var result = fixture.Run("--help"); - // Then - return Verifier.Verify(result.Output); - } + // Then + return Verifier.Verify(result.Output); + } - [Fact] - [Expectation("ArgumentOrder")] - public Task Should_List_Arguments_In_Correct_Order() + [Fact] + [Expectation("ArgumentOrder")] + public Task Should_List_Arguments_In_Correct_Order() + { + // Given + var fixture = new CommandAppTester(); + fixture.SetDefaultCommand>(); + fixture.Configure(configurator => { - // Given - var fixture = new CommandAppTester(); - fixture.SetDefaultCommand>(); - fixture.Configure(configurator => - { - configurator.SetApplicationName("myapp"); - }); + configurator.SetApplicationName("myapp"); + }); - // When - var result = fixture.Run("--help"); + // When + var result = fixture.Run("--help"); - // Then - return Verifier.Verify(result.Output); - } + // Then + return Verifier.Verify(result.Output); + } - [Fact] - [Expectation("Hidden_Command_Options")] - public Task Should_Not_Show_Hidden_Command_Options() + [Fact] + [Expectation("Hidden_Command_Options")] + public Task Should_Not_Show_Hidden_Command_Options() + { + // Given + var fixture = new CommandAppTester(); + fixture.SetDefaultCommand>(); + fixture.Configure(configurator => { - // Given - var fixture = new CommandAppTester(); - fixture.SetDefaultCommand>(); - fixture.Configure(configurator => - { - configurator.SetApplicationName("myapp"); - }); + configurator.SetApplicationName("myapp"); + }); - // When - var result = fixture.Run("--help"); + // When + var result = fixture.Run("--help"); - // Then - return Verifier.Verify(result.Output); - } + // Then + return Verifier.Verify(result.Output); } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Injection.cs b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Injection.cs index eeab2a6..b30472d 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Injection.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Injection.cs @@ -1,97 +1,90 @@ -using Shouldly; -using Spectre.Console.Cli; -using Spectre.Console.Testing; -using Spectre.Console.Tests.Data; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli; -namespace Spectre.Console.Tests.Unit.Cli +public sealed partial class CommandAppTests { - public sealed partial class CommandAppTests + public sealed class Injection { - public sealed class Injection + public sealed class FakeDependency { - public sealed class FakeDependency + } + + public sealed class InjectSettings : CommandSettings + { + public FakeDependency Fake { get; set; } + + [CommandOption("--name ")] + public string Name { get; } + + [CommandOption("--age ")] + public int Age { get; set; } + + public InjectSettings(FakeDependency fake, string name) { - } - - public sealed class InjectSettings : CommandSettings - { - public FakeDependency Fake { get; set; } - - [CommandOption("--name ")] - public string Name { get; } - - [CommandOption("--age ")] - public int Age { get; set; } - - public InjectSettings(FakeDependency fake, string name) - { - Fake = fake; - Name = "Hello " + name; - } - } - - [Fact] - public void Should_Inject_Parameters() - { - // Given - var app = new CommandAppTester(); - var dependency = new FakeDependency(); - - app.SetDefaultCommand>(); - app.Configure(config => - { - config.Settings.Registrar.RegisterInstance(dependency); - config.PropagateExceptions(); - }); - - // When - var result = app.Run(new[] - { - "--name", "foo", - "--age", "35", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(injected => - { - injected.ShouldNotBeNull(); - injected.Fake.ShouldBeSameAs(dependency); - injected.Name.ShouldBe("Hello foo"); - injected.Age.ShouldBe(35); - }); - } - - [Fact] - public void Should_Inject_Dependency_Using_A_Given_Registrar() - { - // Given - var dependency = new FakeDependency(); - var registrar = new FakeTypeRegistrar { TypeResolverFactory = FakeTypeResolver.Factory }; - registrar.RegisterInstance(typeof(FakeDependency), dependency); - var app = new CommandAppTester(registrar); - - app.SetDefaultCommand>(); - app.Configure(config => config.PropagateExceptions()); - - // When - var result = app.Run(new[] - { - "--name", "foo", - "--age", "35", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(injected => - { - injected.ShouldNotBeNull(); - injected.Fake.ShouldBeSameAs(dependency); - injected.Name.ShouldBe("Hello foo"); - injected.Age.ShouldBe(35); - }); + Fake = fake; + Name = "Hello " + name; } } + + [Fact] + public void Should_Inject_Parameters() + { + // Given + var app = new CommandAppTester(); + var dependency = new FakeDependency(); + + app.SetDefaultCommand>(); + app.Configure(config => + { + config.Settings.Registrar.RegisterInstance(dependency); + config.PropagateExceptions(); + }); + + // When + var result = app.Run(new[] + { + "--name", "foo", + "--age", "35", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(injected => + { + injected.ShouldNotBeNull(); + injected.Fake.ShouldBeSameAs(dependency); + injected.Name.ShouldBe("Hello foo"); + injected.Age.ShouldBe(35); + }); + } + + [Fact] + public void Should_Inject_Dependency_Using_A_Given_Registrar() + { + // Given + var dependency = new FakeDependency(); + var registrar = new FakeTypeRegistrar { TypeResolverFactory = FakeTypeResolver.Factory }; + registrar.RegisterInstance(typeof(FakeDependency), dependency); + var app = new CommandAppTester(registrar); + + app.SetDefaultCommand>(); + app.Configure(config => config.PropagateExceptions()); + + // When + var result = app.Run(new[] + { + "--name", "foo", + "--age", "35", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(injected => + { + injected.ShouldNotBeNull(); + injected.Fake.ShouldBeSameAs(dependency); + injected.Name.ShouldBe("Hello foo"); + injected.Age.ShouldBe(35); + }); + } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Pairs.cs b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Pairs.cs index eb8ba40..944891d 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Pairs.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Pairs.cs @@ -1,327 +1,316 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using Shouldly; -using Spectre.Console.Cli; -using Spectre.Console.Testing; -using Spectre.Console.Tests.Data; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli; -namespace Spectre.Console.Tests.Unit.Cli +public sealed partial class CommandAppTests { - public sealed partial class CommandAppTests + public sealed class Pairs { - public sealed class Pairs + public sealed class AmbiguousSettings : CommandSettings { - public sealed class AmbiguousSettings : CommandSettings - { - [CommandOption("--var ")] - [PairDeconstructor(typeof(StringIntDeconstructor))] - [TypeConverter(typeof(CatAgilityConverter))] - public ILookup Values { get; set; } - } + [CommandOption("--var ")] + [PairDeconstructor(typeof(StringIntDeconstructor))] + [TypeConverter(typeof(CatAgilityConverter))] + public ILookup Values { get; set; } + } - public sealed class NotDeconstructableSettings : CommandSettings - { - [CommandOption("--var ")] - [PairDeconstructor(typeof(StringIntDeconstructor))] - public string Values { get; set; } - } + public sealed class NotDeconstructableSettings : CommandSettings + { + [CommandOption("--var ")] + [PairDeconstructor(typeof(StringIntDeconstructor))] + public string Values { get; set; } + } - public sealed class DefaultPairDeconstructorSettings : CommandSettings - { - [CommandOption("--var ")] - public IDictionary Values { get; set; } - } + public sealed class DefaultPairDeconstructorSettings : CommandSettings + { + [CommandOption("--var ")] + public IDictionary Values { get; set; } + } - public sealed class DefaultPairDeconstructorEnumValueSettings : CommandSettings - { - [CommandOption("--var ")] - public IDictionary Values { get; set; } - } + public sealed class DefaultPairDeconstructorEnumValueSettings : CommandSettings + { + [CommandOption("--var ")] + public IDictionary Values { get; set; } + } - public sealed class LookupSettings : CommandSettings - { - [CommandOption("--var ")] - [PairDeconstructor(typeof(StringIntDeconstructor))] - public ILookup Values { get; set; } - } + public sealed class LookupSettings : CommandSettings + { + [CommandOption("--var ")] + [PairDeconstructor(typeof(StringIntDeconstructor))] + public ILookup Values { get; set; } + } - public sealed class DictionarySettings : CommandSettings - { - [CommandOption("--var ")] - [PairDeconstructor(typeof(StringIntDeconstructor))] - public IDictionary Values { get; set; } - } + public sealed class DictionarySettings : CommandSettings + { + [CommandOption("--var ")] + [PairDeconstructor(typeof(StringIntDeconstructor))] + public IDictionary Values { get; set; } + } - public sealed class ReadOnlyDictionarySettings : CommandSettings - { - [CommandOption("--var ")] - [PairDeconstructor(typeof(StringIntDeconstructor))] - public IReadOnlyDictionary Values { get; set; } - } + public sealed class ReadOnlyDictionarySettings : CommandSettings + { + [CommandOption("--var ")] + [PairDeconstructor(typeof(StringIntDeconstructor))] + public IReadOnlyDictionary Values { get; set; } + } - public sealed class StringIntDeconstructor : PairDeconstructor + public sealed class StringIntDeconstructor : PairDeconstructor + { + protected override (string Key, string Value) Deconstruct(string value) { - protected override (string Key, string Value) Deconstruct(string value) + if (value == null) { - if (value == null) - { - throw new ArgumentNullException(nameof(value)); - } - - var parts = value.Split(new[] { '=' }); - if (parts.Length != 2) - { - throw new InvalidOperationException("Could not parse pair"); - } - - return (parts[0], parts[1]); + throw new ArgumentNullException(nameof(value)); } - } - [Fact] - public void Should_Throw_If_Option_Has_Pair_Deconstructor_And_Type_Converter() - { - // Given - var app = new CommandApp>(); - app.Configure(config => + var parts = value.Split(new[] { '=' }); + if (parts.Length != 2) { - config.PropagateExceptions(); - }); + throw new InvalidOperationException("Could not parse pair"); + } - // When - var result = Record.Exception(() => app.Run(new[] - { - "--var", "foo=bar", - "--var", "foo=qux", - })); - - // Then - result.ShouldBeOfType().And(ex => - { - ex.Message.ShouldBe("The option 'var' is both marked as pair deconstructable and convertable."); - }); - } - - [Fact] - public void Should_Throw_If_Option_Has_Pair_Deconstructor_But_Type_Is_Not_Deconstructable() - { - // Given - var app = new CommandApp>(); - app.Configure(config => - { - config.PropagateExceptions(); - }); - - // When - var result = Record.Exception(() => app.Run(new[] - { - "--var", "foo=bar", - "--var", "foo=qux", - })); - - // Then - result.ShouldBeOfType().And(ex => - { - ex.Message.ShouldBe("The option 'var' is marked as pair deconstructable, but the underlying type does not support that."); - }); - } - - [Fact] - public void Should_Map_Pairs_To_Pair_Deconstructable_Collection_Using_Default_Deconstructort() - { - // Given - var app = new CommandAppTester(); - app.SetDefaultCommand>(); - app.Configure(config => - { - config.PropagateExceptions(); - }); - - // When - var result = app.Run(new[] - { - "--var", "foo=1", - "--var", "foo=3", - "--var", "bar=4", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(pair => - { - pair.Values.ShouldNotBeNull(); - pair.Values.Count.ShouldBe(2); - pair.Values["foo"].ShouldBe(3); - pair.Values["bar"].ShouldBe(4); - }); - } - - [Fact] - public void Should_Map_Pairs_With_Enum_Value_To_Pair_Deconstructable_Collection_Using_Default_Deconstructor() - { - // Given - var app = new CommandAppTester(); - app.SetDefaultCommand>(); - app.Configure(config => - { - config.PropagateExceptions(); - }); - - // When - var result = app.Run(new[] - { - "--var", "foo=Monday", - "--var", "bar=Tuesday", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(pair => - { - pair.Values.ShouldNotBeNull(); - pair.Values.Count.ShouldBe(2); - pair.Values["foo"].ShouldBe(DayOfWeek.Monday); - pair.Values["bar"].ShouldBe(DayOfWeek.Tuesday); - }); - } - - [Theory] - [InlineData("foo=1=2", "Error: The value 'foo=1=2' is not in a correct format")] - [InlineData("foo=1=2=3", "Error: The value 'foo=1=2=3' is not in a correct format")] - public void Should_Throw_If_Value_Is_Not_In_A_Valid_Format_Using_Default_Deconstructor( - string input, string expected) - { - // Given - var app = new CommandAppTester(); - app.SetDefaultCommand>(); - - // When - var result = app.Run(new[] - { - "--var", input, - }); - - // Then - result.ExitCode.ShouldBe(-1); - result.Output.ShouldBe(expected); - } - - [Fact] - public void Should_Map_Lookup_Values() - { - // Given - var app = new CommandAppTester(); - app.SetDefaultCommand>(); - app.Configure(config => - { - config.PropagateExceptions(); - }); - - // When - var result = app.Run(new[] - { - "--var", "foo=bar", - "--var", "foo=qux", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(pair => - { - pair.Values.ShouldNotBeNull(); - pair.Values.Count.ShouldBe(1); - pair.Values["foo"].ToList().Count.ShouldBe(2); - }); - } - - [Fact] - public void Should_Map_Dictionary_Values() - { - // Given - var app = new CommandAppTester(); - app.SetDefaultCommand>(); - app.Configure(config => - { - config.PropagateExceptions(); - }); - - // When - var result = app.Run(new[] - { - "--var", "foo=bar", - "--var", "baz=qux", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(pair => - { - pair.Values.ShouldNotBeNull(); - pair.Values.Count.ShouldBe(2); - pair.Values["foo"].ShouldBe("bar"); - pair.Values["baz"].ShouldBe("qux"); - }); - } - - [Fact] - public void Should_Map_Latest_Value_Of_Same_Key_When_Mapping_To_Dictionary() - { - // Given - var app = new CommandAppTester(); - app.SetDefaultCommand>(); - app.Configure(config => - { - config.PropagateExceptions(); - }); - - // When - var result = app.Run(new[] - { - "--var", "foo=bar", - "--var", "foo=qux", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(pair => - { - pair.Values.ShouldNotBeNull(); - pair.Values.Count.ShouldBe(1); - pair.Values["foo"].ShouldBe("qux"); - }); - } - - [Fact] - public void Should_Map_ReadOnly_Dictionary_Values() - { - // Given - var app = new CommandAppTester(); - app.SetDefaultCommand>(); - app.Configure(config => - { - config.PropagateExceptions(); - }); - - // When - var result = app.Run(new[] - { - "--var", "foo=bar", - "--var", "baz=qux", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(pair => - { - pair.Values.ShouldNotBeNull(); - pair.Values.Count.ShouldBe(2); - pair.Values["foo"].ShouldBe("bar"); - pair.Values["baz"].ShouldBe("qux"); - }); + return (parts[0], parts[1]); } } + + [Fact] + public void Should_Throw_If_Option_Has_Pair_Deconstructor_And_Type_Converter() + { + // Given + var app = new CommandApp>(); + app.Configure(config => + { + config.PropagateExceptions(); + }); + + // When + var result = Record.Exception(() => app.Run(new[] + { + "--var", "foo=bar", + "--var", "foo=qux", + })); + + // Then + result.ShouldBeOfType().And(ex => + { + ex.Message.ShouldBe("The option 'var' is both marked as pair deconstructable and convertable."); + }); + } + + [Fact] + public void Should_Throw_If_Option_Has_Pair_Deconstructor_But_Type_Is_Not_Deconstructable() + { + // Given + var app = new CommandApp>(); + app.Configure(config => + { + config.PropagateExceptions(); + }); + + // When + var result = Record.Exception(() => app.Run(new[] + { + "--var", "foo=bar", + "--var", "foo=qux", + })); + + // Then + result.ShouldBeOfType().And(ex => + { + ex.Message.ShouldBe("The option 'var' is marked as pair deconstructable, but the underlying type does not support that."); + }); + } + + [Fact] + public void Should_Map_Pairs_To_Pair_Deconstructable_Collection_Using_Default_Deconstructort() + { + // Given + var app = new CommandAppTester(); + app.SetDefaultCommand>(); + app.Configure(config => + { + config.PropagateExceptions(); + }); + + // When + var result = app.Run(new[] + { + "--var", "foo=1", + "--var", "foo=3", + "--var", "bar=4", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(pair => + { + pair.Values.ShouldNotBeNull(); + pair.Values.Count.ShouldBe(2); + pair.Values["foo"].ShouldBe(3); + pair.Values["bar"].ShouldBe(4); + }); + } + + [Fact] + public void Should_Map_Pairs_With_Enum_Value_To_Pair_Deconstructable_Collection_Using_Default_Deconstructor() + { + // Given + var app = new CommandAppTester(); + app.SetDefaultCommand>(); + app.Configure(config => + { + config.PropagateExceptions(); + }); + + // When + var result = app.Run(new[] + { + "--var", "foo=Monday", + "--var", "bar=Tuesday", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(pair => + { + pair.Values.ShouldNotBeNull(); + pair.Values.Count.ShouldBe(2); + pair.Values["foo"].ShouldBe(DayOfWeek.Monday); + pair.Values["bar"].ShouldBe(DayOfWeek.Tuesday); + }); + } + + [Theory] + [InlineData("foo=1=2", "Error: The value 'foo=1=2' is not in a correct format")] + [InlineData("foo=1=2=3", "Error: The value 'foo=1=2=3' is not in a correct format")] + public void Should_Throw_If_Value_Is_Not_In_A_Valid_Format_Using_Default_Deconstructor( + string input, string expected) + { + // Given + var app = new CommandAppTester(); + app.SetDefaultCommand>(); + + // When + var result = app.Run(new[] + { + "--var", input, + }); + + // Then + result.ExitCode.ShouldBe(-1); + result.Output.ShouldBe(expected); + } + + [Fact] + public void Should_Map_Lookup_Values() + { + // Given + var app = new CommandAppTester(); + app.SetDefaultCommand>(); + app.Configure(config => + { + config.PropagateExceptions(); + }); + + // When + var result = app.Run(new[] + { + "--var", "foo=bar", + "--var", "foo=qux", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(pair => + { + pair.Values.ShouldNotBeNull(); + pair.Values.Count.ShouldBe(1); + pair.Values["foo"].ToList().Count.ShouldBe(2); + }); + } + + [Fact] + public void Should_Map_Dictionary_Values() + { + // Given + var app = new CommandAppTester(); + app.SetDefaultCommand>(); + app.Configure(config => + { + config.PropagateExceptions(); + }); + + // When + var result = app.Run(new[] + { + "--var", "foo=bar", + "--var", "baz=qux", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(pair => + { + pair.Values.ShouldNotBeNull(); + pair.Values.Count.ShouldBe(2); + pair.Values["foo"].ShouldBe("bar"); + pair.Values["baz"].ShouldBe("qux"); + }); + } + + [Fact] + public void Should_Map_Latest_Value_Of_Same_Key_When_Mapping_To_Dictionary() + { + // Given + var app = new CommandAppTester(); + app.SetDefaultCommand>(); + app.Configure(config => + { + config.PropagateExceptions(); + }); + + // When + var result = app.Run(new[] + { + "--var", "foo=bar", + "--var", "foo=qux", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(pair => + { + pair.Values.ShouldNotBeNull(); + pair.Values.Count.ShouldBe(1); + pair.Values["foo"].ShouldBe("qux"); + }); + } + + [Fact] + public void Should_Map_ReadOnly_Dictionary_Values() + { + // Given + var app = new CommandAppTester(); + app.SetDefaultCommand>(); + app.Configure(config => + { + config.PropagateExceptions(); + }); + + // When + var result = app.Run(new[] + { + "--var", "foo=bar", + "--var", "baz=qux", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(pair => + { + pair.Values.ShouldNotBeNull(); + pair.Values.Count.ShouldBe(2); + pair.Values["foo"].ShouldBe("bar"); + pair.Values["baz"].ShouldBe("qux"); + }); + } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Parsing.cs b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Parsing.cs index 3fde2c5..0b9893c 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Parsing.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Parsing.cs @@ -1,677 +1,666 @@ -using System; -using System.Threading.Tasks; -using Shouldly; -using Spectre.Console.Cli; -using Spectre.Console.Testing; -using Spectre.Console.Tests.Data; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli; -namespace Spectre.Console.Tests.Unit.Cli +public sealed partial class CommandAppTests { - public sealed partial class CommandAppTests + [UsesVerify] + [ExpectationPath("Cli/Parsing")] + public sealed class Parsing { [UsesVerify] - [ExpectationPath("Cli/Parsing")] - public sealed class Parsing + [ExpectationPath("UnknownCommand")] + public sealed class UnknownCommand { - [UsesVerify] - [ExpectationPath("UnknownCommand")] - public sealed class UnknownCommand + [Fact] + [Expectation("Test_1")] + public Task Should_Return_Correct_Text_When_Command_Is_Unknown() { - [Fact] - [Expectation("Test_1")] - public Task Should_Return_Correct_Text_When_Command_Is_Unknown() + // Given + var fixture = new Fixture(); + fixture.Configure(config => { - // Given - var fixture = new Fixture(); - fixture.Configure(config => - { - config.AddCommand("dog"); - }); + config.AddCommand("dog"); + }); - // When - var result = fixture.Run("cat", "14"); + // When + var result = fixture.Run("cat", "14"); - // Then - return Verifier.Verify(result); - } - - [Fact] - [Expectation("Test_2")] - public Task Should_Return_Correct_Text_For_Unknown_Command_When_Current_Command_Has_No_Arguments() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.AddCommand("empty"); - }); - - // When - var result = fixture.Run("empty", "other"); - - // Then - return Verifier.Verify(result); - } - - [Fact] - [Expectation("Test_3")] - public Task Should_Return_Correct_Text_With_Suggestion_When_Command_Followed_By_Argument_Is_Unknown_And_Distance_Is_Small() - { - // Given - var fixture = new Fixture(); - fixture.Configure(config => - { - config.AddBranch("dog", a => - { - a.AddCommand("cat"); - }); - }); - - // When - var result = fixture.Run("dog", "bat", "14"); - - // Then - return Verifier.Verify(result); - } - - [Fact] - [Expectation("Test_4")] - public Task Should_Return_Correct_Text_With_Suggestion_When_Root_Command_Followed_By_Argument_Is_Unknown_And_Distance_Is_Small() - { - // Given - var fixture = new Fixture(); - fixture.Configure(config => - { - config.AddCommand("cat"); - }); - - // When - var result = fixture.Run("bat", "14"); - - // Then - return Verifier.Verify(result); - } - - [Fact] - [Expectation("Test_5")] - public Task Should_Return_Correct_Text_With_Suggestion_And_No_Arguments_When_Root_Command_Is_Unknown_And_Distance_Is_Small() - { - // Given - var fixture = new Fixture(); - fixture.WithDefaultCommand>(); - fixture.Configure(config => - { - config.AddCommand>("cat"); - }); - - // When - var result = fixture.Run("bat"); - - // Then - return Verifier.Verify(result); - } - - [Fact] - [Expectation("Test_6")] - public Task Should_Return_Correct_Text_With_Suggestion_And_No_Arguments_When_Command_Is_Unknown_And_Distance_Is_Small() - { - // Given - var fixture = new Fixture(); - fixture.WithDefaultCommand>(); - fixture.Configure(configurator => - { - configurator.AddBranch("dog", a => - { - a.AddCommand("cat"); - }); - }); - - // When - var result = fixture.Run("dog", "bat"); - - // Then - return Verifier.Verify(result); - } - - [Fact] - [Expectation("Test_7")] - public Task Should_Return_Correct_Text_With_Suggestion_When_Root_Command_After_Argument_Is_Unknown_And_Distance_Is_Small() - { - // Given - var fixture = new Fixture(); - fixture.WithDefaultCommand>(); - fixture.Configure(configurator => - { - configurator.AddCommand>("bar"); - }); - - // When - var result = fixture.Run("qux", "bat"); - - // Then - return Verifier.Verify(result); - } - - [Fact] - [Expectation("Test_8")] - public Task Should_Return_Correct_Text_With_Suggestion_When_Command_After_Argument_Is_Unknown_And_Distance_Is_Small() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.AddBranch("foo", a => - { - a.AddCommand>("bar"); - }); - }); - - // When - var result = fixture.Run("foo", "qux", "bat"); - - // Then - return Verifier.Verify(result); - } - } - - [UsesVerify] - [ExpectationPath("CannotAssignValueToFlag")] - public sealed class CannotAssignValueToFlag - { - [Fact] - [Expectation("Test_1")] - public Task Should_Return_Correct_Text_For_Long_Option() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.AddCommand("dog"); - }); - - // When - var result = fixture.Run("dog", "--alive", "foo"); - - // Then - return Verifier.Verify(result); - } - - [Fact] - [Expectation("Test_2")] - public Task Should_Return_Correct_Text_For_Short_Option() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.AddCommand("dog"); - }); - - // When - var result = fixture.Run("dog", "-a", "foo"); - - // Then - return Verifier.Verify(result); - } - } - - [UsesVerify] - [ExpectationPath("NoValueForOption")] - public sealed class NoValueForOption - { - [Fact] - [Expectation("Test_1")] - public Task Should_Return_Correct_Text_For_Long_Option() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.AddCommand("dog"); - }); - - // When - var result = fixture.Run("dog", "--name"); - - // Then - return Verifier.Verify(result); - } - - [Fact] - [Expectation("Test_2")] - public Task Should_Return_Correct_Text_For_Short_Option() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.AddCommand("dog"); - }); - - // When - var result = fixture.Run("dog", "-n"); - - // Then - return Verifier.Verify(result); - } - } - - [UsesVerify] - [ExpectationPath("NoMatchingArgument")] - public sealed class NoMatchingArgument - { - [Fact] - [Expectation("Test_1")] - public Task Should_Return_Correct_Text() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.AddCommand("giraffe"); - }); - - // When - var result = fixture.Run("giraffe", "foo", "bar", "baz"); - - // Then - return Verifier.Verify(result); - } - } - - [UsesVerify] - [ExpectationPath("UnexpectedOption")] - public sealed class UnexpectedOption - { - [Fact] - [Expectation("Test_1")] - public Task Should_Return_Correct_Text_For_Long_Option() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.AddCommand("dog"); - }); - - // When - var result = fixture.Run("--foo"); - - // Then - return Verifier.Verify(result); - } - - [Fact] - [Expectation("Test_2")] - public Task Should_Return_Correct_Text_For_Short_Option() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.AddCommand("dog"); - }); - - // When - var result = fixture.Run("-f"); - - // Then - return Verifier.Verify(result); - } - } - - [UsesVerify] - [ExpectationPath("UnknownOption")] - public sealed class UnknownOption - { - [Fact] - [Expectation("Test_1")] - public Task Should_Return_Correct_Text_For_Long_Option_If_Strict_Mode_Is_Enabled() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.UseStrictParsing(); - configurator.AddCommand("dog"); - }); - - // When - var result = fixture.Run("dog", "--unknown"); - - // Then - return Verifier.Verify(result); - } - - [Fact] - [Expectation("Test_2")] - public Task Should_Return_Correct_Text_For_Short_Option_If_Strict_Mode_Is_Enabled() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.UseStrictParsing(); - configurator.AddCommand("dog"); - }); - - // When - var result = fixture.Run("dog", "-u"); - - // Then - return Verifier.Verify(result); - } - } - - [UsesVerify] - [ExpectationPath("UnterminatedQuote")] - public sealed class UnterminatedQuote - { - [Fact] - [Expectation("Test_1")] - public Task Should_Return_Correct_Text() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.AddCommand("dog"); - }); - - // When - var result = fixture.Run("--name", "\"Rufus"); - - // Then - return Verifier.Verify(result); - } - } - - [UsesVerify] - [ExpectationPath("OptionWithoutName")] - public sealed class OptionWithoutName - { - [Fact] - [Expectation("Test_1")] - public Task Should_Return_Correct_Text_For_Short_Option() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.AddCommand("dog"); - }); - - // When - var result = fixture.Run("dog", "-", " "); - - // Then - return Verifier.Verify(result); - } - - [Fact] - [Expectation("Test_2")] - public Task Should_Return_Correct_Text_For_Missing_Long_Option_Value_With_Equality_Separator() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.AddCommand("dog"); - }); - - // When - var result = fixture.Run("dog", $"--foo="); - - // Then - return Verifier.Verify(result); - } - - [Fact] - [Expectation("Test_3")] - public Task Should_Return_Correct_Text_For_Missing_Long_Option_Value_With_Colon_Separator() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.AddCommand("dog"); - }); - - // When - var result = fixture.Run("dog", $"--foo:"); - - // Then - return Verifier.Verify(result); - } - - [Fact] - [Expectation("Test_4")] - public Task Should_Return_Correct_Text_For_Missing_Short_Option_Value_With_Equality_Separator() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.AddCommand("dog"); - }); - - // When - var result = fixture.Run("dog", $"-f="); - - // Then - return Verifier.Verify(result); - } - - [Fact] - [Expectation("Test_5")] - public Task Should_Return_Correct_Text_For_Missing_Short_Option_Value_With_Colon_Separator() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.AddCommand("dog"); - }); - - // When - var result = fixture.Run("dog", $"-f:"); - - // Then - return Verifier.Verify(result); - } - } - - [UsesVerify] - [ExpectationPath("InvalidShortOptionName")] - public sealed class InvalidShortOptionName - { - [Fact] - [Expectation("Test_1")] - public Task Should_Return_Correct_Text() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.AddCommand("dog"); - }); - - // When - var result = fixture.Run("dog", $"-f0o"); - - // Then - return Verifier.Verify(result); - } - } - - [UsesVerify] - [ExpectationPath("LongOptionNameIsOneCharacter")] - public sealed class LongOptionNameIsOneCharacter - { - [Fact] - [Expectation("Test_1")] - public Task Should_Return_Correct_Text() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.AddCommand("dog"); - }); - - // When - var result = fixture.Run("dog", $"--f"); - - // Then - return Verifier.Verify(result); - } - } - - [UsesVerify] - [ExpectationPath("LongOptionNameIsMissing")] - public sealed class LongOptionNameIsMissing - { - [Fact] - [Expectation("Test_1")] - public Task Should_Return_Correct_Text() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.AddCommand("dog"); - }); - - // When - var result = fixture.Run("dog", $"-- "); - - // Then - return Verifier.Verify(result); - } - } - - [UsesVerify] - [ExpectationPath("LongOptionNameStartWithDigit")] - public sealed class LongOptionNameStartWithDigit - { - [Fact] - [Expectation("Test_1")] - public Task Should_Return_Correct_Text() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.AddCommand("dog"); - }); - - // When - var result = fixture.Run("dog", $"--1foo"); - - // Then - return Verifier.Verify(result); - } - } - - [UsesVerify] - [ExpectationPath("LongOptionNameContainSymbol")] - public sealed class LongOptionNameContainSymbol - { - [Fact] - [Expectation("Test_1")] - public Task Should_Return_Correct_Text() - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.AddCommand("dog"); - }); - - // When - var result = fixture.Run("dog", $"--f€oo"); - - // Then - return Verifier.Verify(result); - } - - [Theory] - [InlineData("--f-oo")] - [InlineData("--f-o-o")] - [InlineData("--f_oo")] - [InlineData("--f_o_o")] - public void Should_Allow_Special_Symbols_In_Name(string option) - { - // Given - var fixture = new Fixture(); - fixture.Configure(configurator => - { - configurator.AddCommand("dog"); - }); - - // When - var result = fixture.Run("dog", option); - - // Then - result.ShouldBe("Error: Command 'dog' is missing required argument 'AGE'."); - } + // Then + return Verifier.Verify(result); } [Fact] - [Expectation("Quoted_Strings")] - public Task Should_Parse_Quoted_Strings_Correctly() + [Expectation("Test_2")] + public Task Should_Return_Correct_Text_For_Unknown_Command_When_Current_Command_Has_No_Arguments() { // Given var fixture = new Fixture(); fixture.Configure(configurator => { - configurator.AddCommand("foo"); + configurator.AddCommand("empty"); }); // When - var result = fixture.Run("foo", "--", "/c", "\"set && pause\""); + var result = fixture.Run("empty", "other"); + + // Then + return Verifier.Verify(result); + } + + [Fact] + [Expectation("Test_3")] + public Task Should_Return_Correct_Text_With_Suggestion_When_Command_Followed_By_Argument_Is_Unknown_And_Distance_Is_Small() + { + // Given + var fixture = new Fixture(); + fixture.Configure(config => + { + config.AddBranch("dog", a => + { + a.AddCommand("cat"); + }); + }); + + // When + var result = fixture.Run("dog", "bat", "14"); + + // Then + return Verifier.Verify(result); + } + + [Fact] + [Expectation("Test_4")] + public Task Should_Return_Correct_Text_With_Suggestion_When_Root_Command_Followed_By_Argument_Is_Unknown_And_Distance_Is_Small() + { + // Given + var fixture = new Fixture(); + fixture.Configure(config => + { + config.AddCommand("cat"); + }); + + // When + var result = fixture.Run("bat", "14"); + + // Then + return Verifier.Verify(result); + } + + [Fact] + [Expectation("Test_5")] + public Task Should_Return_Correct_Text_With_Suggestion_And_No_Arguments_When_Root_Command_Is_Unknown_And_Distance_Is_Small() + { + // Given + var fixture = new Fixture(); + fixture.WithDefaultCommand>(); + fixture.Configure(config => + { + config.AddCommand>("cat"); + }); + + // When + var result = fixture.Run("bat"); + + // Then + return Verifier.Verify(result); + } + + [Fact] + [Expectation("Test_6")] + public Task Should_Return_Correct_Text_With_Suggestion_And_No_Arguments_When_Command_Is_Unknown_And_Distance_Is_Small() + { + // Given + var fixture = new Fixture(); + fixture.WithDefaultCommand>(); + fixture.Configure(configurator => + { + configurator.AddBranch("dog", a => + { + a.AddCommand("cat"); + }); + }); + + // When + var result = fixture.Run("dog", "bat"); + + // Then + return Verifier.Verify(result); + } + + [Fact] + [Expectation("Test_7")] + public Task Should_Return_Correct_Text_With_Suggestion_When_Root_Command_After_Argument_Is_Unknown_And_Distance_Is_Small() + { + // Given + var fixture = new Fixture(); + fixture.WithDefaultCommand>(); + fixture.Configure(configurator => + { + configurator.AddCommand>("bar"); + }); + + // When + var result = fixture.Run("qux", "bat"); + + // Then + return Verifier.Verify(result); + } + + [Fact] + [Expectation("Test_8")] + public Task Should_Return_Correct_Text_With_Suggestion_When_Command_After_Argument_Is_Unknown_And_Distance_Is_Small() + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.AddBranch("foo", a => + { + a.AddCommand>("bar"); + }); + }); + + // When + var result = fixture.Run("foo", "qux", "bat"); // Then return Verifier.Verify(result); } } - internal sealed class Fixture + [UsesVerify] + [ExpectationPath("CannotAssignValueToFlag")] + public sealed class CannotAssignValueToFlag { - private Action _appConfiguration = _ => { }; - private Action _configuration; - - public void WithDefaultCommand() - where T : class, ICommand + [Fact] + [Expectation("Test_1")] + public Task Should_Return_Correct_Text_For_Long_Option() { - _appConfiguration = (app) => app.SetDefaultCommand(); - } - - public void Configure(Action action) - { - _configuration = action; - } - - public string Run(params string[] args) - { - using (var console = new TestConsole()) + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => { - var app = new CommandApp(); - _appConfiguration?.Invoke(app); + configurator.AddCommand("dog"); + }); - app.Configure(_configuration); - app.Configure(c => c.ConfigureConsole(console)); - app.Run(args); + // When + var result = fixture.Run("dog", "--alive", "foo"); - return console.Output - .NormalizeLineEndings() - .TrimLines() - .Trim(); - } + // Then + return Verifier.Verify(result); + } + + [Fact] + [Expectation("Test_2")] + public Task Should_Return_Correct_Text_For_Short_Option() + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.AddCommand("dog"); + }); + + // When + var result = fixture.Run("dog", "-a", "foo"); + + // Then + return Verifier.Verify(result); + } + } + + [UsesVerify] + [ExpectationPath("NoValueForOption")] + public sealed class NoValueForOption + { + [Fact] + [Expectation("Test_1")] + public Task Should_Return_Correct_Text_For_Long_Option() + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.AddCommand("dog"); + }); + + // When + var result = fixture.Run("dog", "--name"); + + // Then + return Verifier.Verify(result); + } + + [Fact] + [Expectation("Test_2")] + public Task Should_Return_Correct_Text_For_Short_Option() + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.AddCommand("dog"); + }); + + // When + var result = fixture.Run("dog", "-n"); + + // Then + return Verifier.Verify(result); + } + } + + [UsesVerify] + [ExpectationPath("NoMatchingArgument")] + public sealed class NoMatchingArgument + { + [Fact] + [Expectation("Test_1")] + public Task Should_Return_Correct_Text() + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.AddCommand("giraffe"); + }); + + // When + var result = fixture.Run("giraffe", "foo", "bar", "baz"); + + // Then + return Verifier.Verify(result); + } + } + + [UsesVerify] + [ExpectationPath("UnexpectedOption")] + public sealed class UnexpectedOption + { + [Fact] + [Expectation("Test_1")] + public Task Should_Return_Correct_Text_For_Long_Option() + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.AddCommand("dog"); + }); + + // When + var result = fixture.Run("--foo"); + + // Then + return Verifier.Verify(result); + } + + [Fact] + [Expectation("Test_2")] + public Task Should_Return_Correct_Text_For_Short_Option() + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.AddCommand("dog"); + }); + + // When + var result = fixture.Run("-f"); + + // Then + return Verifier.Verify(result); + } + } + + [UsesVerify] + [ExpectationPath("UnknownOption")] + public sealed class UnknownOption + { + [Fact] + [Expectation("Test_1")] + public Task Should_Return_Correct_Text_For_Long_Option_If_Strict_Mode_Is_Enabled() + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.UseStrictParsing(); + configurator.AddCommand("dog"); + }); + + // When + var result = fixture.Run("dog", "--unknown"); + + // Then + return Verifier.Verify(result); + } + + [Fact] + [Expectation("Test_2")] + public Task Should_Return_Correct_Text_For_Short_Option_If_Strict_Mode_Is_Enabled() + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.UseStrictParsing(); + configurator.AddCommand("dog"); + }); + + // When + var result = fixture.Run("dog", "-u"); + + // Then + return Verifier.Verify(result); + } + } + + [UsesVerify] + [ExpectationPath("UnterminatedQuote")] + public sealed class UnterminatedQuote + { + [Fact] + [Expectation("Test_1")] + public Task Should_Return_Correct_Text() + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.AddCommand("dog"); + }); + + // When + var result = fixture.Run("--name", "\"Rufus"); + + // Then + return Verifier.Verify(result); + } + } + + [UsesVerify] + [ExpectationPath("OptionWithoutName")] + public sealed class OptionWithoutName + { + [Fact] + [Expectation("Test_1")] + public Task Should_Return_Correct_Text_For_Short_Option() + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.AddCommand("dog"); + }); + + // When + var result = fixture.Run("dog", "-", " "); + + // Then + return Verifier.Verify(result); + } + + [Fact] + [Expectation("Test_2")] + public Task Should_Return_Correct_Text_For_Missing_Long_Option_Value_With_Equality_Separator() + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.AddCommand("dog"); + }); + + // When + var result = fixture.Run("dog", $"--foo="); + + // Then + return Verifier.Verify(result); + } + + [Fact] + [Expectation("Test_3")] + public Task Should_Return_Correct_Text_For_Missing_Long_Option_Value_With_Colon_Separator() + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.AddCommand("dog"); + }); + + // When + var result = fixture.Run("dog", $"--foo:"); + + // Then + return Verifier.Verify(result); + } + + [Fact] + [Expectation("Test_4")] + public Task Should_Return_Correct_Text_For_Missing_Short_Option_Value_With_Equality_Separator() + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.AddCommand("dog"); + }); + + // When + var result = fixture.Run("dog", $"-f="); + + // Then + return Verifier.Verify(result); + } + + [Fact] + [Expectation("Test_5")] + public Task Should_Return_Correct_Text_For_Missing_Short_Option_Value_With_Colon_Separator() + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.AddCommand("dog"); + }); + + // When + var result = fixture.Run("dog", $"-f:"); + + // Then + return Verifier.Verify(result); + } + } + + [UsesVerify] + [ExpectationPath("InvalidShortOptionName")] + public sealed class InvalidShortOptionName + { + [Fact] + [Expectation("Test_1")] + public Task Should_Return_Correct_Text() + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.AddCommand("dog"); + }); + + // When + var result = fixture.Run("dog", $"-f0o"); + + // Then + return Verifier.Verify(result); + } + } + + [UsesVerify] + [ExpectationPath("LongOptionNameIsOneCharacter")] + public sealed class LongOptionNameIsOneCharacter + { + [Fact] + [Expectation("Test_1")] + public Task Should_Return_Correct_Text() + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.AddCommand("dog"); + }); + + // When + var result = fixture.Run("dog", $"--f"); + + // Then + return Verifier.Verify(result); + } + } + + [UsesVerify] + [ExpectationPath("LongOptionNameIsMissing")] + public sealed class LongOptionNameIsMissing + { + [Fact] + [Expectation("Test_1")] + public Task Should_Return_Correct_Text() + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.AddCommand("dog"); + }); + + // When + var result = fixture.Run("dog", $"-- "); + + // Then + return Verifier.Verify(result); + } + } + + [UsesVerify] + [ExpectationPath("LongOptionNameStartWithDigit")] + public sealed class LongOptionNameStartWithDigit + { + [Fact] + [Expectation("Test_1")] + public Task Should_Return_Correct_Text() + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.AddCommand("dog"); + }); + + // When + var result = fixture.Run("dog", $"--1foo"); + + // Then + return Verifier.Verify(result); + } + } + + [UsesVerify] + [ExpectationPath("LongOptionNameContainSymbol")] + public sealed class LongOptionNameContainSymbol + { + [Fact] + [Expectation("Test_1")] + public Task Should_Return_Correct_Text() + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.AddCommand("dog"); + }); + + // When + var result = fixture.Run("dog", $"--f€oo"); + + // Then + return Verifier.Verify(result); + } + + [Theory] + [InlineData("--f-oo")] + [InlineData("--f-o-o")] + [InlineData("--f_oo")] + [InlineData("--f_o_o")] + public void Should_Allow_Special_Symbols_In_Name(string option) + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.AddCommand("dog"); + }); + + // When + var result = fixture.Run("dog", option); + + // Then + result.ShouldBe("Error: Command 'dog' is missing required argument 'AGE'."); + } + } + + [Fact] + [Expectation("Quoted_Strings")] + public Task Should_Parse_Quoted_Strings_Correctly() + { + // Given + var fixture = new Fixture(); + fixture.Configure(configurator => + { + configurator.AddCommand("foo"); + }); + + // When + var result = fixture.Run("foo", "--", "/c", "\"set && pause\""); + + // Then + return Verifier.Verify(result); + } + } + + internal sealed class Fixture + { + private Action _appConfiguration = _ => { }; + private Action _configuration; + + public void WithDefaultCommand() + where T : class, ICommand + { + _appConfiguration = (app) => app.SetDefaultCommand(); + } + + public void Configure(Action action) + { + _configuration = action; + } + + public string Run(params string[] args) + { + using (var console = new TestConsole()) + { + var app = new CommandApp(); + _appConfiguration?.Invoke(app); + + app.Configure(_configuration); + app.Configure(c => c.ConfigureConsole(console)); + app.Run(args); + + return console.Output + .NormalizeLineEndings() + .TrimLines() + .Trim(); } } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Remaining.cs b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Remaining.cs index e02c70b..ba1b31a 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Remaining.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Remaining.cs @@ -1,77 +1,70 @@ -using Shouldly; -using Spectre.Console.Cli; -using Spectre.Console.Testing; -using Spectre.Console.Tests.Data; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli; -namespace Spectre.Console.Tests.Unit.Cli +public sealed partial class CommandAppTests { - public sealed partial class CommandAppTests + public sealed class Remaining { - public sealed class Remaining + [Fact] + public void Should_Register_Remaining_Parsed_Arguments_With_Context() { - [Fact] - public void Should_Register_Remaining_Parsed_Arguments_With_Context() + // Given + var app = new CommandAppTester(); + app.Configure(config => { - // Given - var app = new CommandAppTester(); - app.Configure(config => + config.PropagateExceptions(); + config.AddBranch("animal", animal => { - config.PropagateExceptions(); - config.AddBranch("animal", animal => - { - animal.AddCommand("dog"); - }); + animal.AddCommand("dog"); }); + }); - // When - var result = app.Run(new[] - { - "animal", "4", "dog", "12", "--", - "--foo", "bar", "--foo", "baz", - "-bar", "\"baz\"", "qux", - "foo bar baz qux", - }); - - // Then - result.Context.Remaining.Parsed.Count.ShouldBe(4); - result.Context.ShouldHaveRemainingArgument("foo", values: new[] { "bar", "baz" }); - result.Context.ShouldHaveRemainingArgument("b", values: new[] { (string)null }); - result.Context.ShouldHaveRemainingArgument("a", values: new[] { (string)null }); - result.Context.ShouldHaveRemainingArgument("r", values: new[] { (string)null }); - } - - [Fact] - public void Should_Register_Remaining_Raw_Arguments_With_Context() + // When + var result = app.Run(new[] { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddBranch("animal", animal => - { - animal.AddCommand("dog"); - }); - }); + "animal", "4", "dog", "12", "--", + "--foo", "bar", "--foo", "baz", + "-bar", "\"baz\"", "qux", + "foo bar baz qux", + }); - // When - var result = app.Run(new[] - { - "animal", "4", "dog", "12", "--", - "--foo", "bar", "-bar", "\"baz\"", "qux", - "foo bar baz qux", - }); + // Then + result.Context.Remaining.Parsed.Count.ShouldBe(4); + result.Context.ShouldHaveRemainingArgument("foo", values: new[] { "bar", "baz" }); + result.Context.ShouldHaveRemainingArgument("b", values: new[] { (string)null }); + result.Context.ShouldHaveRemainingArgument("a", values: new[] { (string)null }); + result.Context.ShouldHaveRemainingArgument("r", values: new[] { (string)null }); + } - // Then - result.Context.Remaining.Raw.Count.ShouldBe(6); - result.Context.Remaining.Raw[0].ShouldBe("--foo"); - result.Context.Remaining.Raw[1].ShouldBe("bar"); - result.Context.Remaining.Raw[2].ShouldBe("-bar"); - result.Context.Remaining.Raw[3].ShouldBe("baz"); - result.Context.Remaining.Raw[4].ShouldBe("qux"); - result.Context.Remaining.Raw[5].ShouldBe("foo bar baz qux"); - } + [Fact] + public void Should_Register_Remaining_Raw_Arguments_With_Context() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddBranch("animal", animal => + { + animal.AddCommand("dog"); + }); + }); + + // When + var result = app.Run(new[] + { + "animal", "4", "dog", "12", "--", + "--foo", "bar", "-bar", "\"baz\"", "qux", + "foo bar baz qux", + }); + + // Then + result.Context.Remaining.Raw.Count.ShouldBe(6); + result.Context.Remaining.Raw[0].ShouldBe("--foo"); + result.Context.Remaining.Raw[1].ShouldBe("bar"); + result.Context.Remaining.Raw[2].ShouldBe("-bar"); + result.Context.Remaining.Raw[3].ShouldBe("baz"); + result.Context.Remaining.Raw[4].ShouldBe("qux"); + result.Context.Remaining.Raw[5].ShouldBe("foo bar baz qux"); } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Sensitivity.cs b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Sensitivity.cs index 91e42eb..87e3ca6 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Sensitivity.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Sensitivity.cs @@ -1,118 +1,111 @@ -using Shouldly; -using Spectre.Console.Cli; -using Spectre.Console.Testing; -using Spectre.Console.Tests.Data; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli; -namespace Spectre.Console.Tests.Unit.Cli +public sealed partial class CommandApptests { - public sealed partial class CommandApptests + [Fact] + public void Should_Treat_Commands_As_Case_Sensitive_If_Specified() { - [Fact] - public void Should_Treat_Commands_As_Case_Sensitive_If_Specified() + // Given + var app = new CommandApp(); + app.Configure(config => { - // Given - var app = new CommandApp(); - app.Configure(config => - { - config.UseStrictParsing(); - config.PropagateExceptions(); - config.CaseSensitivity(CaseSensitivity.Commands); - config.AddCommand>("command"); - }); + config.UseStrictParsing(); + config.PropagateExceptions(); + config.CaseSensitivity(CaseSensitivity.Commands); + config.AddCommand>("command"); + }); - // When - var result = Record.Exception(() => app.Run(new[] - { - "Command", "--foo", "bar", - })); - - // Then - result.ShouldNotBeNull(); - result.ShouldBeOfType().And(ex => - { - ex.Message.ShouldBe("Unknown command 'Command'."); - }); - } - - [Fact] - public void Should_Treat_Long_Options_As_Case_Sensitive_If_Specified() + // When + var result = Record.Exception(() => app.Run(new[] { - // Given - var app = new CommandApp(); - app.Configure(config => - { - config.UseStrictParsing(); - config.PropagateExceptions(); - config.CaseSensitivity(CaseSensitivity.LongOptions); - config.AddCommand>("command"); - }); + "Command", "--foo", "bar", + })); - // When - var result = Record.Exception(() => app.Run(new[] - { - "command", "--Foo", "bar", - })); - - // Then - result.ShouldNotBeNull(); - result.ShouldBeOfType().And(ex => - { - ex.Message.ShouldBe("Unknown option 'Foo'."); - }); - } - - [Fact] - public void Should_Treat_Short_Options_As_Case_Sensitive() + // Then + result.ShouldNotBeNull(); + result.ShouldBeOfType().And(ex => { - // Given - var app = new CommandApp(); - app.Configure(config => - { - config.UseStrictParsing(); - config.PropagateExceptions(); - config.AddCommand>("command"); - }); - - // When - var result = Record.Exception(() => app.Run(new[] - { - "command", "-F", "bar", - })); - - // Then - result.ShouldNotBeNull(); - result.ShouldBeOfType().And(ex => - { - ex.Message.ShouldBe("Unknown option 'F'."); - }); - } - - [Fact] - public void Should_Suppress_Case_Sensitivity_If_Specified() - { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.UseStrictParsing(); - config.PropagateExceptions(); - config.CaseSensitivity(CaseSensitivity.None); - config.AddCommand>("command"); - }); - - // When - var result = app.Run(new[] - { - "Command", "--Foo", "bar", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(vec => - { - vec.Foo.ShouldBe("bar"); - }); - } + ex.Message.ShouldBe("Unknown command 'Command'."); + }); } -} \ No newline at end of file + + [Fact] + public void Should_Treat_Long_Options_As_Case_Sensitive_If_Specified() + { + // Given + var app = new CommandApp(); + app.Configure(config => + { + config.UseStrictParsing(); + config.PropagateExceptions(); + config.CaseSensitivity(CaseSensitivity.LongOptions); + config.AddCommand>("command"); + }); + + // When + var result = Record.Exception(() => app.Run(new[] + { + "command", "--Foo", "bar", + })); + + // Then + result.ShouldNotBeNull(); + result.ShouldBeOfType().And(ex => + { + ex.Message.ShouldBe("Unknown option 'Foo'."); + }); + } + + [Fact] + public void Should_Treat_Short_Options_As_Case_Sensitive() + { + // Given + var app = new CommandApp(); + app.Configure(config => + { + config.UseStrictParsing(); + config.PropagateExceptions(); + config.AddCommand>("command"); + }); + + // When + var result = Record.Exception(() => app.Run(new[] + { + "command", "-F", "bar", + })); + + // Then + result.ShouldNotBeNull(); + result.ShouldBeOfType().And(ex => + { + ex.Message.ShouldBe("Unknown option 'F'."); + }); + } + + [Fact] + public void Should_Suppress_Case_Sensitivity_If_Specified() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.UseStrictParsing(); + config.PropagateExceptions(); + config.CaseSensitivity(CaseSensitivity.None); + config.AddCommand>("command"); + }); + + // When + var result = app.Run(new[] + { + "Command", "--Foo", "bar", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(vec => + { + vec.Foo.ShouldBe("bar"); + }); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Settings.cs b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Settings.cs index 7d07191..effeb16 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Settings.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Settings.cs @@ -1,26 +1,21 @@ -using Shouldly; -using Spectre.Console.Cli; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli; -namespace Spectre.Console.Tests.Unit.Cli +public sealed partial class CommandAppTests { - public sealed partial class CommandAppTests + [Fact] + public void Should_Apply_Case_Sensitivity_For_Everything_By_Default() { - [Fact] - public void Should_Apply_Case_Sensitivity_For_Everything_By_Default() + // Given + var app = new CommandApp(); + + // When + var defaultSensitivity = CaseSensitivity.None; + app.Configure(config => { - // Given - var app = new CommandApp(); + defaultSensitivity = config.Settings.CaseSensitivity; + }); - // When - var defaultSensitivity = CaseSensitivity.None; - app.Configure(config => - { - defaultSensitivity = config.Settings.CaseSensitivity; - }); - - // Then - defaultSensitivity.ShouldBe(CaseSensitivity.All); - } + // Then + defaultSensitivity.ShouldBe(CaseSensitivity.All); } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.TypeConverters.cs b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.TypeConverters.cs index 5e7f21d..86db2eb 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.TypeConverters.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.TypeConverters.cs @@ -1,40 +1,33 @@ -using Shouldly; -using Spectre.Console.Cli; -using Spectre.Console.Testing; -using Spectre.Console.Tests.Data; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli; -namespace Spectre.Console.Tests.Unit.Cli +public sealed partial class CommandAppTests { - public sealed partial class CommandAppTests + public sealed class TypeConverters { - public sealed class TypeConverters + [Fact] + public void Should_Bind_Using_Custom_Type_Converter_If_Specified() { - [Fact] - public void Should_Bind_Using_Custom_Type_Converter_If_Specified() + // Given + var app = new CommandAppTester(); + app.Configure(config => { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddCommand("cat"); - }); + config.PropagateExceptions(); + config.AddCommand("cat"); + }); - // When - var result = app.Run(new[] - { - "cat", "--name", "Tiger", - "--agility", "FOOBAR", - }); + // When + var result = app.Run(new[] + { + "cat", "--name", "Tiger", + "--agility", "FOOBAR", + }); - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(cat => - { - cat.Agility.ShouldBe(6); - }); - } + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(cat => + { + cat.Agility.ShouldBe(6); + }); } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Unsafe.cs b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Unsafe.cs index f96fa59..95f1886 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Unsafe.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Unsafe.cs @@ -1,299 +1,291 @@ -using Shouldly; -using Spectre.Console.Cli; -using Spectre.Console.Cli.Unsafe; -using Spectre.Console.Testing; -using Spectre.Console.Tests.Data; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli; -namespace Spectre.Console.Tests.Unit.Cli +public sealed partial class CommandAppTests { - public sealed partial class CommandAppTests + public sealed class SafetyOff { - public sealed class SafetyOff + [Fact] + public void Can_Mix_Safe_And_Unsafe_Configurators() { - [Fact] - public void Can_Mix_Safe_And_Unsafe_Configurators() + // Given + var app = new CommandAppTester(); + app.Configure(config => { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); + config.PropagateExceptions(); - config.AddBranch("animal", animal => + config.AddBranch("animal", animal => + { + animal.SafetyOff().AddBranch("mammal", typeof(MammalSettings), mammal => { - animal.SafetyOff().AddBranch("mammal", typeof(MammalSettings), mammal => - { - mammal.AddCommand("dog", typeof(DogCommand)); - mammal.AddCommand("horse", typeof(HorseCommand)); - }); + mammal.AddCommand("dog", typeof(DogCommand)); + mammal.AddCommand("horse", typeof(HorseCommand)); }); }); + }); - // When - var result = app.Run(new[] - { - "animal", "--alive", "mammal", "--name", - "Rufus", "dog", "12", "--good-boy", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(dog => - { - dog.Age.ShouldBe(12); - dog.GoodBoy.ShouldBe(true); - dog.Name.ShouldBe("Rufus"); - dog.IsAlive.ShouldBe(true); - }); - } - - [Fact] - public void Can_Turn_Safety_On_After_Turning_It_Off_For_Branch() + // When + var result = app.Run(new[] { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); + "animal", "--alive", "mammal", "--name", + "Rufus", "dog", "12", "--good-boy", + }); - config.SafetyOff().AddBranch("animal", typeof(AnimalSettings), animal => + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(dog => + { + dog.Age.ShouldBe(12); + dog.GoodBoy.ShouldBe(true); + dog.Name.ShouldBe("Rufus"); + dog.IsAlive.ShouldBe(true); + }); + } + + [Fact] + public void Can_Turn_Safety_On_After_Turning_It_Off_For_Branch() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + + config.SafetyOff().AddBranch("animal", typeof(AnimalSettings), animal => + { + animal.SafetyOn() + .AddBranch("mammal", mammal => { - animal.SafetyOn() - .AddBranch("mammal", mammal => - { - mammal.SafetyOff().AddCommand("dog", typeof(DogCommand)); - mammal.AddCommand("horse"); - }); + mammal.SafetyOff().AddCommand("dog", typeof(DogCommand)); + mammal.AddCommand("horse"); }); }); + }); - // When - var result = app.Run(new[] - { - "animal", "--alive", "mammal", "--name", - "Rufus", "dog", "12", "--good-boy", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(dog => - { - dog.Age.ShouldBe(12); - dog.GoodBoy.ShouldBe(true); - dog.Name.ShouldBe("Rufus"); - dog.IsAlive.ShouldBe(true); - }); - } - - [Fact] - public void Should_Throw_If_Trying_To_Convert_Unsafe_Branch_Configurator_To_Safe_Version_With_Wrong_Type() + // When + var result = app.Run(new[] { - // Given - var app = new CommandApp(); + "animal", "--alive", "mammal", "--name", + "Rufus", "dog", "12", "--good-boy", + }); - // When - var result = Record.Exception(() => app.Configure(config => - { - config.PropagateExceptions(); - - config.SafetyOff().AddBranch("animal", typeof(AnimalSettings), animal => - { - animal.SafetyOn().AddCommand("dog"); - }); - })); - - // Then - result.ShouldBeOfType(); - result.Message.ShouldBe("Configurator cannot be converted to a safe configurator of type 'MammalSettings'."); - } - - [Fact] - public void Should_Pass_Case_1() + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(dog => { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); + dog.Age.ShouldBe(12); + dog.GoodBoy.ShouldBe(true); + dog.Name.ShouldBe("Rufus"); + dog.IsAlive.ShouldBe(true); + }); + } - config.SafetyOff().AddBranch("animal", typeof(AnimalSettings), animal => + [Fact] + public void Should_Throw_If_Trying_To_Convert_Unsafe_Branch_Configurator_To_Safe_Version_With_Wrong_Type() + { + // Given + var app = new CommandApp(); + + // When + var result = Record.Exception(() => app.Configure(config => + { + config.PropagateExceptions(); + + config.SafetyOff().AddBranch("animal", typeof(AnimalSettings), animal => + { + animal.SafetyOn().AddCommand("dog"); + }); + })); + + // Then + result.ShouldBeOfType(); + result.Message.ShouldBe("Configurator cannot be converted to a safe configurator of type 'MammalSettings'."); + } + + [Fact] + public void Should_Pass_Case_1() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + + config.SafetyOff().AddBranch("animal", typeof(AnimalSettings), animal => + { + animal.AddBranch("mammal", typeof(MammalSettings), mammal => { - animal.AddBranch("mammal", typeof(MammalSettings), mammal => - { - mammal.AddCommand("dog", typeof(DogCommand)); - mammal.AddCommand("horse", typeof(HorseCommand)); - }); + mammal.AddCommand("dog", typeof(DogCommand)); + mammal.AddCommand("horse", typeof(HorseCommand)); }); }); + }); - // When - var result = app.Run(new[] - { - "animal", "--alive", "mammal", "--name", - "Rufus", "dog", "12", "--good-boy", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(dog => - { - dog.Age.ShouldBe(12); - dog.GoodBoy.ShouldBe(true); - dog.Name.ShouldBe("Rufus"); - dog.IsAlive.ShouldBe(true); - }); - } - - [Fact] - public void Should_Pass_Case_2() + // When + var result = app.Run(new[] { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.SafetyOff().AddCommand("dog", typeof(DogCommand)); - }); + "animal", "--alive", "mammal", "--name", + "Rufus", "dog", "12", "--good-boy", + }); - // When - var result = app.Run(new[] - { - "dog", "12", "4", "--good-boy", - "--name", "Rufus", "--alive", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(dog => - { - dog.Legs.ShouldBe(12); - dog.Age.ShouldBe(4); - dog.GoodBoy.ShouldBe(true); - dog.Name.ShouldBe("Rufus"); - dog.IsAlive.ShouldBe(true); - }); - } - - [Fact] - public void Should_Pass_Case_3() + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(dog => { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.SafetyOff().AddBranch("animal", typeof(AnimalSettings), animal => - { - animal.AddCommand("dog", typeof(DogCommand)); - animal.AddCommand("horse", typeof(HorseCommand)); - }); - }); + dog.Age.ShouldBe(12); + dog.GoodBoy.ShouldBe(true); + dog.Name.ShouldBe("Rufus"); + dog.IsAlive.ShouldBe(true); + }); + } - // When - var result = app.Run(new[] - { - "animal", "dog", "12", "--good-boy", - "--name", "Rufus", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(dog => - { - dog.Age.ShouldBe(12); - dog.GoodBoy.ShouldBe(true); - dog.Name.ShouldBe("Rufus"); - dog.IsAlive.ShouldBe(false); - }); - } - - [Fact] - public void Should_Pass_Case_4() + [Fact] + public void Should_Pass_Case_2() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.SafetyOff().AddBranch("animal", typeof(AnimalSettings), animal => - { - animal.AddCommand("dog", typeof(DogCommand)); - }); - }); + config.PropagateExceptions(); + config.SafetyOff().AddCommand("dog", typeof(DogCommand)); + }); - // When - var result = app.Run(new[] - { - "animal", "4", "dog", "12", - "--good-boy", "--name", "Rufus", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(dog => - { - dog.Legs.ShouldBe(4); - dog.Age.ShouldBe(12); - dog.GoodBoy.ShouldBe(true); - dog.IsAlive.ShouldBe(false); - dog.Name.ShouldBe("Rufus"); - }); - } - - [Fact] - public void Should_Pass_Case_5() + // When + var result = app.Run(new[] { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.SafetyOff().AddCommand("multi", typeof(OptionVectorCommand)); - }); + "dog", "12", "4", "--good-boy", + "--name", "Rufus", "--alive", + }); - // When - var result = app.Run(new[] - { - "multi", "--foo", "a", "--foo", "b", "--bar", "1", "--foo", "c", "--bar", "2", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(vec => - { - vec.Foo.Length.ShouldBe(3); - vec.Foo.ShouldBe(new[] { "a", "b", "c" }); - vec.Bar.Length.ShouldBe(2); - vec.Bar.ShouldBe(new[] { 1, 2 }); - }); - } - - [Fact] - public void Should_Pass_Case_6() + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(dog => { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddCommand>("multi"); - }); + dog.Legs.ShouldBe(12); + dog.Age.ShouldBe(4); + dog.GoodBoy.ShouldBe(true); + dog.Name.ShouldBe("Rufus"); + dog.IsAlive.ShouldBe(true); + }); + } - // When - var result = app.Run(new[] + [Fact] + public void Should_Pass_Case_3() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + config.SafetyOff().AddBranch("animal", typeof(AnimalSettings), animal => { - "multi", "a", "b", "c", + animal.AddCommand("dog", typeof(DogCommand)); + animal.AddCommand("horse", typeof(HorseCommand)); }); + }); - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(vec => + // When + var result = app.Run(new[] + { + "animal", "dog", "12", "--good-boy", + "--name", "Rufus", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(dog => + { + dog.Age.ShouldBe(12); + dog.GoodBoy.ShouldBe(true); + dog.Name.ShouldBe("Rufus"); + dog.IsAlive.ShouldBe(false); + }); + } + + [Fact] + public void Should_Pass_Case_4() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + config.SafetyOff().AddBranch("animal", typeof(AnimalSettings), animal => { - vec.Foo.Length.ShouldBe(3); - vec.Foo.ShouldBe(new[] { "a", "b", "c" }); + animal.AddCommand("dog", typeof(DogCommand)); }); - } + }); + + // When + var result = app.Run(new[] + { + "animal", "4", "dog", "12", + "--good-boy", "--name", "Rufus", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(dog => + { + dog.Legs.ShouldBe(4); + dog.Age.ShouldBe(12); + dog.GoodBoy.ShouldBe(true); + dog.IsAlive.ShouldBe(false); + dog.Name.ShouldBe("Rufus"); + }); + } + + [Fact] + public void Should_Pass_Case_5() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + config.SafetyOff().AddCommand("multi", typeof(OptionVectorCommand)); + }); + + // When + var result = app.Run(new[] + { + "multi", "--foo", "a", "--foo", "b", "--bar", "1", "--foo", "c", "--bar", "2", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(vec => + { + vec.Foo.Length.ShouldBe(3); + vec.Foo.ShouldBe(new[] { "a", "b", "c" }); + vec.Bar.Length.ShouldBe(2); + vec.Bar.ShouldBe(new[] { 1, 2 }); + }); + } + + [Fact] + public void Should_Pass_Case_6() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddCommand>("multi"); + }); + + // When + var result = app.Run(new[] + { + "multi", "a", "b", "c", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(vec => + { + vec.Foo.Length.ShouldBe(3); + vec.Foo.ShouldBe(new[] { "a", "b", "c" }); + }); } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Validation.cs b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Validation.cs index 5336ae3..f4b0b7f 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Validation.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Validation.cs @@ -1,88 +1,82 @@ -using Shouldly; -using Spectre.Console.Cli; -using Spectre.Console.Tests.Data; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli; -namespace Spectre.Console.Tests.Unit.Cli +public sealed partial class CommandAppTests { - public sealed partial class CommandAppTests + public sealed class Validation { - public sealed class Validation + [Fact] + public void Should_Throw_If_Attribute_Validation_Fails() { - [Fact] - public void Should_Throw_If_Attribute_Validation_Fails() + // Given + var app = new CommandApp(); + app.Configure(config => { - // Given - var app = new CommandApp(); - app.Configure(config => + config.PropagateExceptions(); + config.AddBranch("animal", animal => { - config.PropagateExceptions(); - config.AddBranch("animal", animal => - { - animal.AddCommand("dog"); - animal.AddCommand("horse"); - }); + animal.AddCommand("dog"); + animal.AddCommand("horse"); }); + }); - // When - var result = Record.Exception(() => app.Run(new[] { "animal", "3", "dog", "7", "--name", "Rufus" })); + // When + var result = Record.Exception(() => app.Run(new[] { "animal", "3", "dog", "7", "--name", "Rufus" })); - // Then - result.ShouldBeOfType().And(e => - { - e.Message.ShouldBe("Animals must have an even number of legs."); - }); - } - - [Fact] - public void Should_Throw_If_Settings_Validation_Fails() + // Then + result.ShouldBeOfType().And(e => { - // Given - var app = new CommandApp(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddBranch("animal", animal => - { - animal.AddCommand("dog"); - animal.AddCommand("horse"); - }); - }); + e.Message.ShouldBe("Animals must have an even number of legs."); + }); + } - // When - var result = Record.Exception(() => app.Run(new[] { "animal", "4", "dog", "7", "--name", "Tiger" })); - - // Then - result.ShouldBeOfType().And(e => - { - e.Message.ShouldBe("Tiger is not a dog name!"); - }); - } - - [Fact] - public void Should_Throw_If_Command_Validation_Fails() + [Fact] + public void Should_Throw_If_Settings_Validation_Fails() + { + // Given + var app = new CommandApp(); + app.Configure(config => { - // Given - var app = new CommandApp(); - app.Configure(config => + config.PropagateExceptions(); + config.AddBranch("animal", animal => { - config.PropagateExceptions(); - config.AddBranch("animal", animal => - { - animal.AddCommand("dog"); - animal.AddCommand("horse"); - }); + animal.AddCommand("dog"); + animal.AddCommand("horse"); }); + }); - // When - var result = Record.Exception(() => app.Run(new[] { "animal", "4", "dog", "101", "--name", "Rufus" })); + // When + var result = Record.Exception(() => app.Run(new[] { "animal", "4", "dog", "7", "--name", "Tiger" })); - // Then - result.ShouldBeOfType().And(e => + // Then + result.ShouldBeOfType().And(e => + { + e.Message.ShouldBe("Tiger is not a dog name!"); + }); + } + + [Fact] + public void Should_Throw_If_Command_Validation_Fails() + { + // Given + var app = new CommandApp(); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddBranch("animal", animal => { - e.Message.ShouldBe("Dog is too old..."); + animal.AddCommand("dog"); + animal.AddCommand("horse"); }); - } + }); + + // When + var result = Record.Exception(() => app.Run(new[] { "animal", "4", "dog", "101", "--name", "Rufus" })); + + // Then + result.ShouldBeOfType().And(e => + { + e.Message.ShouldBe("Dog is too old..."); + }); } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.ValueProviders.cs b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.ValueProviders.cs index a547343..7f29e9e 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.ValueProviders.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.ValueProviders.cs @@ -1,97 +1,88 @@ -using System.ComponentModel; -using System.Globalization; -using Shouldly; -using Spectre.Console.Cli; -using Spectre.Console.Testing; -using Spectre.Console.Tests.Data; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli; -namespace Spectre.Console.Tests.Unit.Cli +public sealed partial class CommandAppTests { - public sealed partial class CommandAppTests + public sealed class ValueProviders { - public sealed class ValueProviders + public sealed class ValueProviderSettings : CommandSettings { - public sealed class ValueProviderSettings : CommandSettings + [CommandOption("-f|--foo ")] + [IntegerValueProvider(32)] + [TypeConverter(typeof(HexConverter))] + public string Foo { get; set; } + } + + public sealed class IntegerValueProvider : ParameterValueProviderAttribute + { + private readonly int _value; + + public IntegerValueProvider(int value) { - [CommandOption("-f|--foo ")] - [IntegerValueProvider(32)] - [TypeConverter(typeof(HexConverter))] - public string Foo { get; set; } + _value = value; } - public sealed class IntegerValueProvider : ParameterValueProviderAttribute + public override bool TryGetValue(CommandParameterContext context, out object result) { - private readonly int _value; - - public IntegerValueProvider(int value) + if (context.Value == null) { - _value = value; + result = _value; + return true; } - public override bool TryGetValue(CommandParameterContext context, out object result) - { - if (context.Value == null) - { - result = _value; - return true; - } - - result = null; - return false; - } - } - - public sealed class HexConverter : TypeConverter - { - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) - { - if (value is int integer) - { - return integer.ToString("X"); - } - - return value is string stringValue && int.TryParse(stringValue, out var intValue) - ? intValue.ToString("X") - : base.ConvertFrom(context, culture, value); - } - } - - [Fact] - public void Should_Use_Provided_Value_If_No_Value_Was_Specified() - { - // Given - var app = new CommandAppTester(); - app.SetDefaultCommand>(); - app.Configure(config => config.PropagateExceptions()); - - // When - var result = app.Run(); - - // Then - result.Settings.ShouldBeOfType().And(settings => - { - settings.Foo.ShouldBe("20"); // 32 is 0x20 - }); - } - - [Fact] - public void Should_Not_Override_Value_If_Value_Was_Specified() - { - // Given - var app = new CommandAppTester(); - app.SetDefaultCommand>(); - app.Configure(config => config.PropagateExceptions()); - - // When - var result = app.Run("--foo", "12"); - - // Then - result.Settings.ShouldBeOfType().And(settings => - { - settings.Foo.ShouldBe("C"); // 12 is 0xC - }); + result = null; + return false; } } + + public sealed class HexConverter : TypeConverter + { + public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + { + if (value is int integer) + { + return integer.ToString("X"); + } + + return value is string stringValue && int.TryParse(stringValue, out var intValue) + ? intValue.ToString("X") + : base.ConvertFrom(context, culture, value); + } + } + + [Fact] + public void Should_Use_Provided_Value_If_No_Value_Was_Specified() + { + // Given + var app = new CommandAppTester(); + app.SetDefaultCommand>(); + app.Configure(config => config.PropagateExceptions()); + + // When + var result = app.Run(); + + // Then + result.Settings.ShouldBeOfType().And(settings => + { + settings.Foo.ShouldBe("20"); // 32 is 0x20 + }); + } + + [Fact] + public void Should_Not_Override_Value_If_Value_Was_Specified() + { + // Given + var app = new CommandAppTester(); + app.SetDefaultCommand>(); + app.Configure(config => config.PropagateExceptions()); + + // When + var result = app.Run("--foo", "12"); + + // Then + result.Settings.ShouldBeOfType().And(settings => + { + settings.Foo.ShouldBe("C"); // 12 is 0xC + }); + } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Vectors.cs b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Vectors.cs index 53fe1cd..f56d990 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Vectors.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Vectors.cs @@ -1,111 +1,104 @@ -using Shouldly; -using Spectre.Console.Cli; -using Spectre.Console.Testing; -using Spectre.Console.Tests.Data; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli; -namespace Spectre.Console.Tests.Unit.Cli +public sealed partial class CommandAppTests { - public sealed partial class CommandAppTests + public sealed class Vectors { - public sealed class Vectors + [Fact] + public void Should_Throw_If_A_Single_Command_Has_Multiple_Argument_Vectors() { - [Fact] - public void Should_Throw_If_A_Single_Command_Has_Multiple_Argument_Vectors() + // Given + var app = new CommandApp(); + app.Configure(config => { - // Given - var app = new CommandApp(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddCommand>("multi"); - }); + config.PropagateExceptions(); + config.AddCommand>("multi"); + }); - // When - var result = Record.Exception(() => app.Run(new[] { "multi", "a", "b", "c" })); + // When + var result = Record.Exception(() => app.Run(new[] { "multi", "a", "b", "c" })); - // Then - result.ShouldBeOfType().And(ex => - { - ex.Message.ShouldBe("The command 'multi' specifies more than one vector argument."); - }); - } - - [Fact] - public void Should_Throw_If_An_Argument_Vector_Is_Not_Specified_Last() + // Then + result.ShouldBeOfType().And(ex => { - // Given - var app = new CommandApp(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddCommand>("multi"); - }); + ex.Message.ShouldBe("The command 'multi' specifies more than one vector argument."); + }); + } - // When - var result = Record.Exception(() => app.Run(new[] { "multi", "a", "b", "c" })); - - // Then - result.ShouldBeOfType().And(ex => - { - ex.Message.ShouldBe("The command 'multi' specifies an argument vector that is not the last argument."); - }); - } - - [Fact] - public void Should_Assign_Values_To_Argument_Vector() + [Fact] + public void Should_Throw_If_An_Argument_Vector_Is_Not_Specified_Last() + { + // Given + var app = new CommandApp(); + app.Configure(config => { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddCommand>("multi"); - }); + config.PropagateExceptions(); + config.AddCommand>("multi"); + }); - // When - var result = app.Run(new[] - { - "multi", "a", "b", "c", - }); + // When + var result = Record.Exception(() => app.Run(new[] { "multi", "a", "b", "c" })); - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(vec => - { - vec.Foo.Length.ShouldBe(3); - vec.Foo[0].ShouldBe("a"); - vec.Foo[1].ShouldBe("b"); - vec.Foo[2].ShouldBe("c"); - }); - } - - [Fact] - public void Should_Assign_Values_To_Option_Vector() + // Then + result.ShouldBeOfType().And(ex => { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddCommand("cmd"); - }); + ex.Message.ShouldBe("The command 'multi' specifies an argument vector that is not the last argument."); + }); + } - // When - var result = app.Run(new[] - { - "cmd", "--foo", "red", - "--bar", "4", "--foo", "blue", - }); + [Fact] + public void Should_Assign_Values_To_Argument_Vector() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddCommand>("multi"); + }); - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(vec => - { - vec.Foo.ShouldBe(new string[] { "red", "blue" }); - vec.Bar.ShouldBe(new int[] { 4 }); - }); - } + // When + var result = app.Run(new[] + { + "multi", "a", "b", "c", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(vec => + { + vec.Foo.Length.ShouldBe(3); + vec.Foo[0].ShouldBe("a"); + vec.Foo[1].ShouldBe("b"); + vec.Foo[2].ShouldBe("c"); + }); + } + + [Fact] + public void Should_Assign_Values_To_Option_Vector() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddCommand("cmd"); + }); + + // When + var result = app.Run(new[] + { + "cmd", "--foo", "red", + "--bar", "4", "--foo", "blue", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(vec => + { + vec.Foo.ShouldBe(new string[] { "red", "blue" }); + vec.Bar.ShouldBe(new int[] { 4 }); + }); } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Version.cs b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Version.cs index 84702a0..e950814 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Version.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Version.cs @@ -1,37 +1,31 @@ -using Shouldly; -using Spectre.Console.Testing; -using Spectre.Console.Tests.Data; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli; -namespace Spectre.Console.Tests.Unit.Cli +public sealed partial class CommandAppTests { - public sealed partial class CommandAppTests + public sealed class Version { - public sealed class Version + [Fact] + public void Should_Output_The_Version_To_The_Console() { - [Fact] - public void Should_Output_The_Version_To_The_Console() + // Given + var fixture = new CommandAppTester(); + fixture.Configure(config => { - // Given - var fixture = new CommandAppTester(); - fixture.Configure(config => + config.AddBranch("animal", animal => { - config.AddBranch("animal", animal => + animal.AddBranch("mammal", mammal => { - animal.AddBranch("mammal", mammal => - { - mammal.AddCommand("dog"); - mammal.AddCommand("horse"); - }); + mammal.AddCommand("dog"); + mammal.AddCommand("horse"); }); }); + }); - // When - var result = fixture.Run(Constants.VersionCommand); + // When + var result = fixture.Run(Constants.VersionCommand); - // Then - result.Output.ShouldStartWith("Spectre.Cli version "); - } + // Then + result.Output.ShouldStartWith("Spectre.Cli version "); } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Xml.cs b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Xml.cs index 1fcd9a8..beefc46 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Xml.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.Xml.cs @@ -1,157 +1,148 @@ -using System.Threading.Tasks; -using Spectre.Console.Cli; -using Spectre.Console.Testing; -using Spectre.Console.Tests.Data; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli; -namespace Spectre.Console.Tests.Unit.Cli +public sealed partial class CommandAppTests { - public sealed partial class CommandAppTests + [UsesVerify] + [ExpectationPath("Cli/Xml")] + public sealed class Xml { - [UsesVerify] - [ExpectationPath("Cli/Xml")] - public sealed class Xml + [Fact] + [Expectation("Test_1")] + public Task Should_Dump_Correct_Model_For_Case_1() { - [Fact] - [Expectation("Test_1")] - public Task Should_Dump_Correct_Model_For_Case_1() + // Given + var fixture = new CommandAppTester(); + fixture.Configure(config => { - // Given - var fixture = new CommandAppTester(); - fixture.Configure(config => + config.PropagateExceptions(); + config.AddBranch("animal", animal => { - config.PropagateExceptions(); - config.AddBranch("animal", animal => + animal.AddBranch("mammal", mammal => { - animal.AddBranch("mammal", mammal => - { - mammal.AddCommand("dog"); - mammal.AddCommand("horse"); - }); + mammal.AddCommand("dog"); + mammal.AddCommand("horse"); }); }); + }); - // When - var result = fixture.Run(Constants.XmlDocCommand); + // When + var result = fixture.Run(Constants.XmlDocCommand); - // Then - return Verifier.Verify(result.Output); - } + // Then + return Verifier.Verify(result.Output); + } - [Fact] - [Expectation("Test_2")] - public Task Should_Dump_Correct_Model_For_Case_2() + [Fact] + [Expectation("Test_2")] + public Task Should_Dump_Correct_Model_For_Case_2() + { + // Given + var fixture = new CommandAppTester(); + fixture.Configure(config => { - // Given - var fixture = new CommandAppTester(); - fixture.Configure(config => + config.AddCommand("dog"); + }); + + // When + var result = fixture.Run(Constants.XmlDocCommand); + + // Then + return Verifier.Verify(result.Output); + } + + [Fact] + [Expectation("Test_3")] + public Task Should_Dump_Correct_Model_For_Case_3() + { + // Given + var fixture = new CommandAppTester(); + fixture.Configure(config => + { + config.AddBranch("animal", animal => { - config.AddCommand("dog"); + animal.AddCommand("dog"); + animal.AddCommand("horse"); }); + }); - // When - var result = fixture.Run(Constants.XmlDocCommand); + // When + var result = fixture.Run(Constants.XmlDocCommand); - // Then - return Verifier.Verify(result.Output); - } + // Then + return Verifier.Verify(result.Output); + } - [Fact] - [Expectation("Test_3")] - public Task Should_Dump_Correct_Model_For_Case_3() + [Fact] + [Expectation("Test_4")] + public Task Should_Dump_Correct_Model_For_Case_4() + { + // Given + var fixture = new CommandAppTester(); + fixture.Configure(config => { - // Given - var fixture = new CommandAppTester(); - fixture.Configure(config => + config.AddBranch("animal", animal => { - config.AddBranch("animal", animal => - { - animal.AddCommand("dog"); - animal.AddCommand("horse"); - }); + animal.AddCommand("dog"); }); + }); - // When - var result = fixture.Run(Constants.XmlDocCommand); + // When + var result = fixture.Run(Constants.XmlDocCommand); - // Then - return Verifier.Verify(result.Output); - } + // Then + return Verifier.Verify(result.Output); + } - [Fact] - [Expectation("Test_4")] - public Task Should_Dump_Correct_Model_For_Case_4() + [Fact] + [Expectation("Test_5")] + public Task Should_Dump_Correct_Model_For_Case_5() + { + // Given + var fixture = new CommandAppTester(); + fixture.Configure(config => { - // Given - var fixture = new CommandAppTester(); - fixture.Configure(config => - { - config.AddBranch("animal", animal => - { - animal.AddCommand("dog"); - }); - }); + config.AddCommand("cmd"); + }); - // When - var result = fixture.Run(Constants.XmlDocCommand); + // When + var result = fixture.Run(Constants.XmlDocCommand); - // Then - return Verifier.Verify(result.Output); - } + // Then + return Verifier.Verify(result.Output); + } - [Fact] - [Expectation("Test_5")] - public Task Should_Dump_Correct_Model_For_Case_5() + [Fact] + [Expectation("Test_6")] + public Task Should_Dump_Correct_Model_For_Model_With_Default_Command() + { + // Given + var fixture = new CommandAppTester(); + fixture.SetDefaultCommand(); + fixture.Configure(config => { - // Given - var fixture = new CommandAppTester(); - fixture.Configure(config => - { - config.AddCommand("cmd"); - }); + config.AddCommand("horse"); + }); - // When - var result = fixture.Run(Constants.XmlDocCommand); + // When + var result = fixture.Run(Constants.XmlDocCommand); - // Then - return Verifier.Verify(result.Output); - } + // Then + return Verifier.Verify(result.Output); + } - [Fact] - [Expectation("Test_6")] - public Task Should_Dump_Correct_Model_For_Model_With_Default_Command() - { - // Given - var fixture = new CommandAppTester(); - fixture.SetDefaultCommand(); - fixture.Configure(config => - { - config.AddCommand("horse"); - }); + [Fact] + [Expectation("Hidden_Command_Options")] + public Task Should_Not_Dump_Hidden_Options_On_A_Command() + { + // Given + var fixture = new CommandAppTester(); + fixture.SetDefaultCommand(); - // When - var result = fixture.Run(Constants.XmlDocCommand); + // When + var result = fixture.Run(Constants.XmlDocCommand); - // Then - return Verifier.Verify(result.Output); - } - - [Fact] - [Expectation("Hidden_Command_Options")] - public Task Should_Not_Dump_Hidden_Options_On_A_Command() - { - // Given - var fixture = new CommandAppTester(); - fixture.SetDefaultCommand(); - - // When - var result = fixture.Run(Constants.XmlDocCommand); - - // Then - return Verifier.Verify(result.Output); - } + // Then + return Verifier.Verify(result.Output); } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.cs b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.cs index 428e3eb..8175ace 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/CommandAppTests.cs @@ -1,820 +1,812 @@ -using System; -using Shouldly; -using Spectre.Console.Cli; -using Spectre.Console.Testing; -using Spectre.Console.Tests.Data; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli; -namespace Spectre.Console.Tests.Unit.Cli +public sealed partial class CommandAppTests { - public sealed partial class CommandAppTests + [Fact] + public void Should_Pass_Case_1() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddBranch("animal", animal => + { + animal.AddBranch("mammal", mammal => + { + mammal.AddCommand("dog"); + mammal.AddCommand("horse"); + }); + }); + }); + + // When + var result = app.Run(new[] + { + "animal", "--alive", "mammal", "--name", + "Rufus", "dog", "12", "--good-boy", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(dog => + { + dog.Age.ShouldBe(12); + dog.GoodBoy.ShouldBe(true); + dog.Name.ShouldBe("Rufus"); + dog.IsAlive.ShouldBe(true); + }); + } + + [Fact] + public void Should_Pass_Case_2() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddCommand("dog"); + }); + + // When + var result = app.Run(new[] + { + "dog", "12", "4", "--good-boy", + "--name", "Rufus", "--alive", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(dog => + { + dog.Legs.ShouldBe(12); + dog.Age.ShouldBe(4); + dog.GoodBoy.ShouldBe(true); + dog.Name.ShouldBe("Rufus"); + dog.IsAlive.ShouldBe(true); + }); + } + + [Fact] + public void Should_Pass_Case_3() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddBranch("animal", animal => + { + animal.AddCommand("dog"); + animal.AddCommand("horse"); + }); + }); + + // When + var result = app.Run(new[] + { + "animal", "dog", "12", "--good-boy", + "--name", "Rufus", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(dog => + { + dog.Age.ShouldBe(12); + dog.GoodBoy.ShouldBe(true); + dog.Name.ShouldBe("Rufus"); + dog.IsAlive.ShouldBe(false); + }); + } + + [Fact] + public void Should_Pass_Case_4() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddBranch("animal", animal => + { + animal.AddCommand("dog"); + }); + }); + + // When + var result = app.Run(new[] + { + "animal", "4", "dog", "12", "--good-boy", + "--name", "Rufus", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(dog => + { + dog.Legs.ShouldBe(4); + dog.Age.ShouldBe(12); + dog.GoodBoy.ShouldBe(true); + dog.IsAlive.ShouldBe(false); + dog.Name.ShouldBe("Rufus"); + }); + } + + [Fact] + public void Should_Pass_Case_5() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddCommand("multi"); + }); + + // When + var result = app.Run(new[] + { + "multi", "--foo", "a", "--foo", "b", + "--bar", "1", "--foo", "c", "--bar", "2", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(vec => + { + vec.Foo.Length.ShouldBe(3); + vec.Foo.ShouldBe(new[] { "a", "b", "c" }); + vec.Bar.Length.ShouldBe(2); + vec.Bar.ShouldBe(new[] { 1, 2 }); + }); + } + + [Fact] + public void Should_Pass_Case_6() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddCommand>("multi"); + }); + + // When + var result = app.Run(new[] + { + "multi", "a", "b", "c", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(vec => + { + vec.Foo.Length.ShouldBe(3); + vec.Foo.ShouldBe(new[] { "a", "b", "c" }); + }); + } + + [Fact] + public void Should_Be_Able_To_Use_Command_Alias() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddCommand("multi").WithAlias("multiple"); + }); + + // When + var result = app.Run(new[] + { + "multiple", "--foo", "a", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(vec => + { + vec.Foo.Length.ShouldBe(1); + vec.Foo.ShouldBe(new[] { "a" }); + }); + } + + [Fact] + public void Should_Assign_Default_Value_To_Optional_Argument() + { + // Given + var app = new CommandAppTester(); + app.SetDefaultCommand>(); + app.Configure(config => + { + config.PropagateExceptions(); + }); + + // When + var result = app.Run(Array.Empty()); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(settings => + { + settings.Greeting.ShouldBe("Hello World"); + }); + } + + [Fact] + public void Should_Assign_Property_Initializer_To_Optional_Argument() + { + // Given + var app = new CommandAppTester(); + app.SetDefaultCommand>(); + app.Configure(config => + { + config.PropagateExceptions(); + }); + + // When + var result = app.Run(Array.Empty()); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings + .ShouldBeOfType() + .And(settings => settings.Count.ShouldBe(1)) + .And(settings => settings.Value.ShouldBe(0)) + .And(settings => settings.Names.ShouldNotBeNull()) + .And(settings => settings.Names.ShouldNotBeNull()) + .And(settings => settings.Names.ShouldBeEmpty()); + } + + [Fact] + public void Should_Overwrite_Property_Initializer_With_Argument_Value() + { + // Given + var app = new CommandAppTester(); + app.SetDefaultCommand>(); + app.Configure(config => + { + config.PropagateExceptions(); + }); + + // When + var result = app.Run("-c", "0", "-v", "50", "ABBA", "Herreys"); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings + .ShouldBeOfType() + .And(settings => settings.Count.ShouldBe(0)) + .And(settings => settings.Value.ShouldBe(50)) + .And(settings => settings.Names.ShouldContain("ABBA")) + .And(settings => settings.Names.ShouldContain("Herreys")); + } + + [Fact] + public void Should_Assign_Default_Value_To_Optional_Argument_Using_Converter_If_Necessary() + { + // Given + var app = new CommandAppTester(); + app.SetDefaultCommand>(); + app.Configure(config => + { + config.PropagateExceptions(); + }); + + // When + var result = app.Run(Array.Empty()); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(settings => + { + settings.Greeting.ShouldBe(5); + }); + } + + [Fact] + public void Should_Throw_If_Required_Argument_Have_Default_Value() + { + // Given + var app = new CommandAppTester(); + app.SetDefaultCommand>(); + app.Configure(config => + { + config.PropagateExceptions(); + }); + + // When + var result = Record.Exception(() => app.Run(Array.Empty())); + + // Then + result.ShouldBeOfType().And(ex => + { + ex.Message.ShouldBe("The required argument 'GREETING' cannot have a default value."); + }); + } + + [Fact] + public void Should_Throw_If_Alias_Conflicts_With_Another_Command() + { + // Given + var app = new CommandApp(); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddCommand("dog").WithAlias("cat"); + config.AddCommand("cat"); + }); + + // When + var result = Record.Exception(() => app.Run(new[] { "dog", "4", "12" })); + + // Then + result.ShouldBeOfType().And(ex => + { + ex.Message.ShouldBe("The alias 'cat' for 'dog' conflicts with another command."); + }); + } + + [Fact] + public void Should_Register_Commands_When_Configuring_Application() + { + // Given + var registrar = new FakeTypeRegistrar(); + var app = new CommandApp(registrar); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddCommand>("foo"); + config.AddBranch("animal", animal => + { + animal.AddCommand("dog"); + animal.AddCommand("horse"); + }); + }); + + // When + app.Run(new[] + { + "animal", "4", "dog", "12", + }); + + // Then + registrar.Registrations.ContainsKey(typeof(GenericCommand)).ShouldBeTrue(); + registrar.Registrations.ContainsKey(typeof(DogCommand)).ShouldBeTrue(); + registrar.Registrations.ContainsKey(typeof(HorseCommand)).ShouldBeTrue(); + registrar.Registrations[typeof(GenericCommand)].ShouldContain(typeof(GenericCommand)); + registrar.Registrations[typeof(DogCommand)].ShouldContain(typeof(DogCommand)); + registrar.Registrations[typeof(HorseCommand)].ShouldContain(typeof(HorseCommand)); + } + + [Fact] + public void Should_Register_Default_Command_When_Configuring_Application() + { + // Given + var registrar = new FakeTypeRegistrar(); + var app = new CommandApp(registrar); + app.Configure(config => + { + config.PropagateExceptions(); + }); + + // When + app.Run(new[] + { + "12", "4", + }); + + // Then + registrar.Registrations.ContainsKey(typeof(DogCommand)).ShouldBeTrue(); + registrar.Registrations[typeof(DogCommand)].ShouldContain(typeof(DogCommand)); + } + + [Fact] + public void Can_Register_Default_Command_Settings_When_Configuring_Application() + { + // Given + var registrar = new FakeTypeRegistrar(); + registrar.Register(typeof(DogSettings), typeof(DogSettings)); + var app = new CommandApp(registrar); + app.Configure(config => + { + config.PropagateExceptions(); + }); + + // When + app.Run(new[] + { + "12", "4", + }); + + // Then + registrar.Registrations.ContainsKey(typeof(DogSettings)).ShouldBeTrue(); + registrar.Registrations[typeof(DogSettings)].Count.ShouldBe(1); + registrar.Registrations[typeof(DogSettings)].ShouldContain(typeof(DogSettings)); + } + + [Fact] + public void Can_Register_Command_Settings_When_Configuring_Application() + { + // Given + var registrar = new FakeTypeRegistrar(); + registrar.Register(typeof(DogSettings), typeof(DogSettings)); + registrar.Register(typeof(MammalSettings), typeof(MammalSettings)); + var app = new CommandApp(registrar); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddBranch("animal", animal => + { + animal.AddCommand("dog"); + animal.AddCommand("horse"); + }); + }); + + // When + app.Run(new[] + { + "animal", "4", "dog", "12", + }); + + // Then + registrar.Registrations.ContainsKey(typeof(DogSettings)).ShouldBeTrue(); + registrar.Registrations[typeof(DogSettings)].Count.ShouldBe(1); + registrar.Registrations[typeof(DogSettings)].ShouldContain(typeof(DogSettings)); + registrar.Registrations.ContainsKey(typeof(MammalSettings)).ShouldBeTrue(); + registrar.Registrations[typeof(MammalSettings)].Count.ShouldBe(1); + registrar.Registrations[typeof(MammalSettings)].ShouldContain(typeof(MammalSettings)); + } + + [Theory] + [InlineData("true", true)] + [InlineData("True", true)] + [InlineData("false", false)] + [InlineData("False", false)] + public void Should_Accept_Explicit_Boolan_Flag(string value, bool expected) + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddCommand("dog"); + }); + + // When + var result = app.Run(new[] + { + "dog", "12", "4", "--alive", value, + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(dog => + { + dog.IsAlive.ShouldBe(expected); + }); + } + + [Fact] + public void Should_Throw_When_Encountering_Unknown_Option_In_Strict_Mode() + { + // Given + var app = new CommandApp(); + app.Configure(config => + { + config.PropagateExceptions(); + config.UseStrictParsing(); + config.AddCommand("dog"); + }); + + // When + var result = Record.Exception(() => app.Run(new[] { "dog", "--foo" })); + + // Then + result.ShouldBeOfType().And(ex => + { + ex.Message.ShouldBe("Unknown option 'foo'."); + }); + } + + [Fact] + public void Should_Add_Unknown_Option_To_Remaining_Arguments_In_Relaxed_Mode() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddBranch("animal", animal => + { + animal.AddCommand("dog"); + }); + }); + + // When + var result = app.Run(new[] + { + "animal", "4", "dog", "12", + "--foo", "bar", + }); + + // Then + result.Context.ShouldNotBeNull(); + result.Context.Remaining.Parsed.Count.ShouldBe(1); + result.Context.ShouldHaveRemainingArgument("foo", values: new[] { "bar" }); + } + + [Fact] + public void Should_Add_Unknown_Option_To_Remaining_Arguments_In_Strict_Mode() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.UseStrictParsing(); + config.PropagateExceptions(); + config.AddBranch("animal", animal => + { + animal.AddCommand("dog"); + }); + }); + + // When + var result = app.Run(new[] + { + "animal", "4", "dog", "12", + "--", + "--foo", "bar", + "-f", "baz", + "qux", + }); + + // Then + result.Context.ShouldNotBeNull(); + result.Context.Remaining.Parsed.Count.ShouldBe(2); + result.Context.ShouldHaveRemainingArgument("foo", values: new[] { "bar" }); + result.Context.ShouldHaveRemainingArgument("f", values: new[] { "baz" }); + result.Context.Remaining.Raw.Count.ShouldBe(5); + result.Context.Remaining.Raw.ShouldBe(new[] + { + "--foo", "bar", + "-f", "baz", + "qux", + }); + } + + [Fact] + public void Should_Add_Unknown_Boolean_Option_To_Remaining_Arguments_In_Relaxed_Mode() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddBranch("animal", animal => + { + animal.AddCommand("dog"); + }); + }); + + // When + var result = app.Run(new[] + { + "animal", "4", "dog", "12", "--foo", + }); + + // Then + result.Context.ShouldNotBeNull(); + result.Context.Remaining.Parsed.Count.ShouldBe(1); + result.Context.ShouldHaveRemainingArgument("foo", values: new[] { (string)null }); + } + + [Fact] + public void Should_Be_Able_To_Set_The_Default_Command() + { + // Given + var app = new CommandAppTester(); + app.SetDefaultCommand(); + + // When + var result = app.Run(new[] + { + "4", "12", "--good-boy", "--name", "Rufus", + }); + + // Then + result.ExitCode.ShouldBe(0); + result.Settings.ShouldBeOfType().And(dog => + { + dog.Legs.ShouldBe(4); + dog.Age.ShouldBe(12); + dog.GoodBoy.ShouldBe(true); + dog.Name.ShouldBe("Rufus"); + }); + } + + [Fact] + public void Should_Set_Command_Name_In_Context() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddBranch("animal", animal => + { + animal.AddCommand("dog"); + }); + }); + + // When + var result = app.Run(new[] + { + "animal", "4", "dog", "12", + }); + + // Then + result.Context.ShouldNotBeNull(); + result.Context.Name.ShouldBe("dog"); + } + + [Fact] + public void Should_Pass_Command_Data_In_Context() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddBranch("animal", animal => + { + animal.AddCommand("dog").WithData(123); + }); + }); + + // When + var result = app.Run(new[] + { + "animal", "4", "dog", "12", + }); + + // Then + result.Context.ShouldNotBeNull(); + result.Context.Data.ShouldBe(123); + } + + public sealed class Delegate_Commands { [Fact] - public void Should_Pass_Case_1() + public void Should_Execute_Delegate_Command_At_Root_Level() { // Given - var app = new CommandAppTester(); + var dog = default(DogSettings); + var data = 0; + + var app = new CommandApp(); app.Configure(config => { config.PropagateExceptions(); - config.AddBranch("animal", animal => - { - animal.AddBranch("mammal", mammal => + config.AddDelegate( + "foo", (context, settings) => { - mammal.AddCommand("dog"); - mammal.AddCommand("horse"); - }); - }); + dog = settings; + data = (int)context.Data; + return 1; + }).WithData(2); }); // When - var result = app.Run(new[] - { - "animal", "--alive", "mammal", "--name", - "Rufus", "dog", "12", "--good-boy", - }); + var result = app.Run(new[] { "foo", "4", "12" }); // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(dog => - { - dog.Age.ShouldBe(12); - dog.GoodBoy.ShouldBe(true); - dog.Name.ShouldBe("Rufus"); - dog.IsAlive.ShouldBe(true); - }); + result.ShouldBe(1); + dog.ShouldNotBeNull(); + dog.Age.ShouldBe(12); + dog.Legs.ShouldBe(4); + data.ShouldBe(2); } [Fact] - public void Should_Pass_Case_2() + public void Should_Execute_Nested_Delegate_Command() { // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddCommand("dog"); - }); + var dog = default(DogSettings); + var data = 0; - // When - var result = app.Run(new[] - { - "dog", "12", "4", "--good-boy", - "--name", "Rufus", "--alive", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(dog => - { - dog.Legs.ShouldBe(12); - dog.Age.ShouldBe(4); - dog.GoodBoy.ShouldBe(true); - dog.Name.ShouldBe("Rufus"); - dog.IsAlive.ShouldBe(true); - }); - } - - [Fact] - public void Should_Pass_Case_3() - { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddBranch("animal", animal => - { - animal.AddCommand("dog"); - animal.AddCommand("horse"); - }); - }); - - // When - var result = app.Run(new[] - { - "animal", "dog", "12", "--good-boy", - "--name", "Rufus", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(dog => - { - dog.Age.ShouldBe(12); - dog.GoodBoy.ShouldBe(true); - dog.Name.ShouldBe("Rufus"); - dog.IsAlive.ShouldBe(false); - }); - } - - [Fact] - public void Should_Pass_Case_4() - { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddBranch("animal", animal => - { - animal.AddCommand("dog"); - }); - }); - - // When - var result = app.Run(new[] - { - "animal", "4", "dog", "12", "--good-boy", - "--name", "Rufus", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(dog => - { - dog.Legs.ShouldBe(4); - dog.Age.ShouldBe(12); - dog.GoodBoy.ShouldBe(true); - dog.IsAlive.ShouldBe(false); - dog.Name.ShouldBe("Rufus"); - }); - } - - [Fact] - public void Should_Pass_Case_5() - { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddCommand("multi"); - }); - - // When - var result = app.Run(new[] - { - "multi", "--foo", "a", "--foo", "b", - "--bar", "1", "--foo", "c", "--bar", "2", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(vec => - { - vec.Foo.Length.ShouldBe(3); - vec.Foo.ShouldBe(new[] { "a", "b", "c" }); - vec.Bar.Length.ShouldBe(2); - vec.Bar.ShouldBe(new[] { 1, 2 }); - }); - } - - [Fact] - public void Should_Pass_Case_6() - { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddCommand>("multi"); - }); - - // When - var result = app.Run(new[] - { - "multi", "a", "b", "c", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(vec => - { - vec.Foo.Length.ShouldBe(3); - vec.Foo.ShouldBe(new[] { "a", "b", "c" }); - }); - } - - [Fact] - public void Should_Be_Able_To_Use_Command_Alias() - { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddCommand("multi").WithAlias("multiple"); - }); - - // When - var result = app.Run(new[] - { - "multiple", "--foo", "a", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(vec => - { - vec.Foo.Length.ShouldBe(1); - vec.Foo.ShouldBe(new[] { "a" }); - }); - } - - [Fact] - public void Should_Assign_Default_Value_To_Optional_Argument() - { - // Given - var app = new CommandAppTester(); - app.SetDefaultCommand>(); - app.Configure(config => - { - config.PropagateExceptions(); - }); - - // When - var result = app.Run(Array.Empty()); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(settings => - { - settings.Greeting.ShouldBe("Hello World"); - }); - } - - [Fact] - public void Should_Assign_Property_Initializer_To_Optional_Argument() - { - // Given - var app = new CommandAppTester(); - app.SetDefaultCommand>(); - app.Configure(config => - { - config.PropagateExceptions(); - }); - - // When - var result = app.Run(Array.Empty()); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings - .ShouldBeOfType() - .And(settings => settings.Count.ShouldBe(1)) - .And(settings => settings.Value.ShouldBe(0)) - .And(settings => settings.Names.ShouldNotBeNull()) - .And(settings => settings.Names.ShouldNotBeNull()) - .And(settings => settings.Names.ShouldBeEmpty()); - } - - [Fact] - public void Should_Overwrite_Property_Initializer_With_Argument_Value() - { - // Given - var app = new CommandAppTester(); - app.SetDefaultCommand>(); - app.Configure(config => - { - config.PropagateExceptions(); - }); - - // When - var result = app.Run("-c", "0", "-v", "50", "ABBA", "Herreys"); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings - .ShouldBeOfType() - .And(settings => settings.Count.ShouldBe(0)) - .And(settings => settings.Value.ShouldBe(50)) - .And(settings => settings.Names.ShouldContain("ABBA")) - .And(settings => settings.Names.ShouldContain("Herreys")); - } - - [Fact] - public void Should_Assign_Default_Value_To_Optional_Argument_Using_Converter_If_Necessary() - { - // Given - var app = new CommandAppTester(); - app.SetDefaultCommand>(); - app.Configure(config => - { - config.PropagateExceptions(); - }); - - // When - var result = app.Run(Array.Empty()); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(settings => - { - settings.Greeting.ShouldBe(5); - }); - } - - [Fact] - public void Should_Throw_If_Required_Argument_Have_Default_Value() - { - // Given - var app = new CommandAppTester(); - app.SetDefaultCommand>(); - app.Configure(config => - { - config.PropagateExceptions(); - }); - - // When - var result = Record.Exception(() => app.Run(Array.Empty())); - - // Then - result.ShouldBeOfType().And(ex => - { - ex.Message.ShouldBe("The required argument 'GREETING' cannot have a default value."); - }); - } - - [Fact] - public void Should_Throw_If_Alias_Conflicts_With_Another_Command() - { - // Given var app = new CommandApp(); app.Configure(config => { config.PropagateExceptions(); - config.AddCommand("dog").WithAlias("cat"); - config.AddCommand("cat"); - }); - - // When - var result = Record.Exception(() => app.Run(new[] { "dog", "4", "12" })); - - // Then - result.ShouldBeOfType().And(ex => - { - ex.Message.ShouldBe("The alias 'cat' for 'dog' conflicts with another command."); - }); - } - - [Fact] - public void Should_Register_Commands_When_Configuring_Application() - { - // Given - var registrar = new FakeTypeRegistrar(); - var app = new CommandApp(registrar); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddCommand>("foo"); - config.AddBranch("animal", animal => + config.AddBranch("foo", foo => { - animal.AddCommand("dog"); - animal.AddCommand("horse"); - }); - }); - - // When - app.Run(new[] - { - "animal", "4", "dog", "12", - }); - - // Then - registrar.Registrations.ContainsKey(typeof(GenericCommand)).ShouldBeTrue(); - registrar.Registrations.ContainsKey(typeof(DogCommand)).ShouldBeTrue(); - registrar.Registrations.ContainsKey(typeof(HorseCommand)).ShouldBeTrue(); - registrar.Registrations[typeof(GenericCommand)].ShouldContain(typeof(GenericCommand)); - registrar.Registrations[typeof(DogCommand)].ShouldContain(typeof(DogCommand)); - registrar.Registrations[typeof(HorseCommand)].ShouldContain(typeof(HorseCommand)); - } - - [Fact] - public void Should_Register_Default_Command_When_Configuring_Application() - { - // Given - var registrar = new FakeTypeRegistrar(); - var app = new CommandApp(registrar); - app.Configure(config => - { - config.PropagateExceptions(); - }); - - // When - app.Run(new[] - { - "12", "4", - }); - - // Then - registrar.Registrations.ContainsKey(typeof(DogCommand)).ShouldBeTrue(); - registrar.Registrations[typeof(DogCommand)].ShouldContain(typeof(DogCommand)); - } - - [Fact] - public void Can_Register_Default_Command_Settings_When_Configuring_Application() - { - // Given - var registrar = new FakeTypeRegistrar(); - registrar.Register(typeof(DogSettings), typeof(DogSettings)); - var app = new CommandApp(registrar); - app.Configure(config => - { - config.PropagateExceptions(); - }); - - // When - app.Run(new[] - { - "12", "4", - }); - - // Then - registrar.Registrations.ContainsKey(typeof(DogSettings)).ShouldBeTrue(); - registrar.Registrations[typeof(DogSettings)].Count.ShouldBe(1); - registrar.Registrations[typeof(DogSettings)].ShouldContain(typeof(DogSettings)); - } - - [Fact] - public void Can_Register_Command_Settings_When_Configuring_Application() - { - // Given - var registrar = new FakeTypeRegistrar(); - registrar.Register(typeof(DogSettings), typeof(DogSettings)); - registrar.Register(typeof(MammalSettings), typeof(MammalSettings)); - var app = new CommandApp(registrar); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddBranch("animal", animal => - { - animal.AddCommand("dog"); - animal.AddCommand("horse"); - }); - }); - - // When - app.Run(new[] - { - "animal", "4", "dog", "12", - }); - - // Then - registrar.Registrations.ContainsKey(typeof(DogSettings)).ShouldBeTrue(); - registrar.Registrations[typeof(DogSettings)].Count.ShouldBe(1); - registrar.Registrations[typeof(DogSettings)].ShouldContain(typeof(DogSettings)); - registrar.Registrations.ContainsKey(typeof(MammalSettings)).ShouldBeTrue(); - registrar.Registrations[typeof(MammalSettings)].Count.ShouldBe(1); - registrar.Registrations[typeof(MammalSettings)].ShouldContain(typeof(MammalSettings)); - } - - [Theory] - [InlineData("true", true)] - [InlineData("True", true)] - [InlineData("false", false)] - [InlineData("False", false)] - public void Should_Accept_Explicit_Boolan_Flag(string value, bool expected) - { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddCommand("dog"); - }); - - // When - var result = app.Run(new[] - { - "dog", "12", "4", "--alive", value, - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(dog => - { - dog.IsAlive.ShouldBe(expected); - }); - } - - [Fact] - public void Should_Throw_When_Encountering_Unknown_Option_In_Strict_Mode() - { - // Given - var app = new CommandApp(); - app.Configure(config => - { - config.PropagateExceptions(); - config.UseStrictParsing(); - config.AddCommand("dog"); - }); - - // When - var result = Record.Exception(() => app.Run(new[] { "dog", "--foo" })); - - // Then - result.ShouldBeOfType().And(ex => - { - ex.Message.ShouldBe("Unknown option 'foo'."); - }); - } - - [Fact] - public void Should_Add_Unknown_Option_To_Remaining_Arguments_In_Relaxed_Mode() - { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddBranch("animal", animal => - { - animal.AddCommand("dog"); - }); - }); - - // When - var result = app.Run(new[] - { - "animal", "4", "dog", "12", - "--foo", "bar", - }); - - // Then - result.Context.ShouldNotBeNull(); - result.Context.Remaining.Parsed.Count.ShouldBe(1); - result.Context.ShouldHaveRemainingArgument("foo", values: new[] { "bar" }); - } - - [Fact] - public void Should_Add_Unknown_Option_To_Remaining_Arguments_In_Strict_Mode() - { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.UseStrictParsing(); - config.PropagateExceptions(); - config.AddBranch("animal", animal => - { - animal.AddCommand("dog"); - }); - }); - - // When - var result = app.Run(new[] - { - "animal", "4", "dog", "12", - "--", - "--foo", "bar", - "-f", "baz", - "qux" - }); - - // Then - result.Context.ShouldNotBeNull(); - result.Context.Remaining.Parsed.Count.ShouldBe(2); - result.Context.ShouldHaveRemainingArgument("foo", values: new[] { "bar" }); - result.Context.ShouldHaveRemainingArgument("f", values: new[] { "baz" }); - result.Context.Remaining.Raw.Count.ShouldBe(5); - result.Context.Remaining.Raw.ShouldBe(new[] - { - "--foo", "bar", - "-f", "baz", - "qux", - }); - } - - [Fact] - public void Should_Add_Unknown_Boolean_Option_To_Remaining_Arguments_In_Relaxed_Mode() - { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddBranch("animal", animal => - { - animal.AddCommand("dog"); - }); - }); - - // When - var result = app.Run(new[] - { - "animal", "4", "dog", "12", "--foo", - }); - - // Then - result.Context.ShouldNotBeNull(); - result.Context.Remaining.Parsed.Count.ShouldBe(1); - result.Context.ShouldHaveRemainingArgument("foo", values: new[] { (string)null }); - } - - [Fact] - public void Should_Be_Able_To_Set_The_Default_Command() - { - // Given - var app = new CommandAppTester(); - app.SetDefaultCommand(); - - // When - var result = app.Run(new[] - { - "4", "12", "--good-boy", "--name", "Rufus", - }); - - // Then - result.ExitCode.ShouldBe(0); - result.Settings.ShouldBeOfType().And(dog => - { - dog.Legs.ShouldBe(4); - dog.Age.ShouldBe(12); - dog.GoodBoy.ShouldBe(true); - dog.Name.ShouldBe("Rufus"); - }); - } - - [Fact] - public void Should_Set_Command_Name_In_Context() - { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddBranch("animal", animal => - { - animal.AddCommand("dog"); - }); - }); - - // When - var result = app.Run(new[] - { - "animal", "4", "dog", "12", - }); - - // Then - result.Context.ShouldNotBeNull(); - result.Context.Name.ShouldBe("dog"); - } - - [Fact] - public void Should_Pass_Command_Data_In_Context() - { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddBranch("animal", animal => - { - animal.AddCommand("dog").WithData(123); - }); - }); - - // When - var result = app.Run(new[] - { - "animal", "4", "dog", "12", - }); - - // Then - result.Context.ShouldNotBeNull(); - result.Context.Data.ShouldBe(123); - } - - public sealed class Delegate_Commands - { - [Fact] - public void Should_Execute_Delegate_Command_At_Root_Level() - { - // Given - var dog = default(DogSettings); - var data = 0; - - var app = new CommandApp(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddDelegate( - "foo", (context, settings) => + foo.AddDelegate( + "bar", (context, settings) => { dog = settings; data = (int)context.Data; return 1; }).WithData(2); }); + }); - // When - var result = app.Run(new[] { "foo", "4", "12" }); + // When + var result = app.Run(new[] { "foo", "4", "bar", "12" }); - // Then - result.ShouldBe(1); - dog.ShouldNotBeNull(); - dog.Age.ShouldBe(12); - dog.Legs.ShouldBe(4); - data.ShouldBe(2); - } - - [Fact] - public void Should_Execute_Nested_Delegate_Command() - { - // Given - var dog = default(DogSettings); - var data = 0; - - var app = new CommandApp(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddBranch("foo", foo => - { - foo.AddDelegate( - "bar", (context, settings) => - { - dog = settings; - data = (int)context.Data; - return 1; - }).WithData(2); - }); - }); - - // When - var result = app.Run(new[] { "foo", "4", "bar", "12" }); - - // Then - result.ShouldBe(1); - dog.ShouldNotBeNull(); - dog.Age.ShouldBe(12); - dog.Legs.ShouldBe(4); - data.ShouldBe(2); - } - } - - public sealed class Remaining_Arguments - { - [Fact] - public void Should_Register_Remaining_Parsed_Arguments_With_Context() - { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddBranch("animal", animal => - { - animal.AddCommand("dog"); - }); - }); - - // When - var result = app.Run(new[] - { - "animal", "4", "dog", "12", "--", - "--foo", "bar", "--foo", "baz", - "-bar", "\"baz\"", "qux", - }); - - // Then - result.Context.Remaining.Parsed.Count.ShouldBe(4); - result.Context.ShouldHaveRemainingArgument("foo", values: new[] { "bar", "baz" }); - result.Context.ShouldHaveRemainingArgument("b", values: new[] { (string)null }); - result.Context.ShouldHaveRemainingArgument("a", values: new[] { (string)null }); - result.Context.ShouldHaveRemainingArgument("r", values: new[] { (string)null }); - } - - [Fact] - public void Should_Register_Remaining_Raw_Arguments_With_Context() - { - // Given - var app = new CommandAppTester(); - app.Configure(config => - { - config.PropagateExceptions(); - config.AddBranch("animal", animal => - { - animal.AddCommand("dog"); - }); - }); - - // When - var result = app.Run(new[] - { - "animal", "4", "dog", "12", "--", - "--foo", "bar", "-bar", "\"baz\"", "qux", - }); - - // Then - result.Context.Remaining.Raw.Count.ShouldBe(5); - result.Context.Remaining.Raw[0].ShouldBe("--foo"); - result.Context.Remaining.Raw[1].ShouldBe("bar"); - result.Context.Remaining.Raw[2].ShouldBe("-bar"); - result.Context.Remaining.Raw[3].ShouldBe("baz"); - result.Context.Remaining.Raw[4].ShouldBe("qux"); - } + // Then + result.ShouldBe(1); + dog.ShouldNotBeNull(); + dog.Age.ShouldBe(12); + dog.Legs.ShouldBe(4); + data.ShouldBe(2); } } -} \ No newline at end of file + + public sealed class Remaining_Arguments + { + [Fact] + public void Should_Register_Remaining_Parsed_Arguments_With_Context() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddBranch("animal", animal => + { + animal.AddCommand("dog"); + }); + }); + + // When + var result = app.Run(new[] + { + "animal", "4", "dog", "12", "--", + "--foo", "bar", "--foo", "baz", + "-bar", "\"baz\"", "qux", + }); + + // Then + result.Context.Remaining.Parsed.Count.ShouldBe(4); + result.Context.ShouldHaveRemainingArgument("foo", values: new[] { "bar", "baz" }); + result.Context.ShouldHaveRemainingArgument("b", values: new[] { (string)null }); + result.Context.ShouldHaveRemainingArgument("a", values: new[] { (string)null }); + result.Context.ShouldHaveRemainingArgument("r", values: new[] { (string)null }); + } + + [Fact] + public void Should_Register_Remaining_Raw_Arguments_With_Context() + { + // Given + var app = new CommandAppTester(); + app.Configure(config => + { + config.PropagateExceptions(); + config.AddBranch("animal", animal => + { + animal.AddCommand("dog"); + }); + }); + + // When + var result = app.Run(new[] + { + "animal", "4", "dog", "12", "--", + "--foo", "bar", "-bar", "\"baz\"", "qux", + }); + + // Then + result.Context.Remaining.Raw.Count.ShouldBe(5); + result.Context.Remaining.Raw[0].ShouldBe("--foo"); + result.Context.Remaining.Raw[1].ShouldBe("bar"); + result.Context.Remaining.Raw[2].ShouldBe("-bar"); + result.Context.Remaining.Raw[3].ShouldBe("baz"); + result.Context.Remaining.Raw[4].ShouldBe("qux"); + } + } +} diff --git a/test/Spectre.Console.Tests/Unit/Cli/DefaultTypeRegistrarTests.cs b/test/Spectre.Console.Tests/Unit/Cli/DefaultTypeRegistrarTests.cs index 9356cfe..6cd2256 100644 --- a/test/Spectre.Console.Tests/Unit/Cli/DefaultTypeRegistrarTests.cs +++ b/test/Spectre.Console.Tests/Unit/Cli/DefaultTypeRegistrarTests.cs @@ -1,16 +1,11 @@ -using Spectre.Console.Cli; -using Spectre.Console.Testing; -using Xunit; +namespace Spectre.Console.Tests.Unit.Cli; -namespace Spectre.Console.Tests.Unit.Cli +public sealed class DefaultTypeRegistrarTests { - public sealed class DefaultTypeRegistrarTests + [Fact] + public void Should_Pass_Base_Registrar_Tests() { - [Fact] - public void Should_Pass_Base_Registrar_Tests() - { - var harness = new TypeRegistrarBaseTests(() => new DefaultTypeRegistrar()); - harness.RunAllTests(); - } + var harness = new TypeRegistrarBaseTests(() => new DefaultTypeRegistrar()); + harness.RunAllTests(); } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/ColorSystemTests.cs b/test/Spectre.Console.Tests/Unit/ColorSystemTests.cs index 5f50b0b..200a2de 100644 --- a/test/Spectre.Console.Tests/Unit/ColorSystemTests.cs +++ b/test/Spectre.Console.Tests/Unit/ColorSystemTests.cs @@ -1,23 +1,19 @@ -using Shouldly; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +public sealed class ColorSystemTests { - public sealed class ColorSystemTests + [Theory] + [InlineData(ColorSystem.NoColors, ColorSystemSupport.NoColors)] + [InlineData(ColorSystem.Legacy, ColorSystemSupport.Legacy)] + [InlineData(ColorSystem.Standard, ColorSystemSupport.Standard)] + [InlineData(ColorSystem.EightBit, ColorSystemSupport.EightBit)] + [InlineData(ColorSystem.TrueColor, ColorSystemSupport.TrueColor)] + public void Should_Be_Analog_To_ColorSystemSupport(ColorSystem colors, ColorSystemSupport support) { - [Theory] - [InlineData(ColorSystem.NoColors, ColorSystemSupport.NoColors)] - [InlineData(ColorSystem.Legacy, ColorSystemSupport.Legacy)] - [InlineData(ColorSystem.Standard, ColorSystemSupport.Standard)] - [InlineData(ColorSystem.EightBit, ColorSystemSupport.EightBit)] - [InlineData(ColorSystem.TrueColor, ColorSystemSupport.TrueColor)] - public void Should_Be_Analog_To_ColorSystemSupport(ColorSystem colors, ColorSystemSupport support) - { - // Given, When - var result = (int)colors; + // Given, When + var result = (int)colors; - // Then - result.ShouldBe((int)support); - } + // Then + result.ShouldBe((int)support); } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/ColorTests.cs b/test/Spectre.Console.Tests/Unit/ColorTests.cs index e0ccf80..5c07195 100644 --- a/test/Spectre.Console.Tests/Unit/ColorTests.cs +++ b/test/Spectre.Console.Tests/Unit/ColorTests.cs @@ -1,287 +1,280 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Shouldly; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +public sealed class ColorTests { - public sealed class ColorTests + public sealed class TheEqualsMethod { - public sealed class TheEqualsMethod + [Fact] + public void Should_Consider_Color_And_Non_Color_Equal() { - [Fact] - public void Should_Consider_Color_And_Non_Color_Equal() - { - // Given - var color1 = new Color(128, 0, 128); + // Given + var color1 = new Color(128, 0, 128); - // When - var result = color1.Equals("Foo"); + // When + var result = color1.Equals("Foo"); + + // Then + result.ShouldBeFalse(); + } + + [Fact] + public void Should_Consider_Same_Colors_Equal_By_Component() + { + // Given + var color1 = new Color(128, 0, 128); + var color2 = new Color(128, 0, 128); + + // When + var result = color1.Equals(color2); + + // Then + result.ShouldBeTrue(); + } + + [Fact] + public void Should_Consider_Same_Known_Colors_Equal() + { + // Given + var color1 = Color.Cyan1; + var color2 = Color.Cyan1; + + // When + var result = color1.Equals(color2); + + // Then + result.ShouldBeTrue(); + } + + [Fact] + public void Should_Consider_Known_Color_And_Color_With_Same_Components_Equal() + { + // Given + var color1 = Color.Cyan1; + var color2 = new Color(0, 255, 255); + + // When + var result = color1.Equals(color2); + + // Then + result.ShouldBeTrue(); + } + + [Fact] + public void Should_Not_Consider_Different_Colors_Equal() + { + // Given + var color1 = new Color(128, 0, 128); + var color2 = new Color(128, 128, 128); + + // When + var result = color1.Equals(color2); + + // Then + result.ShouldBeFalse(); + } + + [Fact] + public void Shourd_Not_Consider_Black_And_Default_Colors_Equal() + { + // Given + var color1 = Color.Default; + var color2 = Color.Black; + + // When + var result = color1.Equals(color2); + + // Then + result.ShouldBeFalse(); + } + } + + public sealed class TheGetHashCodeMethod + { + [Fact] + public void Should_Return_Same_HashCode_For_Same_Colors() + { + // Given + var color1 = new Color(128, 0, 128); + var color2 = new Color(128, 0, 128); + + // When + var hash1 = color1.GetHashCode(); + var hash2 = color2.GetHashCode(); + + // Then + hash1.ShouldBe(hash2); + } + + [Fact] + public void Should_Return_Different_HashCode_For_Different_Colors() + { + // Given + var color1 = new Color(128, 0, 128); + var color2 = new Color(128, 128, 128); + + // When + var hash1 = color1.GetHashCode(); + var hash2 = color2.GetHashCode(); + + // Then + hash1.ShouldNotBe(hash2); + } + } + + public sealed class ImplicitConversions + { + public sealed class Int32ToColor + { + public static IEnumerable Data => + Enumerable.Range(0, 255) + .Select(number => new object[] { number }); + + [Theory] + [MemberData(nameof(Data))] + public void Should_Return_Expected_Color(int number) + { + // Given, When + var result = (Color)number; // Then - result.ShouldBeFalse(); + result.ShouldBe(Color.FromInt32(number)); } [Fact] - public void Should_Consider_Same_Colors_Equal_By_Component() + public void Should_Throw_If_Integer_Is_Lower_Than_Zero() { - // Given - var color1 = new Color(128, 0, 128); - var color2 = new Color(128, 0, 128); - - // When - var result = color1.Equals(color2); + // Given, When + var result = Record.Exception(() => (Color)(-1)); // Then - result.ShouldBeTrue(); + result.ShouldBeOfType(); + result.Message.ShouldBe("Color number must be between 0 and 255"); } [Fact] - public void Should_Consider_Same_Known_Colors_Equal() + public void Should_Throw_If_Integer_Is_Higher_Than_255() { - // Given - var color1 = Color.Cyan1; - var color2 = Color.Cyan1; - - // When - var result = color1.Equals(color2); + // Given, When + var result = Record.Exception(() => (Color)256); // Then - result.ShouldBeTrue(); - } - - [Fact] - public void Should_Consider_Known_Color_And_Color_With_Same_Components_Equal() - { - // Given - var color1 = Color.Cyan1; - var color2 = new Color(0, 255, 255); - - // When - var result = color1.Equals(color2); - - // Then - result.ShouldBeTrue(); - } - - [Fact] - public void Should_Not_Consider_Different_Colors_Equal() - { - // Given - var color1 = new Color(128, 0, 128); - var color2 = new Color(128, 128, 128); - - // When - var result = color1.Equals(color2); - - // Then - result.ShouldBeFalse(); - } - - [Fact] - public void Shourd_Not_Consider_Black_And_Default_Colors_Equal() - { - // Given - var color1 = Color.Default; - var color2 = Color.Black; - - // When - var result = color1.Equals(color2); - - // Then - result.ShouldBeFalse(); + result.ShouldBeOfType(); + result.Message.ShouldBe("Color number must be between 0 and 255"); } } - public sealed class TheGetHashCodeMethod + public sealed class ConsoleColorToColor { - [Fact] - public void Should_Return_Same_HashCode_For_Same_Colors() + [Theory] + [InlineData(ConsoleColor.Black, 0)] + [InlineData(ConsoleColor.DarkRed, 1)] + [InlineData(ConsoleColor.DarkGreen, 2)] + [InlineData(ConsoleColor.DarkYellow, 3)] + [InlineData(ConsoleColor.DarkBlue, 4)] + [InlineData(ConsoleColor.DarkMagenta, 5)] + [InlineData(ConsoleColor.DarkCyan, 6)] + [InlineData(ConsoleColor.Gray, 7)] + [InlineData(ConsoleColor.DarkGray, 8)] + [InlineData(ConsoleColor.Red, 9)] + [InlineData(ConsoleColor.Green, 10)] + [InlineData(ConsoleColor.Yellow, 11)] + [InlineData(ConsoleColor.Blue, 12)] + [InlineData(ConsoleColor.Magenta, 13)] + [InlineData(ConsoleColor.Cyan, 14)] + [InlineData(ConsoleColor.White, 15)] + public void Should_Return_Expected_Color(ConsoleColor color, int expected) { - // Given - var color1 = new Color(128, 0, 128); - var color2 = new Color(128, 0, 128); - - // When - var hash1 = color1.GetHashCode(); - var hash2 = color2.GetHashCode(); + // Given, When + var result = (Color)color; // Then - hash1.ShouldBe(hash2); - } - - [Fact] - public void Should_Return_Different_HashCode_For_Different_Colors() - { - // Given - var color1 = new Color(128, 0, 128); - var color2 = new Color(128, 128, 128); - - // When - var hash1 = color1.GetHashCode(); - var hash2 = color2.GetHashCode(); - - // Then - hash1.ShouldNotBe(hash2); + result.ShouldBe(Color.FromInt32(expected)); } } - public sealed class ImplicitConversions + public sealed class ColorToConsoleColor { - public sealed class Int32ToColor - { - public static IEnumerable Data => - Enumerable.Range(0, 255) - .Select(number => new object[] { number }); - - [Theory] - [MemberData(nameof(Data))] - public void Should_Return_Expected_Color(int number) - { - // Given, When - var result = (Color)number; - - // Then - result.ShouldBe(Color.FromInt32(number)); - } - - [Fact] - public void Should_Throw_If_Integer_Is_Lower_Than_Zero() - { - // Given, When - var result = Record.Exception(() => (Color)(-1)); - - // Then - result.ShouldBeOfType(); - result.Message.ShouldBe("Color number must be between 0 and 255"); - } - - [Fact] - public void Should_Throw_If_Integer_Is_Higher_Than_255() - { - // Given, When - var result = Record.Exception(() => (Color)256); - - // Then - result.ShouldBeOfType(); - result.Message.ShouldBe("Color number must be between 0 and 255"); - } - } - - public sealed class ConsoleColorToColor - { - [Theory] - [InlineData(ConsoleColor.Black, 0)] - [InlineData(ConsoleColor.DarkRed, 1)] - [InlineData(ConsoleColor.DarkGreen, 2)] - [InlineData(ConsoleColor.DarkYellow, 3)] - [InlineData(ConsoleColor.DarkBlue, 4)] - [InlineData(ConsoleColor.DarkMagenta, 5)] - [InlineData(ConsoleColor.DarkCyan, 6)] - [InlineData(ConsoleColor.Gray, 7)] - [InlineData(ConsoleColor.DarkGray, 8)] - [InlineData(ConsoleColor.Red, 9)] - [InlineData(ConsoleColor.Green, 10)] - [InlineData(ConsoleColor.Yellow, 11)] - [InlineData(ConsoleColor.Blue, 12)] - [InlineData(ConsoleColor.Magenta, 13)] - [InlineData(ConsoleColor.Cyan, 14)] - [InlineData(ConsoleColor.White, 15)] - public void Should_Return_Expected_Color(ConsoleColor color, int expected) - { - // Given, When - var result = (Color)color; - - // Then - result.ShouldBe(Color.FromInt32(expected)); - } - } - - public sealed class ColorToConsoleColor - { - [Theory] - [InlineData(0, ConsoleColor.Black)] - [InlineData(1, ConsoleColor.DarkRed)] - [InlineData(2, ConsoleColor.DarkGreen)] - [InlineData(3, ConsoleColor.DarkYellow)] - [InlineData(4, ConsoleColor.DarkBlue)] - [InlineData(5, ConsoleColor.DarkMagenta)] - [InlineData(6, ConsoleColor.DarkCyan)] - [InlineData(7, ConsoleColor.Gray)] - [InlineData(8, ConsoleColor.DarkGray)] - [InlineData(9, ConsoleColor.Red)] - [InlineData(10, ConsoleColor.Green)] - [InlineData(11, ConsoleColor.Yellow)] - [InlineData(12, ConsoleColor.Blue)] - [InlineData(13, ConsoleColor.Magenta)] - [InlineData(14, ConsoleColor.Cyan)] - [InlineData(15, ConsoleColor.White)] - public void Should_Return_Expected_ConsoleColor_For_Known_Color(int color, ConsoleColor expected) - { - // Given, When - var result = (ConsoleColor)Color.FromInt32(color); - - // Then - result.ShouldBe(expected); - } - } - } - - public sealed class TheToMarkupMethod - { - [Fact] - public void Should_Return_Expected_Markup_For_Default_Color() + [Theory] + [InlineData(0, ConsoleColor.Black)] + [InlineData(1, ConsoleColor.DarkRed)] + [InlineData(2, ConsoleColor.DarkGreen)] + [InlineData(3, ConsoleColor.DarkYellow)] + [InlineData(4, ConsoleColor.DarkBlue)] + [InlineData(5, ConsoleColor.DarkMagenta)] + [InlineData(6, ConsoleColor.DarkCyan)] + [InlineData(7, ConsoleColor.Gray)] + [InlineData(8, ConsoleColor.DarkGray)] + [InlineData(9, ConsoleColor.Red)] + [InlineData(10, ConsoleColor.Green)] + [InlineData(11, ConsoleColor.Yellow)] + [InlineData(12, ConsoleColor.Blue)] + [InlineData(13, ConsoleColor.Magenta)] + [InlineData(14, ConsoleColor.Cyan)] + [InlineData(15, ConsoleColor.White)] + public void Should_Return_Expected_ConsoleColor_For_Known_Color(int color, ConsoleColor expected) { // Given, When - var result = Color.Default.ToMarkup(); + var result = (ConsoleColor)Color.FromInt32(color); // Then - result.ShouldBe("default"); - } - - [Fact] - public void Should_Return_Expected_Markup_For_Known_Color() - { - // Given, When - var result = Color.Red.ToMarkup(); - - // Then - result.ShouldBe("red"); - } - - [Fact] - public void Should_Return_Expected_Markup_For_Custom_Color() - { - // Given, When - var result = new Color(255, 1, 12).ToMarkup(); - - // Then - result.ShouldBe("#FF010C"); - } - } - - public sealed class TheToStringMethod - { - [Fact] - public void Should_Return_Color_Name_For_Known_Colors() - { - // Given, When - var name = Color.Fuchsia.ToString(); - - // Then - name.ShouldBe("fuchsia"); - } - - [Fact] - public void Should_Return_Hex_String_For_Unknown_Colors() - { - // Given, When - var name = new Color(128, 0, 128).ToString(); - - // Then - name.ShouldBe("#800080 (RGB=128,0,128)"); + result.ShouldBe(expected); } } } -} \ No newline at end of file + + public sealed class TheToMarkupMethod + { + [Fact] + public void Should_Return_Expected_Markup_For_Default_Color() + { + // Given, When + var result = Color.Default.ToMarkup(); + + // Then + result.ShouldBe("default"); + } + + [Fact] + public void Should_Return_Expected_Markup_For_Known_Color() + { + // Given, When + var result = Color.Red.ToMarkup(); + + // Then + result.ShouldBe("red"); + } + + [Fact] + public void Should_Return_Expected_Markup_For_Custom_Color() + { + // Given, When + var result = new Color(255, 1, 12).ToMarkup(); + + // Then + result.ShouldBe("#FF010C"); + } + } + + public sealed class TheToStringMethod + { + [Fact] + public void Should_Return_Color_Name_For_Known_Colors() + { + // Given, When + var name = Color.Fuchsia.ToString(); + + // Then + name.ShouldBe("fuchsia"); + } + + [Fact] + public void Should_Return_Hex_String_For_Unknown_Colors() + { + // Given, When + var name = new Color(128, 0, 128).ToString(); + + // Then + name.ShouldBe("#800080 (RGB=128,0,128)"); + } + } +} diff --git a/test/Spectre.Console.Tests/Unit/EmojiTests.cs b/test/Spectre.Console.Tests/Unit/EmojiTests.cs index 7dac292..6aa67a1 100644 --- a/test/Spectre.Console.Tests/Unit/EmojiTests.cs +++ b/test/Spectre.Console.Tests/Unit/EmojiTests.cs @@ -1,96 +1,91 @@ -using Shouldly; -using Spectre.Console.Testing; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +public sealed class EmojiTests { - public sealed class EmojiTests + [Fact] + public void Should_Substitute_Emoji_Shortcodes_In_Markdown() + { + // Given + var console = new TestConsole(); + + // When + console.Markup("Hello :globe_showing_europe_africa:!"); + + // Then + console.Output.ShouldBe("Hello 🌍!"); + } + + [Fact] + public void Should_Contain_Predefined_Emojis() + { + // Given, When + const string result = "Hello " + Emoji.Known.GlobeShowingEuropeAfrica + "!"; + + // Then + result.ShouldBe("Hello 🌍!"); + } + + public sealed class TheReplaceMethod { [Fact] - public void Should_Substitute_Emoji_Shortcodes_In_Markdown() + public void Should_Replace_Emojis_In_Text() + { + // Given, When + var result = Emoji.Replace("Hello :globe_showing_europe_africa:!"); + + // Then + result.ShouldBe("Hello 🌍!"); + } + } + + public sealed class Parsing + { + [Theory] + [InlineData(":", ":")] + [InlineData("::", "::")] + [InlineData(":::", ":::")] + [InlineData("::::", "::::")] + [InlineData("::i:", "::i:")] + [InlineData(":i:i:", ":i:i:")] + [InlineData("::globe_showing_europe_africa::", ":🌍:")] + [InlineData(":globe_showing_europe_africa::globe_showing_europe_africa:", "🌍🌍")] + [InlineData("::globe_showing_europe_africa:::test:::globe_showing_europe_africa:::", ":🌍::test::🌍::")] + public void Can_Handle_Different_Combinations(string markup, string expected) { // Given var console = new TestConsole(); // When - console.Markup("Hello :globe_showing_europe_africa:!"); + console.Markup(markup); // Then - console.Output.ShouldBe("Hello 🌍!"); + console.Output.ShouldBe(expected); } [Fact] - public void Should_Contain_Predefined_Emojis() + public void Should_Leave_Single_Colons() { - // Given, When - const string result = "Hello " + Emoji.Known.GlobeShowingEuropeAfrica + "!"; + // Given + var console = new TestConsole(); + + // When + console.Markup("Hello :globe_showing_europe_africa:! Output: good"); // Then - result.ShouldBe("Hello 🌍!"); + console.Output.ShouldBe("Hello 🌍! Output: good"); } - public sealed class TheReplaceMethod + [Fact] + public void Unknown_emojis_should_remain_unchanged() { - [Fact] - public void Should_Replace_Emojis_In_Text() - { - // Given, When - var result = Emoji.Replace("Hello :globe_showing_europe_africa:!"); + // Given + var console = new TestConsole(); - // Then - result.ShouldBe("Hello 🌍!"); - } - } + // When + console.Markup("Hello :globe_showing_flat_earth:!"); - public sealed class Parsing - { - [Theory] - [InlineData(":", ":")] - [InlineData("::", "::")] - [InlineData(":::", ":::")] - [InlineData("::::", "::::")] - [InlineData("::i:", "::i:")] - [InlineData(":i:i:", ":i:i:")] - [InlineData("::globe_showing_europe_africa::", ":🌍:")] - [InlineData(":globe_showing_europe_africa::globe_showing_europe_africa:", "🌍🌍")] - [InlineData("::globe_showing_europe_africa:::test:::globe_showing_europe_africa:::", ":🌍::test::🌍::")] - public void Can_Handle_Different_Combinations(string markup, string expected) - { - // Given - var console = new TestConsole(); - - // When - console.Markup(markup); - - // Then - console.Output.ShouldBe(expected); - } - - [Fact] - public void Should_Leave_Single_Colons() - { - // Given - var console = new TestConsole(); - - // When - console.Markup("Hello :globe_showing_europe_africa:! Output: good"); - - // Then - console.Output.ShouldBe("Hello 🌍! Output: good"); - } - - [Fact] - public void Unknown_emojis_should_remain_unchanged() - { - // Given - var console = new TestConsole(); - - // When - console.Markup("Hello :globe_showing_flat_earth:!"); - - // Then - console.Output.ShouldBe("Hello :globe_showing_flat_earth:!"); - } + // Then + console.Output.ShouldBe("Hello :globe_showing_flat_earth:!"); } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/ExceptionTests.cs b/test/Spectre.Console.Tests/Unit/ExceptionTests.cs index 64c4ed6..bafaa8a 100644 --- a/test/Spectre.Console.Tests/Unit/ExceptionTests.cs +++ b/test/Spectre.Console.Tests/Unit/ExceptionTests.cs @@ -1,104 +1,95 @@ -using System; -using System.Threading.Tasks; -using Spectre.Console.Testing; -using Spectre.Console.Tests.Data; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("Exception")] +public sealed class ExceptionTests { - [UsesVerify] - [ExpectationPath("Exception")] - public sealed class ExceptionTests + [Fact] + [Expectation("Default")] + public Task Should_Write_Exception() { - [Fact] - [Expectation("Default")] - public Task Should_Write_Exception() - { - // Given - var console = new TestConsole().Width(1024); - var dex = GetException(() => TestExceptions.MethodThatThrows(null)); + // Given + var console = new TestConsole().Width(1024); + var dex = GetException(() => TestExceptions.MethodThatThrows(null)); - // When - var result = console.WriteNormalizedException(dex); + // When + var result = console.WriteNormalizedException(dex); - // Then - return Verifier.Verify(result); - } - - [Fact] - [Expectation("ShortenedTypes")] - public Task Should_Write_Exception_With_Shortened_Types() - { - // Given - var console = new TestConsole().Width(1024); - var dex = GetException(() => TestExceptions.MethodThatThrows(null)); - - // When - var result = console.WriteNormalizedException(dex, ExceptionFormats.ShortenTypes); - - // Then - return Verifier.Verify(result); - } - - [Fact] - [Expectation("ShortenedMethods")] - public Task Should_Write_Exception_With_Shortened_Methods() - { - // Given - var console = new TestConsole().Width(1024); - var dex = GetException(() => TestExceptions.MethodThatThrows(null)); - - // When - var result = console.WriteNormalizedException(dex, ExceptionFormats.ShortenMethods); - - // Then - return Verifier.Verify(result); - } - - [Fact] - [Expectation("InnerException")] - public Task Should_Write_Exception_With_Inner_Exception() - { - // Given - var console = new TestConsole().Width(1024); - var dex = GetException(() => TestExceptions.ThrowWithInnerException()); - - // When - var result = console.WriteNormalizedException(dex); - - // Then - return Verifier.Verify(result); - } - - [Fact] - [Expectation("CallSite")] - public Task Should_Write_Exceptions_With_Generic_Type_Parameters_In_Callsite_As_Expected() - { - // Given - var console = new TestConsole().Width(1024); - var dex = GetException(() => TestExceptions.ThrowWithGenericInnerException()); - - // When - var result = console.WriteNormalizedException(dex); - - // Then - return Verifier.Verify(result); - } - - public static Exception GetException(Action action) - { - try - { - action?.Invoke(); - } - catch (Exception e) - { - return e; - } - - throw new InvalidOperationException("Exception harness failed"); - } + // Then + return Verifier.Verify(result); } -} \ No newline at end of file + + [Fact] + [Expectation("ShortenedTypes")] + public Task Should_Write_Exception_With_Shortened_Types() + { + // Given + var console = new TestConsole().Width(1024); + var dex = GetException(() => TestExceptions.MethodThatThrows(null)); + + // When + var result = console.WriteNormalizedException(dex, ExceptionFormats.ShortenTypes); + + // Then + return Verifier.Verify(result); + } + + [Fact] + [Expectation("ShortenedMethods")] + public Task Should_Write_Exception_With_Shortened_Methods() + { + // Given + var console = new TestConsole().Width(1024); + var dex = GetException(() => TestExceptions.MethodThatThrows(null)); + + // When + var result = console.WriteNormalizedException(dex, ExceptionFormats.ShortenMethods); + + // Then + return Verifier.Verify(result); + } + + [Fact] + [Expectation("InnerException")] + public Task Should_Write_Exception_With_Inner_Exception() + { + // Given + var console = new TestConsole().Width(1024); + var dex = GetException(() => TestExceptions.ThrowWithInnerException()); + + // When + var result = console.WriteNormalizedException(dex); + + // Then + return Verifier.Verify(result); + } + + [Fact] + [Expectation("CallSite")] + public Task Should_Write_Exceptions_With_Generic_Type_Parameters_In_Callsite_As_Expected() + { + // Given + var console = new TestConsole().Width(1024); + var dex = GetException(() => TestExceptions.ThrowWithGenericInnerException()); + + // When + var result = console.WriteNormalizedException(dex); + + // Then + return Verifier.Verify(result); + } + + public static Exception GetException(Action action) + { + try + { + action?.Invoke(); + } + catch (Exception e) + { + return e; + } + + throw new InvalidOperationException("Exception harness failed"); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Live/Progress/DownloadedColumnTests.cs b/test/Spectre.Console.Tests/Unit/Live/Progress/DownloadedColumnTests.cs index 3347851..6b2b76f 100644 --- a/test/Spectre.Console.Tests/Unit/Live/Progress/DownloadedColumnTests.cs +++ b/test/Spectre.Console.Tests/Unit/Live/Progress/DownloadedColumnTests.cs @@ -1,30 +1,25 @@ -using System.Globalization; -using Shouldly; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +public sealed class DownloadedColumnTests { - public sealed class DownloadedColumnTests + [Theory] + [InlineData(0, 1, "0/1 byte")] + [InlineData(37, 101, "37/101 bytes")] + [InlineData(101, 101, "101 bytes")] + [InlineData(512, 1024, "0.5/1.0 KB")] + [InlineData(1024, 1024, "1.0 KB")] + [InlineData(1024 * 512, 5 * 1024 * 1024, "0.5/5.0 MB")] + [InlineData(5 * 1024 * 1024, 5 * 1024 * 1024, "5.0 MB")] + public void Should_Return_Correct_Value(double value, double total, string expected) { - [Theory] - [InlineData(0, 1, "0/1 byte")] - [InlineData(37, 101, "37/101 bytes")] - [InlineData(101, 101, "101 bytes")] - [InlineData(512, 1024, "0.5/1.0 KB")] - [InlineData(1024, 1024, "1.0 KB")] - [InlineData(1024 * 512, 5 * 1024 * 1024, "0.5/5.0 MB")] - [InlineData(5 * 1024 * 1024, 5 * 1024 * 1024, "5.0 MB")] - public void Should_Return_Correct_Value(double value, double total, string expected) - { - // Given - var fixture = new ProgressColumnFixture(value, total); - fixture.Column.Culture = CultureInfo.InvariantCulture; + // Given + var fixture = new ProgressColumnFixture(value, total); + fixture.Column.Culture = CultureInfo.InvariantCulture; - // When - var result = fixture.Render(); + // When + var result = fixture.Render(); - // Then - result.ShouldBe(expected); - } + // Then + result.ShouldBe(expected); } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/Live/Progress/ProgressColumnFixture.cs b/test/Spectre.Console.Tests/Unit/Live/Progress/ProgressColumnFixture.cs index bd34f77..4b10877 100644 --- a/test/Spectre.Console.Tests/Unit/Live/Progress/ProgressColumnFixture.cs +++ b/test/Spectre.Console.Tests/Unit/Live/Progress/ProgressColumnFixture.cs @@ -1,28 +1,23 @@ -using System; -using Spectre.Console.Rendering; -using Spectre.Console.Testing; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +public sealed class ProgressColumnFixture + where T : ProgressColumn, new() { - public sealed class ProgressColumnFixture - where T : ProgressColumn, new() + public T Column { get; } + public ProgressTask Task { get; set; } + + public ProgressColumnFixture(double completed, double total) { - public T Column { get; } - public ProgressTask Task { get; set; } - - public ProgressColumnFixture(double completed, double total) - { - Column = new T(); - Task = new ProgressTask(1, "Foo", total); - Task.Increment(completed); - } - - public string Render() - { - var console = new TestConsole(); - var context = new RenderContext(console.Profile.Capabilities); - console.Write(Column.Render(context, Task, TimeSpan.Zero)); - return console.Output; - } + Column = new T(); + Task = new ProgressTask(1, "Foo", total); + Task.Increment(completed); } -} \ No newline at end of file + + public string Render() + { + var console = new TestConsole(); + var context = new RenderContext(console.Profile.Capabilities); + console.Write(Column.Render(context, Task, TimeSpan.Zero)); + return console.Output; + } +} diff --git a/test/Spectre.Console.Tests/Unit/Live/Progress/ProgressTests.cs b/test/Spectre.Console.Tests/Unit/Live/Progress/ProgressTests.cs index 4c376fc..f42f387 100644 --- a/test/Spectre.Console.Tests/Unit/Live/Progress/ProgressTests.cs +++ b/test/Spectre.Console.Tests/Unit/Live/Progress/ProgressTests.cs @@ -1,275 +1,267 @@ -using System; -using System.Threading; -using System.Threading.Tasks; -using Shouldly; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("Live/Progress")] +public sealed class ProgressTests { - [UsesVerify] - [ExpectationPath("Live/Progress")] - public sealed class ProgressTests + [Fact] + public void Should_Render_Task_Correctly() { - [Fact] - public void Should_Render_Task_Correctly() - { - // Given - var console = new TestConsole() - .Width(10) - .Interactive() - .EmitAnsiSequences(); + // Given + var console = new TestConsole() + .Width(10) + .Interactive() + .EmitAnsiSequences(); - var progress = new Progress(console) - .Columns(new[] { new ProgressBarColumn() }) - .AutoRefresh(false) - .AutoClear(true); + var progress = new Progress(console) + .Columns(new[] { new ProgressBarColumn() }) + .AutoRefresh(false) + .AutoClear(true); - // When - progress.Start(ctx => ctx.AddTask("foo")); + // When + progress.Start(ctx => ctx.AddTask("foo")); - // Then - console.Output - .NormalizeLineEndings() - .ShouldBe( - "[?25l" + // Hide cursor - " \n" + // Top padding - "━━━━━━━━━━\n" + // Task - " " + // Bottom padding - "[?25h"); // Clear + show cursor - } + // Then + console.Output + .NormalizeLineEndings() + .ShouldBe( + "[?25l" + // Hide cursor + " \n" + // Top padding + "━━━━━━━━━━\n" + // Task + " " + // Bottom padding + "[?25h"); // Clear + show cursor + } - [Fact] - public void Should_Not_Auto_Clear_If_Specified() - { - // Given - var console = new TestConsole() - .Width(10) - .Interactive() - .EmitAnsiSequences(); + [Fact] + public void Should_Not_Auto_Clear_If_Specified() + { + // Given + var console = new TestConsole() + .Width(10) + .Interactive() + .EmitAnsiSequences(); - var progress = new Progress(console) - .Columns(new[] { new ProgressBarColumn() }) - .AutoRefresh(false) - .AutoClear(false); + var progress = new Progress(console) + .Columns(new[] { new ProgressBarColumn() }) + .AutoRefresh(false) + .AutoClear(false); - // When - progress.Start(ctx => ctx.AddTask("foo")); + // When + progress.Start(ctx => ctx.AddTask("foo")); - // Then - console.Output - .NormalizeLineEndings() - .ShouldBe( - "[?25l" + // Hide cursor - " \n" + // Top padding - "━━━━━━━━━━\n" + // Task - " \n" + // Bottom padding - "[?25h"); // show cursor - } + // Then + console.Output + .NormalizeLineEndings() + .ShouldBe( + "[?25l" + // Hide cursor + " \n" + // Top padding + "━━━━━━━━━━\n" + // Task + " \n" + // Bottom padding + "[?25h"); // show cursor + } - [Fact] - [Expectation("Render_ReduceWidth")] - public Task Should_Reduce_Width_If_Needed() - { - // Given - var console = new TestConsole() - .Width(20) - .Interactive(); + [Fact] + [Expectation("Render_ReduceWidth")] + public Task Should_Reduce_Width_If_Needed() + { + // Given + var console = new TestConsole() + .Width(20) + .Interactive(); - var progress = new Progress(console) - .Columns(new ProgressColumn[] - { + var progress = new Progress(console) + .Columns(new ProgressColumn[] + { new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn(), new RemainingTimeColumn(), new SpinnerColumn(), - }) - .AutoRefresh(false) - .AutoClear(false); + }) + .AutoRefresh(false) + .AutoClear(false); - // When - progress.Start(ctx => - { - ctx.AddTask("foo"); - ctx.AddTask("bar"); - ctx.AddTask("baz"); - }); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - public void Setting_Max_Value_Should_Set_The_MaxValue_And_Cap_Value() + // When + progress.Start(ctx => { - // Given - var console = new TestConsole() - .Interactive(); + ctx.AddTask("foo"); + ctx.AddTask("bar"); + ctx.AddTask("baz"); + }); - var task = default(ProgressTask); - var progress = new Progress(console) - .Columns(new[] { new ProgressBarColumn() }) - .AutoRefresh(false) - .AutoClear(false); - - // When - progress.Start(ctx => - { - task = ctx.AddTask("foo"); - task.Increment(100); - task.MaxValue = 20; - }); - - // Then - task.MaxValue.ShouldBe(20); - task.Value.ShouldBe(20); - } - - [Fact] - public void Setting_Value_Should_Override_Incremented_Value() - { - // Given - var console = new TestConsole() - .Interactive(); - - var task = default(ProgressTask); - var progress = new Progress(console) - .Columns(new[] { new ProgressBarColumn() }) - .AutoRefresh(false) - .AutoClear(false); - - // When - progress.Start(ctx => - { - task = ctx.AddTask("foo"); - task.Increment(50); - task.Value = 20; - }); - - // Then - task.MaxValue.ShouldBe(100); - task.Value.ShouldBe(20); - } - - [Fact] - public void Setting_Value_To_MaxValue_Should_Finish_Task() - { - // Given - var console = new TestConsole() - .Interactive(); - - var task = default(ProgressTask); - var progress = new Progress(console) - .Columns(new[] { new ProgressBarColumn() }) - .AutoRefresh(false) - .AutoClear(false); - - // When - progress.Start(ctx => - { - task = ctx.AddTask("foo"); - task.Value = task.MaxValue; - }); - - // Then - task.IsFinished.ShouldBe(true); - } - - [Fact] - public void Should_Increment_Manually_Set_Value() - { - // Given - var console = new TestConsole() - .Interactive(); - - var task = default(ProgressTask); - var progress = new Progress(console) - .Columns(new[] { new ProgressBarColumn() }) - .AutoRefresh(false) - .AutoClear(false); - - // When - progress.Start(ctx => - { - task = ctx.AddTask("foo"); - task.Value = 50; - task.Increment(10); - }); - - // Then - task.Value.ShouldBe(60); - } - - [Fact] - public void Should_Hide_Completed_Tasks() - { - // Given - var console = new TestConsole() - .Width(10) - .Interactive() - .EmitAnsiSequences(); - - var taskFinished = default(ProgressTask); - var taskInProgress1 = default(ProgressTask); - var taskInProgress2 = default(ProgressTask); - - var progress = new Progress(console) - .Columns(new[] { new ProgressBarColumn() }) - .AutoRefresh(false) - .AutoClear(false) - .HideCompleted(true); - - // When - progress.Start(ctx => - { - taskInProgress1 = ctx.AddTask("foo"); - taskFinished = ctx.AddTask("bar"); - taskInProgress2 = ctx.AddTask("baz"); - taskInProgress2.Increment(20); - taskFinished.Value = taskFinished.MaxValue; - }); - - // Then - console.Output - .NormalizeLineEndings() - .ShouldBe( - "[?25l" + // Hide cursor - " \n" + // top padding - "━━━━━━━━━━\n" + // taskInProgress1 - "━━━━━━━━━━\n" + // taskInProgress2 - " \n" + // bottom padding - "[?25h"); // show cursor - } - - [Fact] - public void Should_Report_Max_Remaining_Time_For_Extremely_Small_Progress() - { - // Given - var console = new TestConsole() - .Interactive(); - - var task = default(ProgressTask); - var progress = new Progress(console) - .Columns(new[] { new RemainingTimeColumn() }) - .AutoRefresh(false) - .AutoClear(false); - - // When - progress.Start(ctx => - { - task = ctx.AddTask("foo"); - task.Increment(double.Epsilon); - // Make sure that at least one millisecond has elapsed between the increments else the RemainingTime is null - // when the last timestamp is equal to the first timestamp of the samples. - Thread.Sleep(1); - task.Increment(double.Epsilon); - }); - - // Then - task.RemainingTime.ShouldBe(TimeSpan.MaxValue); - } + // Then + return Verifier.Verify(console.Output); } -} \ No newline at end of file + + [Fact] + public void Setting_Max_Value_Should_Set_The_MaxValue_And_Cap_Value() + { + // Given + var console = new TestConsole() + .Interactive(); + + var task = default(ProgressTask); + var progress = new Progress(console) + .Columns(new[] { new ProgressBarColumn() }) + .AutoRefresh(false) + .AutoClear(false); + + // When + progress.Start(ctx => + { + task = ctx.AddTask("foo"); + task.Increment(100); + task.MaxValue = 20; + }); + + // Then + task.MaxValue.ShouldBe(20); + task.Value.ShouldBe(20); + } + + [Fact] + public void Setting_Value_Should_Override_Incremented_Value() + { + // Given + var console = new TestConsole() + .Interactive(); + + var task = default(ProgressTask); + var progress = new Progress(console) + .Columns(new[] { new ProgressBarColumn() }) + .AutoRefresh(false) + .AutoClear(false); + + // When + progress.Start(ctx => + { + task = ctx.AddTask("foo"); + task.Increment(50); + task.Value = 20; + }); + + // Then + task.MaxValue.ShouldBe(100); + task.Value.ShouldBe(20); + } + + [Fact] + public void Setting_Value_To_MaxValue_Should_Finish_Task() + { + // Given + var console = new TestConsole() + .Interactive(); + + var task = default(ProgressTask); + var progress = new Progress(console) + .Columns(new[] { new ProgressBarColumn() }) + .AutoRefresh(false) + .AutoClear(false); + + // When + progress.Start(ctx => + { + task = ctx.AddTask("foo"); + task.Value = task.MaxValue; + }); + + // Then + task.IsFinished.ShouldBe(true); + } + + [Fact] + public void Should_Increment_Manually_Set_Value() + { + // Given + var console = new TestConsole() + .Interactive(); + + var task = default(ProgressTask); + var progress = new Progress(console) + .Columns(new[] { new ProgressBarColumn() }) + .AutoRefresh(false) + .AutoClear(false); + + // When + progress.Start(ctx => + { + task = ctx.AddTask("foo"); + task.Value = 50; + task.Increment(10); + }); + + // Then + task.Value.ShouldBe(60); + } + + [Fact] + public void Should_Hide_Completed_Tasks() + { + // Given + var console = new TestConsole() + .Width(10) + .Interactive() + .EmitAnsiSequences(); + + var taskFinished = default(ProgressTask); + var taskInProgress1 = default(ProgressTask); + var taskInProgress2 = default(ProgressTask); + + var progress = new Progress(console) + .Columns(new[] { new ProgressBarColumn() }) + .AutoRefresh(false) + .AutoClear(false) + .HideCompleted(true); + + // When + progress.Start(ctx => + { + taskInProgress1 = ctx.AddTask("foo"); + taskFinished = ctx.AddTask("bar"); + taskInProgress2 = ctx.AddTask("baz"); + taskInProgress2.Increment(20); + taskFinished.Value = taskFinished.MaxValue; + }); + + // Then + console.Output + .NormalizeLineEndings() + .ShouldBe( + "[?25l" + // Hide cursor + " \n" + // top padding + "━━━━━━━━━━\n" + // taskInProgress1 + "━━━━━━━━━━\n" + // taskInProgress2 + " \n" + // bottom padding + "[?25h"); // show cursor + } + + [Fact] + public void Should_Report_Max_Remaining_Time_For_Extremely_Small_Progress() + { + // Given + var console = new TestConsole() + .Interactive(); + + var task = default(ProgressTask); + var progress = new Progress(console) + .Columns(new[] { new RemainingTimeColumn() }) + .AutoRefresh(false) + .AutoClear(false); + + // When + progress.Start(ctx => + { + task = ctx.AddTask("foo"); + task.Increment(double.Epsilon); + + // Make sure that at least one millisecond has elapsed between the increments else the RemainingTime is null + // when the last timestamp is equal to the first timestamp of the samples. + Thread.Sleep(1); + + task.Increment(double.Epsilon); + }); + + // Then + task.RemainingTime.ShouldBe(TimeSpan.MaxValue); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Live/StatusTests.cs b/test/Spectre.Console.Tests/Unit/Live/StatusTests.cs index 3c6527f..60f914d 100644 --- a/test/Spectre.Console.Tests/Unit/Live/StatusTests.cs +++ b/test/Spectre.Console.Tests/Unit/Live/StatusTests.cs @@ -1,61 +1,52 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("Live/Status")] +public sealed class StatusTests { - [UsesVerify] - [ExpectationPath("Live/Status")] - public sealed class StatusTests + public sealed class DummySpinner1 : Spinner { - public sealed class DummySpinner1 : Spinner - { - public override TimeSpan Interval => TimeSpan.FromMilliseconds(100); - public override bool IsUnicode => true; - public override IReadOnlyList Frames => new List { "*", }; - } - - public sealed class DummySpinner2 : Spinner - { - public override TimeSpan Interval => TimeSpan.FromMilliseconds(100); - public override bool IsUnicode => true; - public override IReadOnlyList Frames => new List { "-", }; - } - - [Fact] - [Expectation("Render")] - public Task Should_Render_Status_Correctly() - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.TrueColor) - .Width(10) - .Interactive() - .EmitAnsiSequences(); - - var status = new Status(console) - { - AutoRefresh = false, - Spinner = new DummySpinner1(), - }; - - // When - status.Start("foo", ctx => - { - ctx.Refresh(); - ctx.Spinner(new DummySpinner2()); - ctx.Status("bar"); - ctx.Refresh(); - ctx.Spinner(new DummySpinner1()); - ctx.Status("baz"); - }); - - // Then - return Verifier.Verify(console.Output); - } + public override TimeSpan Interval => TimeSpan.FromMilliseconds(100); + public override bool IsUnicode => true; + public override IReadOnlyList Frames => new List { "*", }; } -} \ No newline at end of file + + public sealed class DummySpinner2 : Spinner + { + public override TimeSpan Interval => TimeSpan.FromMilliseconds(100); + public override bool IsUnicode => true; + public override IReadOnlyList Frames => new List { "-", }; + } + + [Fact] + [Expectation("Render")] + public Task Should_Render_Status_Correctly() + { + // Given + var console = new TestConsole() + .Colors(ColorSystem.TrueColor) + .Width(10) + .Interactive() + .EmitAnsiSequences(); + + var status = new Status(console) + { + AutoRefresh = false, + Spinner = new DummySpinner1(), + }; + + // When + status.Start("foo", ctx => + { + ctx.Refresh(); + ctx.Spinner(new DummySpinner2()); + ctx.Status("bar"); + ctx.Refresh(); + ctx.Spinner(new DummySpinner1()); + ctx.Status("baz"); + }); + + // Then + return Verifier.Verify(console.Output); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Prompts/MultiSelectionPromptTests.cs b/test/Spectre.Console.Tests/Unit/Prompts/MultiSelectionPromptTests.cs index da7cae4..1f3b026 100644 --- a/test/Spectre.Console.Tests/Unit/Prompts/MultiSelectionPromptTests.cs +++ b/test/Spectre.Console.Tests/Unit/Prompts/MultiSelectionPromptTests.cs @@ -1,156 +1,149 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using Shouldly; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +public sealed class MultiSelectionPromptTests { - public sealed class MultiSelectionPromptTests + private class CustomItem { - private class CustomItem + public int X { get; set; } + public int Y { get; set; } + + public class Comparer : IEqualityComparer { - public int X { get; set; } - public int Y { get; set; } - - public class Comparer : IEqualityComparer + public bool Equals(CustomItem x, CustomItem y) { - public bool Equals(CustomItem x, CustomItem y) - { - return x.X == y.X && x.Y == y.Y; - } + return x.X == y.X && x.Y == y.Y; + } - public int GetHashCode([DisallowNull] CustomItem obj) - { - throw new NotImplementedException(); - } + public int GetHashCode([DisallowNull] CustomItem obj) + { + throw new NotSupportedException(); } } - - [Fact] - public void Should_Not_Mark_Item_As_Selected_By_Default() - { - // Given - var prompt = new MultiSelectionPrompt(); - - // When - var choice = prompt.AddChoice(32); - - // Then - choice.IsSelected.ShouldBeFalse(); - } - - [Fact] - public void Should_Mark_Item_As_Selected() - { - // Given - var prompt = new MultiSelectionPrompt(); - var choice = prompt.AddChoice(32); - - // When - prompt.Select(32); - - // Then - choice.IsSelected.ShouldBeTrue(); - } - - [Fact] - public void Should_Mark_Custom_Item_As_Selected_If_The_Same_Reference_Is_Used() - { - // Given - var prompt = new MultiSelectionPrompt(); - var item = new CustomItem { X = 18, Y = 32 }; - var choice = prompt.AddChoice(item); - - // When - prompt.Select(item); - - // Then - choice.IsSelected.ShouldBeTrue(); - } - - [Fact] - public void Should_Mark_Custom_Item_As_Selected_If_A_Comparer_Is_Provided() - { - // Given - var prompt = new MultiSelectionPrompt(new CustomItem.Comparer()); - var choice = prompt.AddChoice(new CustomItem { X = 18, Y = 32 }); - - // When - prompt.Select(new CustomItem { X = 18, Y = 32 }); - - // Then - choice.IsSelected.ShouldBeTrue(); - } - - [Fact] - public void Should_Get_The_Direct_Parent() - { - // Given - var prompt = new MultiSelectionPrompt(); - prompt.AddChoice("root").AddChild("level-1").AddChild("level-2").AddChild("item"); - - // When - var actual = prompt.GetParent("item"); - - // Then - actual.ShouldBe("level-2"); - } - - [Fact] - public void Should_Get_The_List_Of_All_Parents() - { - // Given - var prompt = new MultiSelectionPrompt(); - prompt.AddChoice("root").AddChild("level-1").AddChild("level-2").AddChild("item"); - - // When - var actual = prompt.GetParents("item"); - - // Then - actual.ShouldBe(new[] { "root", "level-1", "level-2" }); - } - - [Fact] - public void Should_Get_An_Empty_List_Of_Parents_For_Root_Node() - { - // Given - var prompt = new MultiSelectionPrompt(); - prompt.AddChoice("root"); - - // When - var actual = prompt.GetParents("root"); - - // Then - actual.ShouldBeEmpty(); - } - - [Fact] - public void Should_Get_Null_As_Direct_Parent_Of_Root_Node() - { - // Given - var prompt = new MultiSelectionPrompt(); - prompt.AddChoice("root"); - - // When - var actual = prompt.GetParent("root"); - - // Then - actual.ShouldBeNull(); - } - - [Fact] - public void Should_Throw_When_Getting_Parents_Of_Non_Existing_Node() - { - // Given - var prompt = new MultiSelectionPrompt(); - prompt.AddChoice("root").AddChild("level-1").AddChild("level-2").AddChild("item"); - - // When - Action action = () => prompt.GetParents("non-existing"); - - // Then - action.ShouldThrow(); - } } -} \ No newline at end of file + + [Fact] + public void Should_Not_Mark_Item_As_Selected_By_Default() + { + // Given + var prompt = new MultiSelectionPrompt(); + + // When + var choice = prompt.AddChoice(32); + + // Then + choice.IsSelected.ShouldBeFalse(); + } + + [Fact] + public void Should_Mark_Item_As_Selected() + { + // Given + var prompt = new MultiSelectionPrompt(); + var choice = prompt.AddChoice(32); + + // When + prompt.Select(32); + + // Then + choice.IsSelected.ShouldBeTrue(); + } + + [Fact] + public void Should_Mark_Custom_Item_As_Selected_If_The_Same_Reference_Is_Used() + { + // Given + var prompt = new MultiSelectionPrompt(); + var item = new CustomItem { X = 18, Y = 32 }; + var choice = prompt.AddChoice(item); + + // When + prompt.Select(item); + + // Then + choice.IsSelected.ShouldBeTrue(); + } + + [Fact] + public void Should_Mark_Custom_Item_As_Selected_If_A_Comparer_Is_Provided() + { + // Given + var prompt = new MultiSelectionPrompt(new CustomItem.Comparer()); + var choice = prompt.AddChoice(new CustomItem { X = 18, Y = 32 }); + + // When + prompt.Select(new CustomItem { X = 18, Y = 32 }); + + // Then + choice.IsSelected.ShouldBeTrue(); + } + + [Fact] + public void Should_Get_The_Direct_Parent() + { + // Given + var prompt = new MultiSelectionPrompt(); + prompt.AddChoice("root").AddChild("level-1").AddChild("level-2").AddChild("item"); + + // When + var actual = prompt.GetParent("item"); + + // Then + actual.ShouldBe("level-2"); + } + + [Fact] + public void Should_Get_The_List_Of_All_Parents() + { + // Given + var prompt = new MultiSelectionPrompt(); + prompt.AddChoice("root").AddChild("level-1").AddChild("level-2").AddChild("item"); + + // When + var actual = prompt.GetParents("item"); + + // Then + actual.ShouldBe(new[] { "root", "level-1", "level-2" }); + } + + [Fact] + public void Should_Get_An_Empty_List_Of_Parents_For_Root_Node() + { + // Given + var prompt = new MultiSelectionPrompt(); + prompt.AddChoice("root"); + + // When + var actual = prompt.GetParents("root"); + + // Then + actual.ShouldBeEmpty(); + } + + [Fact] + public void Should_Get_Null_As_Direct_Parent_Of_Root_Node() + { + // Given + var prompt = new MultiSelectionPrompt(); + prompt.AddChoice("root"); + + // When + var actual = prompt.GetParent("root"); + + // Then + actual.ShouldBeNull(); + } + + [Fact] + public void Should_Throw_When_Getting_Parents_Of_Non_Existing_Node() + { + // Given + var prompt = new MultiSelectionPrompt(); + prompt.AddChoice("root").AddChild("level-1").AddChild("level-2").AddChild("item"); + + // When + Action action = () => prompt.GetParents("non-existing"); + + // Then + action.ShouldThrow(); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Prompts/SelectionPromptTests.cs b/test/Spectre.Console.Tests/Unit/Prompts/SelectionPromptTests.cs index 036a74d..3e63dae 100644 --- a/test/Spectre.Console.Tests/Unit/Prompts/SelectionPromptTests.cs +++ b/test/Spectre.Console.Tests/Unit/Prompts/SelectionPromptTests.cs @@ -1,30 +1,24 @@ -using System; -using Shouldly; -using Spectre.Console.Testing; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +public sealed class SelectionPromptTests { - public sealed class SelectionPromptTests + [Fact] + [GitHubIssue(608)] + public void Should_Not_Throw_When_Selecting_An_Item_With_Escaped_Markup() { - [Fact] - [GitHubIssue(608)] - public void Should_Not_Throw_When_Selecting_An_Item_With_Escaped_Markup() - { - // Given - var console = new TestConsole(); - console.Profile.Capabilities.Interactive = true; - console.Input.PushKey(ConsoleKey.Enter); - var input = "[red]This text will never be red[/]".EscapeMarkup(); + // Given + var console = new TestConsole(); + console.Profile.Capabilities.Interactive = true; + console.Input.PushKey(ConsoleKey.Enter); + var input = "[red]This text will never be red[/]".EscapeMarkup(); - // When - var prompt = new SelectionPrompt() - .Title("Select one") - .AddChoices(input); - prompt.Show(console); + // When + var prompt = new SelectionPrompt() + .Title("Select one") + .AddChoices(input); + prompt.Show(console); - // Then - console.Output.ShouldContain(@"[red]This text will never be red[/]"); - } + // Then + console.Output.ShouldContain(@"[red]This text will never be red[/]"); } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/Prompts/TextPromptTests.cs b/test/Spectre.Console.Tests/Unit/Prompts/TextPromptTests.cs index 2143b5b..a3a8ee3 100644 --- a/test/Spectre.Console.Tests/Unit/Prompts/TextPromptTests.cs +++ b/test/Spectre.Console.Tests/Unit/Prompts/TextPromptTests.cs @@ -1,253 +1,244 @@ -using System; -using System.Threading.Tasks; -using Shouldly; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("Prompts/Text")] +public sealed class TextPromptTests { - [UsesVerify] - [ExpectationPath("Prompts/Text")] - public sealed class TextPromptTests + [Fact] + public void Should_Return_Entered_Text() { - [Fact] - public void Should_Return_Entered_Text() - { - // Given - var console = new TestConsole(); - console.Input.PushTextWithEnter("Hello World"); + // Given + var console = new TestConsole(); + console.Input.PushTextWithEnter("Hello World"); - // When - var result = console.Prompt(new TextPrompt("Enter text:")); + // When + var result = console.Prompt(new TextPrompt("Enter text:")); - // Then - result.ShouldBe("Hello World"); - } - - [Fact] - [Expectation("ConversionError")] - public Task Should_Return_Validation_Error_If_Value_Cannot_Be_Converted() - { - // Given - var console = new TestConsole(); - console.Input.PushTextWithEnter("ninety-nine"); - console.Input.PushTextWithEnter("99"); - - // When - console.Prompt(new TextPrompt("Age?")); - - // Then - return Verifier.Verify(console.Lines); - } - - [Fact] - [Expectation("DefaultValue")] - public Task Should_Chose_Default_Value_If_Nothing_Is_Entered() - { - // Given - var console = new TestConsole(); - console.Input.PushKey(ConsoleKey.Enter); - - // When - console.Prompt( - new TextPrompt("Favorite fruit?") - .AddChoice("Banana") - .AddChoice("Orange") - .DefaultValue("Banana")); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("InvalidChoice")] - public Task Should_Return_Error_If_An_Invalid_Choice_Is_Made() - { - // Given - var console = new TestConsole(); - console.Input.PushTextWithEnter("Apple"); - console.Input.PushTextWithEnter("Banana"); - - // When - console.Prompt( - new TextPrompt("Favorite fruit?") - .AddChoice("Banana") - .AddChoice("Orange") - .DefaultValue("Banana")); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("AcceptChoice")] - public Task Should_Accept_Choice_In_List() - { - // Given - var console = new TestConsole(); - console.Input.PushTextWithEnter("Orange"); - - // When - console.Prompt( - new TextPrompt("Favorite fruit?") - .AddChoice("Banana") - .AddChoice("Orange") - .DefaultValue("Banana")); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("AutoComplete_Empty")] - public Task Should_Auto_Complete_To_First_Choice_If_Pressing_Tab_On_Empty_String() - { - // Given - var console = new TestConsole(); - console.Input.PushKey(ConsoleKey.Tab); - console.Input.PushKey(ConsoleKey.Enter); - - // When - console.Prompt( - new TextPrompt("Favorite fruit?") - .AddChoice("Banana") - .AddChoice("Orange") - .DefaultValue("Banana")); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("AutoComplete_BestMatch")] - public Task Should_Auto_Complete_To_Best_Match() - { - // Given - var console = new TestConsole(); - console.Input.PushText("Band"); - console.Input.PushKey(ConsoleKey.Tab); - console.Input.PushKey(ConsoleKey.Enter); - - // When - console.Prompt( - new TextPrompt("Favorite fruit?") - .AddChoice("Banana") - .AddChoice("Bandana") - .AddChoice("Orange")); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("AutoComplete_NextChoice")] - public Task Should_Auto_Complete_To_Next_Choice_When_Pressing_Tab_On_A_Match() - { - // Given - var console = new TestConsole(); - console.Input.PushText("Apple"); - console.Input.PushKey(ConsoleKey.Tab); - console.Input.PushKey(ConsoleKey.Enter); - - // When - console.Prompt( - new TextPrompt("Favorite fruit?") - .AddChoice("Apple") - .AddChoice("Banana") - .AddChoice("Orange")); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("CustomValidation")] - public Task Should_Return_Error_If_Custom_Validation_Fails() - { - // Given - var console = new TestConsole(); - console.Input.PushTextWithEnter("22"); - console.Input.PushTextWithEnter("102"); - console.Input.PushTextWithEnter("ABC"); - console.Input.PushTextWithEnter("99"); - - // When - console.Prompt( - new TextPrompt("Guess number:") - .ValidationErrorMessage("Invalid input") - .Validate(age => - { - if (age < 99) - { - return ValidationResult.Error("Too low"); - } - else if (age > 99) - { - return ValidationResult.Error("Too high"); - } - - return ValidationResult.Success(); - })); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("CustomConverter")] - public Task Should_Use_Custom_Converter() - { - // Given - var console = new TestConsole(); - console.Input.PushTextWithEnter("Banana"); - - // When - var result = console.Prompt( - new TextPrompt<(int, string)>("Favorite fruit?") - .AddChoice((1, "Apple")) - .AddChoice((2, "Banana")) - .WithConverter(testData => testData.Item2)); - - // Then - result.Item1.ShouldBe(2); - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("SecretDefaultValue")] - public Task Should_Chose_Masked_Default_Value_If_Nothing_Is_Entered_And_Prompt_Is_Secret() - { - // Given - var console = new TestConsole(); - console.Input.PushKey(ConsoleKey.Enter); - - // When - console.Prompt( - new TextPrompt("Favorite fruit?") - .Secret() - .DefaultValue("Banana")); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("NoSuffix")] - [GitHubIssue(413)] - public Task Should_Not_Append_Questionmark_Or_Colon_If_No_Choices_Are_Set() - { - // Given - var console = new TestConsole(); - console.Input.PushTextWithEnter("Orange"); - - // When - console.Prompt( - new TextPrompt("Enter command$")); - - // Then - return Verifier.Verify(console.Output); - } + // Then + result.ShouldBe("Hello World"); } -} \ No newline at end of file + + [Fact] + [Expectation("ConversionError")] + public Task Should_Return_Validation_Error_If_Value_Cannot_Be_Converted() + { + // Given + var console = new TestConsole(); + console.Input.PushTextWithEnter("ninety-nine"); + console.Input.PushTextWithEnter("99"); + + // When + console.Prompt(new TextPrompt("Age?")); + + // Then + return Verifier.Verify(console.Lines); + } + + [Fact] + [Expectation("DefaultValue")] + public Task Should_Chose_Default_Value_If_Nothing_Is_Entered() + { + // Given + var console = new TestConsole(); + console.Input.PushKey(ConsoleKey.Enter); + + // When + console.Prompt( + new TextPrompt("Favorite fruit?") + .AddChoice("Banana") + .AddChoice("Orange") + .DefaultValue("Banana")); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("InvalidChoice")] + public Task Should_Return_Error_If_An_Invalid_Choice_Is_Made() + { + // Given + var console = new TestConsole(); + console.Input.PushTextWithEnter("Apple"); + console.Input.PushTextWithEnter("Banana"); + + // When + console.Prompt( + new TextPrompt("Favorite fruit?") + .AddChoice("Banana") + .AddChoice("Orange") + .DefaultValue("Banana")); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("AcceptChoice")] + public Task Should_Accept_Choice_In_List() + { + // Given + var console = new TestConsole(); + console.Input.PushTextWithEnter("Orange"); + + // When + console.Prompt( + new TextPrompt("Favorite fruit?") + .AddChoice("Banana") + .AddChoice("Orange") + .DefaultValue("Banana")); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("AutoComplete_Empty")] + public Task Should_Auto_Complete_To_First_Choice_If_Pressing_Tab_On_Empty_String() + { + // Given + var console = new TestConsole(); + console.Input.PushKey(ConsoleKey.Tab); + console.Input.PushKey(ConsoleKey.Enter); + + // When + console.Prompt( + new TextPrompt("Favorite fruit?") + .AddChoice("Banana") + .AddChoice("Orange") + .DefaultValue("Banana")); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("AutoComplete_BestMatch")] + public Task Should_Auto_Complete_To_Best_Match() + { + // Given + var console = new TestConsole(); + console.Input.PushText("Band"); + console.Input.PushKey(ConsoleKey.Tab); + console.Input.PushKey(ConsoleKey.Enter); + + // When + console.Prompt( + new TextPrompt("Favorite fruit?") + .AddChoice("Banana") + .AddChoice("Bandana") + .AddChoice("Orange")); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("AutoComplete_NextChoice")] + public Task Should_Auto_Complete_To_Next_Choice_When_Pressing_Tab_On_A_Match() + { + // Given + var console = new TestConsole(); + console.Input.PushText("Apple"); + console.Input.PushKey(ConsoleKey.Tab); + console.Input.PushKey(ConsoleKey.Enter); + + // When + console.Prompt( + new TextPrompt("Favorite fruit?") + .AddChoice("Apple") + .AddChoice("Banana") + .AddChoice("Orange")); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("CustomValidation")] + public Task Should_Return_Error_If_Custom_Validation_Fails() + { + // Given + var console = new TestConsole(); + console.Input.PushTextWithEnter("22"); + console.Input.PushTextWithEnter("102"); + console.Input.PushTextWithEnter("ABC"); + console.Input.PushTextWithEnter("99"); + + // When + console.Prompt( + new TextPrompt("Guess number:") + .ValidationErrorMessage("Invalid input") + .Validate(age => + { + if (age < 99) + { + return ValidationResult.Error("Too low"); + } + else if (age > 99) + { + return ValidationResult.Error("Too high"); + } + + return ValidationResult.Success(); + })); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("CustomConverter")] + public Task Should_Use_Custom_Converter() + { + // Given + var console = new TestConsole(); + console.Input.PushTextWithEnter("Banana"); + + // When + var result = console.Prompt( + new TextPrompt<(int, string)>("Favorite fruit?") + .AddChoice((1, "Apple")) + .AddChoice((2, "Banana")) + .WithConverter(testData => testData.Item2)); + + // Then + result.Item1.ShouldBe(2); + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("SecretDefaultValue")] + public Task Should_Chose_Masked_Default_Value_If_Nothing_Is_Entered_And_Prompt_Is_Secret() + { + // Given + var console = new TestConsole(); + console.Input.PushKey(ConsoleKey.Enter); + + // When + console.Prompt( + new TextPrompt("Favorite fruit?") + .Secret() + .DefaultValue("Banana")); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("NoSuffix")] + [GitHubIssue(413)] + public Task Should_Not_Append_Questionmark_Or_Colon_If_No_Choices_Are_Set() + { + // Given + var console = new TestConsole(); + console.Input.PushTextWithEnter("Orange"); + + // When + console.Prompt( + new TextPrompt("Enter command$")); + + // Then + return Verifier.Verify(console.Output); + } +} diff --git a/test/Spectre.Console.Tests/Unit/RecorderTests.cs b/test/Spectre.Console.Tests/Unit/RecorderTests.cs index 9dfcde0..798cbd6 100644 --- a/test/Spectre.Console.Tests/Unit/RecorderTests.cs +++ b/test/Spectre.Console.Tests/Unit/RecorderTests.cs @@ -1,54 +1,47 @@ -using System.Threading.Tasks; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("Widgets/Recorder")] +public sealed class RecorderTests { - [UsesVerify] - [ExpectationPath("Widgets/Recorder")] - public sealed class RecorderTests + [Fact] + [Expectation("Text")] + public Task Should_Export_Text_As_Expected() { - [Fact] - [Expectation("Text")] - public Task Should_Export_Text_As_Expected() - { - // Given - var console = new TestConsole(); - var recorder = new Recorder(console); + // Given + var console = new TestConsole(); + var recorder = new Recorder(console); - recorder.Write(new Table() - .AddColumns("Foo", "Bar", "Qux") - .AddRow("Corgi", "Waldo", "Zap") - .AddRow(new Panel("Hello World").RoundedBorder())); + recorder.Write(new Table() + .AddColumns("Foo", "Bar", "Qux") + .AddRow("Corgi", "Waldo", "Zap") + .AddRow(new Panel("Hello World").RoundedBorder())); - // When - var result = recorder.ExportText(); + // When + var result = recorder.ExportText(); - // Then - return Verifier.Verify(result); - } - - [Fact] - [Expectation("Html")] - public Task Should_Export_Html_Text_As_Expected() - { - // Given - var console = new TestConsole(); - var recorder = new Recorder(console); - - recorder.Write(new Table() - .AddColumns("[red on black]Foo[/]", "[green bold]Bar[/]", "[blue italic]Qux[/]") - .AddRow("[invert underline]Corgi[/]", "[bold strikethrough]Waldo[/]", "[dim]Zap[/]") - .AddRow(new Panel("[blue]Hello World[/]") - .BorderColor(Color.Red).RoundedBorder())); - - // When - var result = recorder.ExportHtml(); - - // Then - return Verifier.Verify(result); - } + // Then + return Verifier.Verify(result); } -} \ No newline at end of file + + [Fact] + [Expectation("Html")] + public Task Should_Export_Html_Text_As_Expected() + { + // Given + var console = new TestConsole(); + var recorder = new Recorder(console); + + recorder.Write(new Table() + .AddColumns("[red on black]Foo[/]", "[green bold]Bar[/]", "[blue italic]Qux[/]") + .AddRow("[invert underline]Corgi[/]", "[bold strikethrough]Waldo[/]", "[dim]Zap[/]") + .AddRow(new Panel("[blue]Hello World[/]") + .BorderColor(Color.Red).RoundedBorder())); + + // When + var result = recorder.ExportHtml(); + + // Then + return Verifier.Verify(result); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Rendering/Borders/BoxBorderTests.cs b/test/Spectre.Console.Tests/Unit/Rendering/Borders/BoxBorderTests.cs index e52c74a..f16fe97 100644 --- a/test/Spectre.Console.Tests/Unit/Rendering/Borders/BoxBorderTests.cs +++ b/test/Spectre.Console.Tests/Unit/Rendering/Borders/BoxBorderTests.cs @@ -1,210 +1,201 @@ -using System.Threading.Tasks; -using Shouldly; -using Spectre.Console.Rendering; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("Rendering/Borders/Box")] +public sealed class BoxBorderTests { [UsesVerify] - [ExpectationPath("Rendering/Borders/Box")] - public sealed class BoxBorderTests + public sealed class NoBorder { - [UsesVerify] - public sealed class NoBorder - { - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = BoxExtensions.GetSafeBorder(BoxBorder.None, safe: true); - - // Then - border.ShouldBeSameAs(BoxBorder.None); - } - } - - [Fact] - [Expectation("NoBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var panel = Fixture.GetPanel().NoBorder(); - - // When - console.Write(panel); - - // Then - return Verifier.Verify(console.Output); - } - } - - [UsesVerify] - public sealed class AsciiBorder - { - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = BoxExtensions.GetSafeBorder(BoxBorder.Ascii, safe: true); - - // Then - border.ShouldBeSameAs(BoxBorder.Ascii); - } - } - - [Fact] - [Expectation("AsciiBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var panel = Fixture.GetPanel().AsciiBorder(); - - // When - console.Write(panel); - - // Then - return Verifier.Verify(console.Output); - } - } - - [UsesVerify] - public sealed class DoubleBorder - { - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = BoxExtensions.GetSafeBorder(BoxBorder.Double, safe: true); - - // Then - border.ShouldBeSameAs(BoxBorder.Double); - } - } - - [Fact] - [Expectation("DoubleBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var panel = Fixture.GetPanel().DoubleBorder(); - - // When - console.Write(panel); - - // Then - return Verifier.Verify(console.Output); - } - } - - [UsesVerify] - public sealed class HeavyBorder - { - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = BoxExtensions.GetSafeBorder(BoxBorder.Heavy, safe: true); - - // Then - border.ShouldBeSameAs(BoxBorder.Square); - } - } - - [Fact] - [Expectation("HeavyBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var panel = Fixture.GetPanel().HeavyBorder(); - - // When - console.Write(panel); - - // Then - return Verifier.Verify(console.Output); - } - } - - [UsesVerify] - public sealed class RoundedBorder + public sealed class TheSafeGetBorderMethod { [Fact] public void Should_Return_Safe_Border() { // Given, When - var border = BoxExtensions.GetSafeBorder(BoxBorder.Rounded, safe: true); + var border = BoxExtensions.GetSafeBorder(BoxBorder.None, safe: true); // Then - border.ShouldBeSameAs(BoxBorder.Square); - } - - [Fact] - [Expectation("RoundedBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var panel = Fixture.GetPanel().RoundedBorder(); - - // When - console.Write(panel); - - // Then - return Verifier.Verify(console.Output); + border.ShouldBeSameAs(BoxBorder.None); } } - [UsesVerify] - public sealed class SquareBorder + [Fact] + [Expectation("NoBorder")] + public Task Should_Render_As_Expected() { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = BoxExtensions.GetSafeBorder(BoxBorder.Square, safe: true); + // Given + var console = new TestConsole(); + var panel = Fixture.GetPanel().NoBorder(); - // Then - border.ShouldBeSameAs(BoxBorder.Square); - } + // When + console.Write(panel); - [Fact] - [Expectation("SquareBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var panel = Fixture.GetPanel().SquareBorder(); - - // When - console.Write(panel); - - // Then - return Verifier.Verify(console.Output); - } - } - - private static class Fixture - { - public static Panel GetPanel() - { - return new Panel("Hello World") - .Header("Greeting"); - } + // Then + return Verifier.Verify(console.Output); } } -} \ No newline at end of file + + [UsesVerify] + public sealed class AsciiBorder + { + public sealed class TheSafeGetBorderMethod + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = BoxExtensions.GetSafeBorder(BoxBorder.Ascii, safe: true); + + // Then + border.ShouldBeSameAs(BoxBorder.Ascii); + } + } + + [Fact] + [Expectation("AsciiBorder")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var panel = Fixture.GetPanel().AsciiBorder(); + + // When + console.Write(panel); + + // Then + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class DoubleBorder + { + public sealed class TheSafeGetBorderMethod + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = BoxExtensions.GetSafeBorder(BoxBorder.Double, safe: true); + + // Then + border.ShouldBeSameAs(BoxBorder.Double); + } + } + + [Fact] + [Expectation("DoubleBorder")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var panel = Fixture.GetPanel().DoubleBorder(); + + // When + console.Write(panel); + + // Then + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class HeavyBorder + { + public sealed class TheSafeGetBorderMethod + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = BoxExtensions.GetSafeBorder(BoxBorder.Heavy, safe: true); + + // Then + border.ShouldBeSameAs(BoxBorder.Square); + } + } + + [Fact] + [Expectation("HeavyBorder")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var panel = Fixture.GetPanel().HeavyBorder(); + + // When + console.Write(panel); + + // Then + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class RoundedBorder + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = BoxExtensions.GetSafeBorder(BoxBorder.Rounded, safe: true); + + // Then + border.ShouldBeSameAs(BoxBorder.Square); + } + + [Fact] + [Expectation("RoundedBorder")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var panel = Fixture.GetPanel().RoundedBorder(); + + // When + console.Write(panel); + + // Then + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class SquareBorder + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = BoxExtensions.GetSafeBorder(BoxBorder.Square, safe: true); + + // Then + border.ShouldBeSameAs(BoxBorder.Square); + } + + [Fact] + [Expectation("SquareBorder")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var panel = Fixture.GetPanel().SquareBorder(); + + // When + console.Write(panel); + + // Then + return Verifier.Verify(console.Output); + } + } + + private static class Fixture + { + public static Panel GetPanel() + { + return new Panel("Hello World") + .Header("Greeting"); + } + } +} diff --git a/test/Spectre.Console.Tests/Unit/Rendering/Borders/TableBorderTests.cs b/test/Spectre.Console.Tests/Unit/Rendering/Borders/TableBorderTests.cs index f63b4f8..a9177f2 100644 --- a/test/Spectre.Console.Tests/Unit/Rendering/Borders/TableBorderTests.cs +++ b/test/Spectre.Console.Tests/Unit/Rendering/Borders/TableBorderTests.cs @@ -1,829 +1,820 @@ -using System.Threading.Tasks; -using Shouldly; -using Spectre.Console.Rendering; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("Rendering/Borders/Table")] +public sealed class TableBorderTests { [UsesVerify] - [ExpectationPath("Rendering/Borders/Table")] - public sealed class TableBorderTests + public sealed class NoBorder { - [UsesVerify] - public sealed class NoBorder + [Fact] + public void Should_Return_Correct_Visibility() + { + // Given, When + var visibility = TableBorder.None.Visible; + + // Then + visibility.ShouldBeFalse(); + } + + public sealed class TheSafeGetBorderMethod { [Fact] - public void Should_Return_Correct_Visibility() + public void Should_Return_Safe_Border() { // Given, When - var visibility = TableBorder.None.Visible; + var border = TableBorder.None.GetSafeBorder(safe: true); // Then - visibility.ShouldBeFalse(); - } - - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = TableBorder.None.GetSafeBorder(safe: true); - - // Then - border.ShouldBeSameAs(TableBorder.None); - } - } - - [Fact] - [Expectation("NoBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var table = Fixture.GetTable().NoBorder(); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); + border.ShouldBeSameAs(TableBorder.None); } } - [UsesVerify] - public sealed class AsciiBorder + [Fact] + [Expectation("NoBorder")] + public Task Should_Render_As_Expected() { - [Fact] - public void Should_Return_Correct_Visibility() - { - // Given, When - var visibility = TableBorder.Ascii.Visible; + // Given + var console = new TestConsole(); + var table = Fixture.GetTable().NoBorder(); - // Then - visibility.ShouldBeTrue(); - } + // When + console.Write(table); - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = TableBorder.Ascii.GetSafeBorder(safe: true); - - // Then - border.ShouldBeSameAs(TableBorder.Ascii); - } - } - - [Fact] - [Expectation("AsciiBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var table = Fixture.GetTable().AsciiBorder(); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - } - - [UsesVerify] - public sealed class Ascii2Border - { - [Fact] - public void Should_Return_Correct_Visibility() - { - // Given, When - var visibility = TableBorder.Ascii2.Visible; - - // Then - visibility.ShouldBeTrue(); - } - - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = TableBorder.Ascii2.GetSafeBorder(safe: true); - - // Then - border.ShouldBeSameAs(TableBorder.Ascii2); - } - } - - [Fact] - [Expectation("Ascii2Border")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var table = Fixture.GetTable().Ascii2Border(); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - } - - [UsesVerify] - public sealed class AsciiDoubleHeadBorder - { - [Fact] - public void Should_Return_Correct_Visibility() - { - // Given, When - var visibility = TableBorder.AsciiDoubleHead.Visible; - - // Then - visibility.ShouldBeTrue(); - } - - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = TableBorder.AsciiDoubleHead.GetSafeBorder(safe: true); - - // Then - border.ShouldBeSameAs(TableBorder.AsciiDoubleHead); - } - } - - [Fact] - [Expectation("AsciiDoubleHeadBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var table = Fixture.GetTable().AsciiDoubleHeadBorder(); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - } - - [UsesVerify] - public sealed class SquareBorder - { - [Fact] - public void Should_Return_Correct_Visibility() - { - // Given, When - var visibility = TableBorder.Square.Visible; - - // Then - visibility.ShouldBeTrue(); - } - - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = TableBorder.Square.GetSafeBorder(safe: true); - - // Then - border.ShouldBeSameAs(TableBorder.Square); - } - } - - [Fact] - [Expectation("SquareBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var table = Fixture.GetTable().SquareBorder(); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - } - - [UsesVerify] - public sealed class RoundedBorder - { - [Fact] - public void Should_Return_Correct_Visibility() - { - // Given, When - var visibility = TableBorder.Rounded.Visible; - - // Then - visibility.ShouldBeTrue(); - } - - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = TableBorder.Rounded.GetSafeBorder(safe: true); - - // Then - border.ShouldBeSameAs(TableBorder.Square); - } - } - - [Fact] - [Expectation("RoundedBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var table = Fixture.GetTable().RoundedBorder(); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - } - - [UsesVerify] - public sealed class MinimalBorder - { - [Fact] - public void Should_Return_Correct_Visibility() - { - // Given, When - var visibility = TableBorder.Minimal.Visible; - - // Then - visibility.ShouldBeTrue(); - } - - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = TableBorder.Minimal.GetSafeBorder(safe: true); - - // Then - border.ShouldBeSameAs(TableBorder.Minimal); - } - } - - [Fact] - [Expectation("MinimalBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var table = Fixture.GetTable().MinimalBorder(); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - } - - [UsesVerify] - public sealed class MinimalHeavyHeadBorder - { - [Fact] - public void Should_Return_Correct_Visibility() - { - // Given, When - var visibility = TableBorder.MinimalHeavyHead.Visible; - - // Then - visibility.ShouldBeTrue(); - } - - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = TableBorder.MinimalHeavyHead.GetSafeBorder(safe: true); - - // Then - border.ShouldBeSameAs(TableBorder.Minimal); - } - } - - [Fact] - [Expectation("MinimalHeavyHeadBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var table = Fixture.GetTable().MinimalHeavyHeadBorder(); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - } - - [UsesVerify] - public sealed class MinimalDoubleHeadBorder - { - [Fact] - public void Should_Return_Correct_Visibility() - { - // Given, When - var visibility = TableBorder.MinimalDoubleHead.Visible; - - // Then - visibility.ShouldBeTrue(); - } - - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = TableBorder.MinimalDoubleHead.GetSafeBorder(safe: true); - - // Then - border.ShouldBeSameAs(TableBorder.MinimalDoubleHead); - } - } - - [Fact] - [Expectation("MinimalDoubleHeadBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var table = Fixture.GetTable().MinimalDoubleHeadBorder(); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - } - - [UsesVerify] - public sealed class SimpleBorder - { - [Fact] - public void Should_Return_Correct_Visibility() - { - // Given, When - var visibility = TableBorder.Simple.Visible; - - // Then - visibility.ShouldBeTrue(); - } - - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = TableBorder.Simple.GetSafeBorder(safe: true); - - // Then - border.ShouldBeSameAs(TableBorder.Simple); - } - } - - [Fact] - [Expectation("SimpleBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var table = Fixture.GetTable().SimpleBorder(); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - } - - [UsesVerify] - public sealed class HorizontalBorder - { - [Fact] - public void Should_Return_Correct_Visibility() - { - // Given, When - var visibility = TableBorder.Horizontal.Visible; - - // Then - visibility.ShouldBeTrue(); - } - - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = TableBorder.Horizontal.GetSafeBorder(safe: true); - - // Then - border.ShouldBeSameAs(TableBorder.Horizontal); - } - } - - [Fact] - [Expectation("HorizontalBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var table = Fixture.GetTable().HorizontalBorder(); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - } - - [UsesVerify] - public sealed class SimpleHeavyBorder - { - [Fact] - public void Should_Return_Correct_Visibility() - { - // Given, When - var visibility = TableBorder.SimpleHeavy.Visible; - - // Then - visibility.ShouldBeTrue(); - } - - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = TableBorder.SimpleHeavy.GetSafeBorder(safe: true); - - // Then - border.ShouldBeSameAs(TableBorder.Simple); - } - } - - [Fact] - [Expectation("SimpleHeavyBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var table = Fixture.GetTable().SimpleHeavyBorder(); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - } - - [UsesVerify] - public sealed class HeavyBorder - { - [Fact] - public void Should_Return_Correct_Visibility() - { - // Given, When - var visibility = TableBorder.Heavy.Visible; - - // Then - visibility.ShouldBeTrue(); - } - - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = TableBorder.Heavy.GetSafeBorder(safe: true); - - // Then - border.ShouldBeSameAs(TableBorder.Square); - } - } - - [Fact] - [Expectation("HeavyBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var table = Fixture.GetTable().HeavyBorder(); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - } - - [UsesVerify] - public sealed class HeavyEdgeBorder - { - [Fact] - public void Should_Return_Correct_Visibility() - { - // Given, When - var visibility = TableBorder.HeavyEdge.Visible; - - // Then - visibility.ShouldBeTrue(); - } - - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = TableBorder.HeavyEdge.GetSafeBorder(safe: true); - - // Then - border.ShouldBeSameAs(TableBorder.Square); - } - } - - [Fact] - [Expectation("HeavyEdgeBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var table = Fixture.GetTable().HeavyEdgeBorder(); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - } - - [UsesVerify] - public sealed class HeavyHeadBorder - { - [Fact] - public void Should_Return_Correct_Visibility() - { - // Given, When - var visibility = TableBorder.HeavyHead.Visible; - - // Then - visibility.ShouldBeTrue(); - } - - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = TableBorder.HeavyHead.GetSafeBorder(safe: true); - - // Then - border.ShouldBeSameAs(TableBorder.Square); - } - } - - [Fact] - [Expectation("HeavyHeadBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var table = Fixture.GetTable().HeavyHeadBorder(); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - } - - [UsesVerify] - public sealed class DoubleBorder - { - [Fact] - public void Should_Return_Correct_Visibility() - { - // Given, When - var visibility = TableBorder.Double.Visible; - - // Then - visibility.ShouldBeTrue(); - } - - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = TableBorder.Double.GetSafeBorder(safe: true); - - // Then - border.ShouldBeSameAs(TableBorder.Double); - } - } - - [Fact] - [Expectation("DoubleBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var table = Fixture.GetTable().DoubleBorder(); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - } - - [UsesVerify] - public sealed class DoubleEdgeBorder - { - [Fact] - public void Should_Return_Correct_Visibility() - { - // Given, When - var visibility = TableBorder.DoubleEdge.Visible; - - // Then - visibility.ShouldBeTrue(); - } - - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = TableBorder.DoubleEdge.GetSafeBorder(safe: true); - - // Then - border.ShouldBeSameAs(TableBorder.DoubleEdge); - } - } - - [Fact] - [Expectation("DoubleEdgeBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var table = Fixture.GetTable().DoubleEdgeBorder(); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - } - - [UsesVerify] - public sealed class MarkdownBorder - { - [Fact] - public void Should_Return_Correct_Visibility() - { - // Given, When - var visibility = TableBorder.Markdown.Visible; - - // Then - visibility.ShouldBeTrue(); - } - - public sealed class TheSafeGetBorderMethod - { - [Fact] - public void Should_Return_Safe_Border() - { - // Given, When - var border = TableBorder.Markdown.GetSafeBorder(safe: true); - - // Then - border.ShouldBeSameAs(TableBorder.Markdown); - } - } - - [Fact] - [Expectation("MarkdownBorder")] - public Task Should_Render_As_Expected() - { - // Given - var console = new TestConsole(); - var table = Fixture.GetTable().MarkdownBorder(); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("MarkdownBorder_LeftAligned")] - public Task Should_Render_Left_Aligned_Table_Columns_As_Expected() - { - // Given - var console = new TestConsole(); - var table = Fixture.GetTable(header2: Justify.Left).MarkdownBorder(); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("MarkdownBorder_Centered")] - public Task Should_Render_Center_Aligned_Table_Columns_As_Expected() - { - // Given - var console = new TestConsole(); - var table = Fixture.GetTable(header2: Justify.Center).MarkdownBorder(); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("MarkdownBorder_RightAligned")] - public Task Should_Render_Right_Aligned_Table_Columns_As_Expected() - { - // Given - var console = new TestConsole(); - var table = Fixture.GetTable(header2: Justify.Right).MarkdownBorder(); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - } - - private static class Fixture - { - public static Table GetTable(Justify? header1 = null, Justify? header2 = null) - { - var table = new Table(); - table.AddColumn("Header 1", c => c.Alignment(header1).Footer("Footer 1")); - table.AddColumn("Header 2", c => c.Alignment(header2).Footer("Footer 2")); - table.AddRow("Cell", "Cell"); - table.AddRow("Cell", "Cell"); - return table; - } + // Then + return Verifier.Verify(console.Output); } } -} \ No newline at end of file + + [UsesVerify] + public sealed class AsciiBorder + { + [Fact] + public void Should_Return_Correct_Visibility() + { + // Given, When + var visibility = TableBorder.Ascii.Visible; + + // Then + visibility.ShouldBeTrue(); + } + + public sealed class TheSafeGetBorderMethod + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = TableBorder.Ascii.GetSafeBorder(safe: true); + + // Then + border.ShouldBeSameAs(TableBorder.Ascii); + } + } + + [Fact] + [Expectation("AsciiBorder")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var table = Fixture.GetTable().AsciiBorder(); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class Ascii2Border + { + [Fact] + public void Should_Return_Correct_Visibility() + { + // Given, When + var visibility = TableBorder.Ascii2.Visible; + + // Then + visibility.ShouldBeTrue(); + } + + public sealed class TheSafeGetBorderMethod + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = TableBorder.Ascii2.GetSafeBorder(safe: true); + + // Then + border.ShouldBeSameAs(TableBorder.Ascii2); + } + } + + [Fact] + [Expectation("Ascii2Border")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var table = Fixture.GetTable().Ascii2Border(); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class AsciiDoubleHeadBorder + { + [Fact] + public void Should_Return_Correct_Visibility() + { + // Given, When + var visibility = TableBorder.AsciiDoubleHead.Visible; + + // Then + visibility.ShouldBeTrue(); + } + + public sealed class TheSafeGetBorderMethod + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = TableBorder.AsciiDoubleHead.GetSafeBorder(safe: true); + + // Then + border.ShouldBeSameAs(TableBorder.AsciiDoubleHead); + } + } + + [Fact] + [Expectation("AsciiDoubleHeadBorder")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var table = Fixture.GetTable().AsciiDoubleHeadBorder(); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class SquareBorder + { + [Fact] + public void Should_Return_Correct_Visibility() + { + // Given, When + var visibility = TableBorder.Square.Visible; + + // Then + visibility.ShouldBeTrue(); + } + + public sealed class TheSafeGetBorderMethod + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = TableBorder.Square.GetSafeBorder(safe: true); + + // Then + border.ShouldBeSameAs(TableBorder.Square); + } + } + + [Fact] + [Expectation("SquareBorder")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var table = Fixture.GetTable().SquareBorder(); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class RoundedBorder + { + [Fact] + public void Should_Return_Correct_Visibility() + { + // Given, When + var visibility = TableBorder.Rounded.Visible; + + // Then + visibility.ShouldBeTrue(); + } + + public sealed class TheSafeGetBorderMethod + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = TableBorder.Rounded.GetSafeBorder(safe: true); + + // Then + border.ShouldBeSameAs(TableBorder.Square); + } + } + + [Fact] + [Expectation("RoundedBorder")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var table = Fixture.GetTable().RoundedBorder(); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class MinimalBorder + { + [Fact] + public void Should_Return_Correct_Visibility() + { + // Given, When + var visibility = TableBorder.Minimal.Visible; + + // Then + visibility.ShouldBeTrue(); + } + + public sealed class TheSafeGetBorderMethod + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = TableBorder.Minimal.GetSafeBorder(safe: true); + + // Then + border.ShouldBeSameAs(TableBorder.Minimal); + } + } + + [Fact] + [Expectation("MinimalBorder")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var table = Fixture.GetTable().MinimalBorder(); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class MinimalHeavyHeadBorder + { + [Fact] + public void Should_Return_Correct_Visibility() + { + // Given, When + var visibility = TableBorder.MinimalHeavyHead.Visible; + + // Then + visibility.ShouldBeTrue(); + } + + public sealed class TheSafeGetBorderMethod + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = TableBorder.MinimalHeavyHead.GetSafeBorder(safe: true); + + // Then + border.ShouldBeSameAs(TableBorder.Minimal); + } + } + + [Fact] + [Expectation("MinimalHeavyHeadBorder")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var table = Fixture.GetTable().MinimalHeavyHeadBorder(); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class MinimalDoubleHeadBorder + { + [Fact] + public void Should_Return_Correct_Visibility() + { + // Given, When + var visibility = TableBorder.MinimalDoubleHead.Visible; + + // Then + visibility.ShouldBeTrue(); + } + + public sealed class TheSafeGetBorderMethod + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = TableBorder.MinimalDoubleHead.GetSafeBorder(safe: true); + + // Then + border.ShouldBeSameAs(TableBorder.MinimalDoubleHead); + } + } + + [Fact] + [Expectation("MinimalDoubleHeadBorder")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var table = Fixture.GetTable().MinimalDoubleHeadBorder(); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class SimpleBorder + { + [Fact] + public void Should_Return_Correct_Visibility() + { + // Given, When + var visibility = TableBorder.Simple.Visible; + + // Then + visibility.ShouldBeTrue(); + } + + public sealed class TheSafeGetBorderMethod + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = TableBorder.Simple.GetSafeBorder(safe: true); + + // Then + border.ShouldBeSameAs(TableBorder.Simple); + } + } + + [Fact] + [Expectation("SimpleBorder")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var table = Fixture.GetTable().SimpleBorder(); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class HorizontalBorder + { + [Fact] + public void Should_Return_Correct_Visibility() + { + // Given, When + var visibility = TableBorder.Horizontal.Visible; + + // Then + visibility.ShouldBeTrue(); + } + + public sealed class TheSafeGetBorderMethod + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = TableBorder.Horizontal.GetSafeBorder(safe: true); + + // Then + border.ShouldBeSameAs(TableBorder.Horizontal); + } + } + + [Fact] + [Expectation("HorizontalBorder")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var table = Fixture.GetTable().HorizontalBorder(); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class SimpleHeavyBorder + { + [Fact] + public void Should_Return_Correct_Visibility() + { + // Given, When + var visibility = TableBorder.SimpleHeavy.Visible; + + // Then + visibility.ShouldBeTrue(); + } + + public sealed class TheSafeGetBorderMethod + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = TableBorder.SimpleHeavy.GetSafeBorder(safe: true); + + // Then + border.ShouldBeSameAs(TableBorder.Simple); + } + } + + [Fact] + [Expectation("SimpleHeavyBorder")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var table = Fixture.GetTable().SimpleHeavyBorder(); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class HeavyBorder + { + [Fact] + public void Should_Return_Correct_Visibility() + { + // Given, When + var visibility = TableBorder.Heavy.Visible; + + // Then + visibility.ShouldBeTrue(); + } + + public sealed class TheSafeGetBorderMethod + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = TableBorder.Heavy.GetSafeBorder(safe: true); + + // Then + border.ShouldBeSameAs(TableBorder.Square); + } + } + + [Fact] + [Expectation("HeavyBorder")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var table = Fixture.GetTable().HeavyBorder(); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class HeavyEdgeBorder + { + [Fact] + public void Should_Return_Correct_Visibility() + { + // Given, When + var visibility = TableBorder.HeavyEdge.Visible; + + // Then + visibility.ShouldBeTrue(); + } + + public sealed class TheSafeGetBorderMethod + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = TableBorder.HeavyEdge.GetSafeBorder(safe: true); + + // Then + border.ShouldBeSameAs(TableBorder.Square); + } + } + + [Fact] + [Expectation("HeavyEdgeBorder")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var table = Fixture.GetTable().HeavyEdgeBorder(); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class HeavyHeadBorder + { + [Fact] + public void Should_Return_Correct_Visibility() + { + // Given, When + var visibility = TableBorder.HeavyHead.Visible; + + // Then + visibility.ShouldBeTrue(); + } + + public sealed class TheSafeGetBorderMethod + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = TableBorder.HeavyHead.GetSafeBorder(safe: true); + + // Then + border.ShouldBeSameAs(TableBorder.Square); + } + } + + [Fact] + [Expectation("HeavyHeadBorder")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var table = Fixture.GetTable().HeavyHeadBorder(); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class DoubleBorder + { + [Fact] + public void Should_Return_Correct_Visibility() + { + // Given, When + var visibility = TableBorder.Double.Visible; + + // Then + visibility.ShouldBeTrue(); + } + + public sealed class TheSafeGetBorderMethod + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = TableBorder.Double.GetSafeBorder(safe: true); + + // Then + border.ShouldBeSameAs(TableBorder.Double); + } + } + + [Fact] + [Expectation("DoubleBorder")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var table = Fixture.GetTable().DoubleBorder(); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class DoubleEdgeBorder + { + [Fact] + public void Should_Return_Correct_Visibility() + { + // Given, When + var visibility = TableBorder.DoubleEdge.Visible; + + // Then + visibility.ShouldBeTrue(); + } + + public sealed class TheSafeGetBorderMethod + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = TableBorder.DoubleEdge.GetSafeBorder(safe: true); + + // Then + border.ShouldBeSameAs(TableBorder.DoubleEdge); + } + } + + [Fact] + [Expectation("DoubleEdgeBorder")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var table = Fixture.GetTable().DoubleEdgeBorder(); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class MarkdownBorder + { + [Fact] + public void Should_Return_Correct_Visibility() + { + // Given, When + var visibility = TableBorder.Markdown.Visible; + + // Then + visibility.ShouldBeTrue(); + } + + public sealed class TheSafeGetBorderMethod + { + [Fact] + public void Should_Return_Safe_Border() + { + // Given, When + var border = TableBorder.Markdown.GetSafeBorder(safe: true); + + // Then + border.ShouldBeSameAs(TableBorder.Markdown); + } + } + + [Fact] + [Expectation("MarkdownBorder")] + public Task Should_Render_As_Expected() + { + // Given + var console = new TestConsole(); + var table = Fixture.GetTable().MarkdownBorder(); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("MarkdownBorder_LeftAligned")] + public Task Should_Render_Left_Aligned_Table_Columns_As_Expected() + { + // Given + var console = new TestConsole(); + var table = Fixture.GetTable(header2: Justify.Left).MarkdownBorder(); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("MarkdownBorder_Centered")] + public Task Should_Render_Center_Aligned_Table_Columns_As_Expected() + { + // Given + var console = new TestConsole(); + var table = Fixture.GetTable(header2: Justify.Center).MarkdownBorder(); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("MarkdownBorder_RightAligned")] + public Task Should_Render_Right_Aligned_Table_Columns_As_Expected() + { + // Given + var console = new TestConsole(); + var table = Fixture.GetTable(header2: Justify.Right).MarkdownBorder(); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + } + + private static class Fixture + { + public static Table GetTable(Justify? header1 = null, Justify? header2 = null) + { + var table = new Table(); + table.AddColumn("Header 1", c => c.Alignment(header1).Footer("Footer 1")); + table.AddColumn("Header 2", c => c.Alignment(header2).Footer("Footer 2")); + table.AddRow("Cell", "Cell"); + table.AddRow("Cell", "Cell"); + return table; + } + } +} diff --git a/test/Spectre.Console.Tests/Unit/Rendering/RenderHookTests.cs b/test/Spectre.Console.Tests/Unit/Rendering/RenderHookTests.cs index d3ff1ae..219a13d 100644 --- a/test/Spectre.Console.Tests/Unit/Rendering/RenderHookTests.cs +++ b/test/Spectre.Console.Tests/Unit/Rendering/RenderHookTests.cs @@ -1,35 +1,27 @@ -using System.Collections.Generic; -using System.Linq; -using Shouldly; -using Spectre.Console.Rendering; -using Spectre.Console.Testing; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +public sealed class RenderHookTests { - public sealed class RenderHookTests + private sealed class HelloRenderHook : IRenderHook { - private sealed class HelloRenderHook : IRenderHook + public IEnumerable Process(RenderContext context, IEnumerable renderables) { - public IEnumerable Process(RenderContext context, IEnumerable renderables) - { - return new IRenderable[] { new Text("Hello\n") }.Concat(renderables); - } - } - - [Fact] - public void Should_Inject_Renderable_Before_Writing_To_Console() - { - // Given - var console = new TestConsole(); - console.Pipeline.Attach(new HelloRenderHook()); - - // When - console.Write(new Text("World")); - - // Then - console.Lines[0].ShouldBe("Hello"); - console.Lines[1].ShouldBe("World"); + return new IRenderable[] { new Text("Hello\n") }.Concat(renderables); } } -} \ No newline at end of file + + [Fact] + public void Should_Inject_Renderable_Before_Writing_To_Console() + { + // Given + var console = new TestConsole(); + console.Pipeline.Attach(new HelloRenderHook()); + + // When + console.Write(new Text("World")); + + // Then + console.Lines[0].ShouldBe("Hello"); + console.Lines[1].ShouldBe("World"); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Rendering/SegmentTests.cs b/test/Spectre.Console.Tests/Unit/Rendering/SegmentTests.cs index 42745d2..9d5eca8 100644 --- a/test/Spectre.Console.Tests/Unit/Rendering/SegmentTests.cs +++ b/test/Spectre.Console.Tests/Unit/Rendering/SegmentTests.cs @@ -1,95 +1,90 @@ -using Shouldly; -using Spectre.Console.Rendering; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +public sealed class SegmentTests { - public sealed class SegmentTests + [UsesVerify] + public sealed class TheSplitMethod { - [UsesVerify] - public sealed class TheSplitMethod + [Theory] + [InlineData("Foo Bar", 0, "", "Foo Bar")] + [InlineData("Foo Bar", 1, "F", "oo Bar")] + [InlineData("Foo Bar", 2, "Fo", "o Bar")] + [InlineData("Foo Bar", 3, "Foo", " Bar")] + [InlineData("Foo Bar", 4, "Foo ", "Bar")] + [InlineData("Foo Bar", 5, "Foo B", "ar")] + [InlineData("Foo Bar", 6, "Foo Ba", "r")] + [InlineData("Foo Bar", 7, "Foo Bar", null)] + [InlineData("Foo 测试 Bar", 0, "", "Foo 测试 Bar")] + [InlineData("Foo 测试 Bar", 1, "F", "oo 测试 Bar")] + [InlineData("Foo 测试 Bar", 2, "Fo", "o 测试 Bar")] + [InlineData("Foo 测试 Bar", 3, "Foo", " 测试 Bar")] + [InlineData("Foo 测试 Bar", 4, "Foo ", "测试 Bar")] + [InlineData("Foo 测试 Bar", 5, "Foo 测", "试 Bar")] + [InlineData("Foo 测试 Bar", 6, "Foo 测", "试 Bar")] + [InlineData("Foo 测试 Bar", 7, "Foo 测试", " Bar")] + [InlineData("Foo 测试 Bar", 8, "Foo 测试", " Bar")] + [InlineData("Foo 测试 Bar", 9, "Foo 测试 ", "Bar")] + [InlineData("Foo 测试 Bar", 10, "Foo 测试 B", "ar")] + [InlineData("Foo 测试 Bar", 11, "Foo 测试 Ba", "r")] + [InlineData("Foo 测试 Bar", 12, "Foo 测试 Bar", null)] + public void Should_Split_Segment_Correctly(string text, int offset, string expectedFirst, string expectedSecond) { - [Theory] - [InlineData("Foo Bar", 0, "", "Foo Bar")] - [InlineData("Foo Bar", 1, "F", "oo Bar")] - [InlineData("Foo Bar", 2, "Fo", "o Bar")] - [InlineData("Foo Bar", 3, "Foo", " Bar")] - [InlineData("Foo Bar", 4, "Foo ", "Bar")] - [InlineData("Foo Bar", 5, "Foo B", "ar")] - [InlineData("Foo Bar", 6, "Foo Ba", "r")] - [InlineData("Foo Bar", 7, "Foo Bar", null)] - [InlineData("Foo 测试 Bar", 0, "", "Foo 测试 Bar")] - [InlineData("Foo 测试 Bar", 1, "F", "oo 测试 Bar")] - [InlineData("Foo 测试 Bar", 2, "Fo", "o 测试 Bar")] - [InlineData("Foo 测试 Bar", 3, "Foo", " 测试 Bar")] - [InlineData("Foo 测试 Bar", 4, "Foo ", "测试 Bar")] - [InlineData("Foo 测试 Bar", 5, "Foo 测", "试 Bar")] - [InlineData("Foo 测试 Bar", 6, "Foo 测", "试 Bar")] - [InlineData("Foo 测试 Bar", 7, "Foo 测试", " Bar")] - [InlineData("Foo 测试 Bar", 8, "Foo 测试", " Bar")] - [InlineData("Foo 测试 Bar", 9, "Foo 测试 ", "Bar")] - [InlineData("Foo 测试 Bar", 10, "Foo 测试 B", "ar")] - [InlineData("Foo 测试 Bar", 11, "Foo 测试 Ba", "r")] - [InlineData("Foo 测试 Bar", 12, "Foo 测试 Bar", null)] - public void Should_Split_Segment_Correctly(string text, int offset, string expectedFirst, string expectedSecond) - { - // Given - var style = new Style(Color.Red, Color.Green, Decoration.Bold); - var segment = new Segment(text, style); + // Given + var style = new Style(Color.Red, Color.Green, Decoration.Bold); + var segment = new Segment(text, style); - // When - var (first, second) = segment.Split(offset); + // When + var (first, second) = segment.Split(offset); - // Then - first.Text.ShouldBe(expectedFirst); - first.Style.ShouldBe(style); - second?.Text?.ShouldBe(expectedSecond); - second?.Style?.ShouldBe(style); - } + // Then + first.Text.ShouldBe(expectedFirst); + first.Style.ShouldBe(style); + second?.Text?.ShouldBe(expectedSecond); + second?.Style?.ShouldBe(style); + } + } + + [UsesVerify] + public sealed class TheSplitLinesMethod + { + [Fact] + public void Should_Split_Segment() + { + // Given, When + var lines = Segment.SplitLines( + new[] + { + new Segment("Foo"), + new Segment("Bar"), + new Segment("\n"), + new Segment("Baz"), + new Segment("Qux"), + new Segment("\n"), + new Segment("Corgi"), + }); + + // Then + lines.Count.ShouldBe(3); + + lines[0].Count.ShouldBe(2); + lines[0][0].Text.ShouldBe("Foo"); + lines[0][1].Text.ShouldBe("Bar"); + + lines[1].Count.ShouldBe(2); + lines[1][0].Text.ShouldBe("Baz"); + lines[1][1].Text.ShouldBe("Qux"); + + lines[2].Count.ShouldBe(1); + lines[2][0].Text.ShouldBe("Corgi"); } - [UsesVerify] - public sealed class TheSplitLinesMethod + [Fact] + public void Should_Split_Segment_With_Windows_LineBreak() { - [Fact] - public void Should_Split_Segment() - { - // Given, When - var lines = Segment.SplitLines( - new[] - { - new Segment("Foo"), - new Segment("Bar"), - new Segment("\n"), - new Segment("Baz"), - new Segment("Qux"), - new Segment("\n"), - new Segment("Corgi"), - }); - - // Then - lines.Count.ShouldBe(3); - - lines[0].Count.ShouldBe(2); - lines[0][0].Text.ShouldBe("Foo"); - lines[0][1].Text.ShouldBe("Bar"); - - lines[1].Count.ShouldBe(2); - lines[1][0].Text.ShouldBe("Baz"); - lines[1][1].Text.ShouldBe("Qux"); - - lines[2].Count.ShouldBe(1); - lines[2][0].Text.ShouldBe("Corgi"); - } - - [Fact] - public void Should_Split_Segment_With_Windows_LineBreak() - { - // Given, When - var lines = Segment.SplitLines( - new[] - { + // Given, When + var lines = Segment.SplitLines( + new[] + { new Segment("Foo"), new Segment("Bar"), new Segment("\r\n"), @@ -97,53 +92,52 @@ namespace Spectre.Console.Tests.Unit new Segment("Qux"), new Segment("\r\n"), new Segment("Corgi"), - }); + }); - // Then - lines.Count.ShouldBe(3); + // Then + lines.Count.ShouldBe(3); - lines[0].Count.ShouldBe(2); - lines[0][0].Text.ShouldBe("Foo"); - lines[0][1].Text.ShouldBe("Bar"); + lines[0].Count.ShouldBe(2); + lines[0][0].Text.ShouldBe("Foo"); + lines[0][1].Text.ShouldBe("Bar"); - lines[1].Count.ShouldBe(2); - lines[1][0].Text.ShouldBe("Baz"); - lines[1][1].Text.ShouldBe("Qux"); + lines[1].Count.ShouldBe(2); + lines[1][0].Text.ShouldBe("Baz"); + lines[1][1].Text.ShouldBe("Qux"); - lines[2].Count.ShouldBe(1); - lines[2][0].Text.ShouldBe("Corgi"); - } + lines[2].Count.ShouldBe(1); + lines[2][0].Text.ShouldBe("Corgi"); + } - [Fact] - public void Should_Split_Segments_With_Linebreak_In_Text() - { - // Given, Given - var lines = Segment.SplitLines( - new[] - { + [Fact] + public void Should_Split_Segments_With_Linebreak_In_Text() + { + // Given, Given + var lines = Segment.SplitLines( + new[] + { new Segment("Foo\n"), new Segment("Bar\n"), new Segment("Baz"), new Segment("Qux\n"), new Segment("Corgi"), - }); + }); - // Then - lines.Count.ShouldBe(4); + // Then + lines.Count.ShouldBe(4); - lines[0].Count.ShouldBe(1); - lines[0][0].Text.ShouldBe("Foo"); + lines[0].Count.ShouldBe(1); + lines[0][0].Text.ShouldBe("Foo"); - lines[1].Count.ShouldBe(1); - lines[1][0].Text.ShouldBe("Bar"); + lines[1].Count.ShouldBe(1); + lines[1][0].Text.ShouldBe("Bar"); - lines[2].Count.ShouldBe(2); - lines[2][0].Text.ShouldBe("Baz"); - lines[2][1].Text.ShouldBe("Qux"); + lines[2].Count.ShouldBe(2); + lines[2][0].Text.ShouldBe("Baz"); + lines[2][1].Text.ShouldBe("Qux"); - lines[3].Count.ShouldBe(1); - lines[3][0].Text.ShouldBe("Corgi"); - } + lines[3].Count.ShouldBe(1); + lines[3][0].Text.ShouldBe("Corgi"); } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/StyleTests.cs b/test/Spectre.Console.Tests/Unit/StyleTests.cs index 7d6d40d..5213ed9 100644 --- a/test/Spectre.Console.Tests/Unit/StyleTests.cs +++ b/test/Spectre.Console.Tests/Unit/StyleTests.cs @@ -1,401 +1,396 @@ -using System; -using Shouldly; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +public sealed class StyleTests { - public sealed class StyleTests + [Fact] + public void Should_Combine_Two_Styles_As_Expected() + { + // Given + var first = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic); + var other = new Style(Color.Green, Color.Silver, Decoration.Underline, "https://example.com"); + + // When + var result = first.Combine(other); + + // Then + result.Foreground.ShouldBe(Color.Green); + result.Background.ShouldBe(Color.Silver); + result.Decoration.ShouldBe(Decoration.Bold | Decoration.Italic | Decoration.Underline); + result.Link.ShouldBe("https://example.com"); + } + + [Fact] + public void Should_Consider_Two_Identical_Styles_Equal() + { + // Given + var first = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://example.com"); + var second = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://example.com"); + + // When + var result = first.Equals(second); + + // Then + result.ShouldBeTrue(); + } + + [Fact] + public void Should_Not_Consider_Two_Styles_With_Different_Foreground_Colors_Equal() + { + // Given + var first = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://example.com"); + var second = new Style(Color.Blue, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://example.com"); + + // When + var result = first.Equals(second); + + // Then + result.ShouldBeFalse(); + } + + [Fact] + public void Should_Not_Consider_Two_Styles_With_Different_Background_Colors_Equal() + { + // Given + var first = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://example.com"); + var second = new Style(Color.White, Color.Blue, Decoration.Bold | Decoration.Italic, "http://example.com"); + + // When + var result = first.Equals(second); + + // Then + result.ShouldBeFalse(); + } + + [Fact] + public void Should_Not_Consider_Two_Styles_With_Different_Decorations_Equal() + { + // Given + var first = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://example.com"); + var second = new Style(Color.White, Color.Yellow, Decoration.Bold, "http://example.com"); + + // When + var result = first.Equals(second); + + // Then + result.ShouldBeFalse(); + } + + [Fact] + public void Should_Not_Consider_Two_Styles_With_Different_Links_Equal() + { + // Given + var first = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://example.com"); + var second = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://foo.com"); + + // When + var result = first.Equals(second); + + // Then + result.ShouldBeFalse(); + } + + public sealed class TheParseMethod { [Fact] - public void Should_Combine_Two_Styles_As_Expected() + public void Default_Keyword_Should_Return_Default_Style() { - // Given - var first = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic); - var other = new Style(Color.Green, Color.Silver, Decoration.Underline, "https://example.com"); - - // When - var result = first.Combine(other); + // Given, When + var result = Style.Parse("default"); // Then - result.Foreground.ShouldBe(Color.Green); - result.Background.ShouldBe(Color.Silver); - result.Decoration.ShouldBe(Decoration.Bold | Decoration.Italic | Decoration.Underline); + result.ShouldNotBeNull(); + result.Foreground.ShouldBe(Color.Default); + result.Background.ShouldBe(Color.Default); + result.Decoration.ShouldBe(Decoration.None); + } + + [Theory] + [InlineData("bold", Decoration.Bold)] + [InlineData("b", Decoration.Bold)] + [InlineData("dim", Decoration.Dim)] + [InlineData("i", Decoration.Italic)] + [InlineData("italic", Decoration.Italic)] + [InlineData("underline", Decoration.Underline)] + [InlineData("u", Decoration.Underline)] + [InlineData("invert", Decoration.Invert)] + [InlineData("conceal", Decoration.Conceal)] + [InlineData("slowblink", Decoration.SlowBlink)] + [InlineData("rapidblink", Decoration.RapidBlink)] + [InlineData("strikethrough", Decoration.Strikethrough)] + [InlineData("s", Decoration.Strikethrough)] + public void Should_Parse_Decoration(string text, Decoration decoration) + { + // Given, When + var result = Style.Parse(text); + + // Then + result.ShouldNotBeNull(); + result.Decoration.ShouldBe(decoration); + } + + [Fact] + public void Should_Parse_Link_Without_Address() + { + // Given, When + var result = Style.Parse("link"); + + // Then + result.ShouldNotBeNull(); + result.Link.ShouldBe("https://emptylink"); + } + + [Fact] + public void Should_Parse_Link() + { + // Given, When + var result = Style.Parse("link=https://example.com"); + + // Then + result.ShouldNotBeNull(); result.Link.ShouldBe("https://example.com"); } [Fact] - public void Should_Consider_Two_Identical_Styles_Equal() + public void Should_Throw_If_Link_Is_Set_Twice() { - // Given - var first = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://example.com"); - var second = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://example.com"); + // Given, When + var result = Record.Exception(() => Style.Parse("link=https://example.com link=https://example.com")); - // When - var result = first.Equals(second); + // Then + result.ShouldBeOfType(); + result.Message.ShouldBe("A link has already been set."); + } + + [Fact] + public void Should_Parse_Background_If_Foreground_Is_Set_To_Default() + { + // Given, When + var result = Style.Parse("default on green"); + + // Then + result.ShouldNotBeNull(); + result.Decoration.ShouldBe(Decoration.None); + result.Foreground.ShouldBe(Color.Default); + result.Background.ShouldBe(Color.Green); + } + + [Fact] + public void Should_Throw_If_Foreground_Is_Set_Twice() + { + // Given, When + var result = Record.Exception(() => Style.Parse("green yellow")); + + // Then + result.ShouldBeOfType(); + result.Message.ShouldBe("A foreground color has already been set."); + } + + [Fact] + public void Should_Throw_If_Background_Is_Set_Twice() + { + // Given, When + var result = Record.Exception(() => Style.Parse("green on blue yellow")); + + // Then + result.ShouldBeOfType(); + result.Message.ShouldBe("A background color has already been set."); + } + + [Fact] + public void Should_Throw_If_Color_Name_Could_Not_Be_Found() + { + // Given, When + var result = Record.Exception(() => Style.Parse("bold lol")); + + // Then + result.ShouldBeOfType(); + result.Message.ShouldBe("Could not find color or style 'lol'."); + } + + [Fact] + public void Should_Throw_If_Background_Color_Name_Could_Not_Be_Found() + { + // Given, When + var result = Record.Exception(() => Style.Parse("blue on lol")); + + // Then + result.ShouldBeOfType(); + result.Message.ShouldBe("Could not find color 'lol'."); + } + + [Fact] + public void Should_Parse_Colors_And_Decoration_And_Link() + { + // Given, When + var result = Style.Parse("link=https://example.com bold underline blue on green"); + + // Then + result.ShouldNotBeNull(); + result.Decoration.ShouldBe(Decoration.Bold | Decoration.Underline); + result.Foreground.ShouldBe(Color.Blue); + result.Background.ShouldBe(Color.Green); + result.Link.ShouldBe("https://example.com"); + } + + [Theory] + [InlineData("#FF0000 on #0000FF")] + [InlineData("#F00 on #00F")] + public void Should_Parse_Hex_Colors_Correctly(string style) + { + // Given, When + var result = Style.Parse(style); + + // Then + result.Foreground.ShouldBe(Color.Red); + result.Background.ShouldBe(Color.Blue); + } + + [Theory] + [InlineData("#", "Invalid hex color '#'.")] + [InlineData("#FF00FF00FF", "Invalid hex color '#FF00FF00FF'.")] + [InlineData("#FOO", "Invalid hex color '#FOO'. Could not find any recognizable digits.")] + public void Should_Return_Error_If_Hex_Color_Is_Invalid(string style, string expected) + { + // Given, When + var result = Record.Exception(() => Style.Parse(style)); + + // Then + result.ShouldNotBeNull(); + result.Message.ShouldBe(expected); + } + + [Theory] + [InlineData("rgb(255,0,0) on rgb(0,0,255)")] + public void Should_Parse_Rgb_Colors_Correctly(string style) + { + // Given, When + var result = Style.Parse(style); + + // Then + result.Foreground.ShouldBe(Color.Red); + result.Background.ShouldBe(Color.Blue); + } + + [Theory] + [InlineData("12 on 24")] + public void Should_Parse_Colors_Numbers_Correctly(string style) + { + // Given, When + var result = Style.Parse(style); + + // Then + result.Foreground.ShouldBe(Color.Blue); + result.Background.ShouldBe(Color.DeepSkyBlue4_1); + } + + [Theory] + [InlineData("-12", "Color number must be greater than or equal to 0 (was -12)")] + [InlineData("256", "Color number must be less than or equal to 255 (was 256)")] + public void Should_Return_Error_If_Color_Number_Is_Invalid(string style, string expected) + { + // Given, When + var result = Record.Exception(() => Style.Parse(style)); + + // Then + result.ShouldNotBeNull(); + result.Message.ShouldBe(expected); + } + + [Theory] + [InlineData("rgb()", "Invalid RGB color 'rgb()'.")] + [InlineData("rgb(", "Invalid RGB color 'rgb('.")] + [InlineData("rgb(255)", "Invalid RGB color 'rgb(255)'.")] + [InlineData("rgb(255,255)", "Invalid RGB color 'rgb(255,255)'.")] + [InlineData("rgb(255,255,255", "Invalid RGB color 'rgb(255,255,255'.")] + [InlineData("rgb(A,B,C)", "Invalid RGB color 'rgb(A,B,C)'. Input string was not in a correct format.")] + public void Should_Return_Error_If_Rgb_Color_Is_Invalid(string style, string expected) + { + // Given, When + var result = Record.Exception(() => Style.Parse(style)); + + // Then + result.ShouldNotBeNull(); + result.Message.ShouldBe(expected); + } + } + + public sealed class TheTryParseMethod + { + [Fact] + public void Should_Return_True_If_Parsing_Succeeded() + { + // Given, When + var result = Style.TryParse("bold", out var style); // Then result.ShouldBeTrue(); + style.ShouldNotBeNull(); + style.Decoration.ShouldBe(Decoration.Bold); } [Fact] - public void Should_Not_Consider_Two_Styles_With_Different_Foreground_Colors_Equal() + public void Should_Return_False_If_Parsing_Failed() { - // Given - var first = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://example.com"); - var second = new Style(Color.Blue, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://example.com"); - - // When - var result = first.Equals(second); + // Given, When + var result = Style.TryParse("lol", out _); // Then result.ShouldBeFalse(); } - - [Fact] - public void Should_Not_Consider_Two_Styles_With_Different_Background_Colors_Equal() - { - // Given - var first = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://example.com"); - var second = new Style(Color.White, Color.Blue, Decoration.Bold | Decoration.Italic, "http://example.com"); - - // When - var result = first.Equals(second); - - // Then - result.ShouldBeFalse(); - } - - [Fact] - public void Should_Not_Consider_Two_Styles_With_Different_Decorations_Equal() - { - // Given - var first = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://example.com"); - var second = new Style(Color.White, Color.Yellow, Decoration.Bold, "http://example.com"); - - // When - var result = first.Equals(second); - - // Then - result.ShouldBeFalse(); - } - - [Fact] - public void Should_Not_Consider_Two_Styles_With_Different_Links_Equal() - { - // Given - var first = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://example.com"); - var second = new Style(Color.White, Color.Yellow, Decoration.Bold | Decoration.Italic, "http://foo.com"); - - // When - var result = first.Equals(second); - - // Then - result.ShouldBeFalse(); - } - - public sealed class TheParseMethod - { - [Fact] - public void Default_Keyword_Should_Return_Default_Style() - { - // Given, When - var result = Style.Parse("default"); - - // Then - result.ShouldNotBeNull(); - result.Foreground.ShouldBe(Color.Default); - result.Background.ShouldBe(Color.Default); - result.Decoration.ShouldBe(Decoration.None); - } - - [Theory] - [InlineData("bold", Decoration.Bold)] - [InlineData("b", Decoration.Bold)] - [InlineData("dim", Decoration.Dim)] - [InlineData("i", Decoration.Italic)] - [InlineData("italic", Decoration.Italic)] - [InlineData("underline", Decoration.Underline)] - [InlineData("u", Decoration.Underline)] - [InlineData("invert", Decoration.Invert)] - [InlineData("conceal", Decoration.Conceal)] - [InlineData("slowblink", Decoration.SlowBlink)] - [InlineData("rapidblink", Decoration.RapidBlink)] - [InlineData("strikethrough", Decoration.Strikethrough)] - [InlineData("s", Decoration.Strikethrough)] - public void Should_Parse_Decoration(string text, Decoration decoration) - { - // Given, When - var result = Style.Parse(text); - - // Then - result.ShouldNotBeNull(); - result.Decoration.ShouldBe(decoration); - } - - [Fact] - public void Should_Parse_Link_Without_Address() - { - // Given, When - var result = Style.Parse("link"); - - // Then - result.ShouldNotBeNull(); - result.Link.ShouldBe("https://emptylink"); - } - - [Fact] - public void Should_Parse_Link() - { - // Given, When - var result = Style.Parse("link=https://example.com"); - - // Then - result.ShouldNotBeNull(); - result.Link.ShouldBe("https://example.com"); - } - - [Fact] - public void Should_Throw_If_Link_Is_Set_Twice() - { - // Given, When - var result = Record.Exception(() => Style.Parse("link=https://example.com link=https://example.com")); - - // Then - result.ShouldBeOfType(); - result.Message.ShouldBe("A link has already been set."); - } - - [Fact] - public void Should_Parse_Background_If_Foreground_Is_Set_To_Default() - { - // Given, When - var result = Style.Parse("default on green"); - - // Then - result.ShouldNotBeNull(); - result.Decoration.ShouldBe(Decoration.None); - result.Foreground.ShouldBe(Color.Default); - result.Background.ShouldBe(Color.Green); - } - - [Fact] - public void Should_Throw_If_Foreground_Is_Set_Twice() - { - // Given, When - var result = Record.Exception(() => Style.Parse("green yellow")); - - // Then - result.ShouldBeOfType(); - result.Message.ShouldBe("A foreground color has already been set."); - } - - [Fact] - public void Should_Throw_If_Background_Is_Set_Twice() - { - // Given, When - var result = Record.Exception(() => Style.Parse("green on blue yellow")); - - // Then - result.ShouldBeOfType(); - result.Message.ShouldBe("A background color has already been set."); - } - - [Fact] - public void Should_Throw_If_Color_Name_Could_Not_Be_Found() - { - // Given, When - var result = Record.Exception(() => Style.Parse("bold lol")); - - // Then - result.ShouldBeOfType(); - result.Message.ShouldBe("Could not find color or style 'lol'."); - } - - [Fact] - public void Should_Throw_If_Background_Color_Name_Could_Not_Be_Found() - { - // Given, When - var result = Record.Exception(() => Style.Parse("blue on lol")); - - // Then - result.ShouldBeOfType(); - result.Message.ShouldBe("Could not find color 'lol'."); - } - - [Fact] - public void Should_Parse_Colors_And_Decoration_And_Link() - { - // Given, When - var result = Style.Parse("link=https://example.com bold underline blue on green"); - - // Then - result.ShouldNotBeNull(); - result.Decoration.ShouldBe(Decoration.Bold | Decoration.Underline); - result.Foreground.ShouldBe(Color.Blue); - result.Background.ShouldBe(Color.Green); - result.Link.ShouldBe("https://example.com"); - } - - [Theory] - [InlineData("#FF0000 on #0000FF")] - [InlineData("#F00 on #00F")] - public void Should_Parse_Hex_Colors_Correctly(string style) - { - // Given, When - var result = Style.Parse(style); - - // Then - result.Foreground.ShouldBe(Color.Red); - result.Background.ShouldBe(Color.Blue); - } - - [Theory] - [InlineData("#", "Invalid hex color '#'.")] - [InlineData("#FF00FF00FF", "Invalid hex color '#FF00FF00FF'.")] - [InlineData("#FOO", "Invalid hex color '#FOO'. Could not find any recognizable digits.")] - public void Should_Return_Error_If_Hex_Color_Is_Invalid(string style, string expected) - { - // Given, When - var result = Record.Exception(() => Style.Parse(style)); - - // Then - result.ShouldNotBeNull(); - result.Message.ShouldBe(expected); - } - - [Theory] - [InlineData("rgb(255,0,0) on rgb(0,0,255)")] - public void Should_Parse_Rgb_Colors_Correctly(string style) - { - // Given, When - var result = Style.Parse(style); - - // Then - result.Foreground.ShouldBe(Color.Red); - result.Background.ShouldBe(Color.Blue); - } - - [Theory] - [InlineData("12 on 24")] - public void Should_Parse_Colors_Numbers_Correctly(string style) - { - // Given, When - var result = Style.Parse(style); - - // Then - result.Foreground.ShouldBe(Color.Blue); - result.Background.ShouldBe(Color.DeepSkyBlue4_1); - } - - [Theory] - [InlineData("-12", "Color number must be greater than or equal to 0 (was -12)")] - [InlineData("256", "Color number must be less than or equal to 255 (was 256)")] - public void Should_Return_Error_If_Color_Number_Is_Invalid(string style, string expected) - { - // Given, When - var result = Record.Exception(() => Style.Parse(style)); - - // Then - result.ShouldNotBeNull(); - result.Message.ShouldBe(expected); - } - - [Theory] - [InlineData("rgb()", "Invalid RGB color 'rgb()'.")] - [InlineData("rgb(", "Invalid RGB color 'rgb('.")] - [InlineData("rgb(255)", "Invalid RGB color 'rgb(255)'.")] - [InlineData("rgb(255,255)", "Invalid RGB color 'rgb(255,255)'.")] - [InlineData("rgb(255,255,255", "Invalid RGB color 'rgb(255,255,255'.")] - [InlineData("rgb(A,B,C)", "Invalid RGB color 'rgb(A,B,C)'. Input string was not in a correct format.")] - public void Should_Return_Error_If_Rgb_Color_Is_Invalid(string style, string expected) - { - // Given, When - var result = Record.Exception(() => Style.Parse(style)); - - // Then - result.ShouldNotBeNull(); - result.Message.ShouldBe(expected); - } - } - - public sealed class TheTryParseMethod - { - [Fact] - public void Should_Return_True_If_Parsing_Succeeded() - { - // Given, When - var result = Style.TryParse("bold", out var style); - - // Then - result.ShouldBeTrue(); - style.ShouldNotBeNull(); - style.Decoration.ShouldBe(Decoration.Bold); - } - - [Fact] - public void Should_Return_False_If_Parsing_Failed() - { - // Given, When - var result = Style.TryParse("lol", out _); - - // Then - result.ShouldBeFalse(); - } - } - - public sealed class TheToMarkupMethod - { - [Fact] - public void Should_Return_Expected_Markup_For_Style_With_Foreground_Color() - { - // Given - var style = new Style(Color.Red); - - // When - var result = style.ToMarkup(); - - // Then - result.ShouldBe("red"); - } - - [Fact] - public void Should_Return_Expected_Markup_For_Style_With_Foreground_And_Background_Color() - { - // Given - var style = new Style(Color.Red, Color.Green); - - // When - var result = style.ToMarkup(); - - // Then - result.ShouldBe("red on green"); - } - - [Fact] - public void Should_Return_Expected_Markup_For_Style_With_Foreground_And_Background_Color_And_Decoration() - { - // Given - var style = new Style(Color.Red, Color.Green, Decoration.Bold | Decoration.Underline); - - // When - var result = style.ToMarkup(); - - // Then - result.ShouldBe("bold underline red on green"); - } - - [Fact] - public void Should_Return_Expected_Markup_For_Style_With_Only_Background_Color() - { - // Given - var style = new Style(background: Color.Green); - - // When - var result = style.ToMarkup(); - - // Then - result.ShouldBe("default on green"); - } - } } -} \ No newline at end of file + + public sealed class TheToMarkupMethod + { + [Fact] + public void Should_Return_Expected_Markup_For_Style_With_Foreground_Color() + { + // Given + var style = new Style(Color.Red); + + // When + var result = style.ToMarkup(); + + // Then + result.ShouldBe("red"); + } + + [Fact] + public void Should_Return_Expected_Markup_For_Style_With_Foreground_And_Background_Color() + { + // Given + var style = new Style(Color.Red, Color.Green); + + // When + var result = style.ToMarkup(); + + // Then + result.ShouldBe("red on green"); + } + + [Fact] + public void Should_Return_Expected_Markup_For_Style_With_Foreground_And_Background_Color_And_Decoration() + { + // Given + var style = new Style(Color.Red, Color.Green, Decoration.Bold | Decoration.Underline); + + // When + var result = style.ToMarkup(); + + // Then + result.ShouldBe("bold underline red on green"); + } + + [Fact] + public void Should_Return_Expected_Markup_For_Style_With_Only_Background_Color() + { + // Given + var style = new Style(background: Color.Green); + + // When + var result = style.ToMarkup(); + + // Then + result.ShouldBe("default on green"); + } + } +} diff --git a/test/Spectre.Console.Tests/Unit/Widgets/BarChartTests.cs b/test/Spectre.Console.Tests/Unit/Widgets/BarChartTests.cs index 7b41825..70a941c 100644 --- a/test/Spectre.Console.Tests/Unit/Widgets/BarChartTests.cs +++ b/test/Spectre.Console.Tests/Unit/Widgets/BarChartTests.cs @@ -1,72 +1,64 @@ -using System.Threading.Tasks; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("Widgets/BarChart")] +public sealed class BarChartTests { - [UsesVerify] - [ExpectationPath("Widgets/BarChart")] - public sealed class BarChartTests + [Fact] + [Expectation("Render")] + public async Task Should_Render_Correctly() { - [Fact] - [Expectation("Render")] - public async Task Should_Render_Correctly() - { - // Given - var console = new TestConsole(); + // Given + var console = new TestConsole(); - // When - console.Write(new BarChart() - .Width(60) - .Label("Number of fruits") - .AddItem("Apple", 12) - .AddItem("Orange", 54) - .AddItem("Banana", 33)); - - // Then - await Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Zero_Value")] - public async Task Should_Render_Correctly_2() - { - // Given - var console = new TestConsole(); - - // When - console.Write(new BarChart() - .Width(60) - .Label("Number of fruits") - .AddItem("Apple", 0) - .AddItem("Orange", 54) - .AddItem("Banana", 33)); - - // Then - await Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Fixed_Max_Value")] - public async Task Should_Render_Correctly_3() - { - // Given - var console = new TestConsole(); - - // When - console.Write(new BarChart() - .Width(60) - .WithMaxValue(100) - .Label("Number of fruits") - .AddItem("Apple", 12) - .AddItem("Orange", 54) - .AddItem("Banana", 33)); - - // Then - await Verifier.Verify(console.Output); - } + // When + console.Write(new BarChart() + .Width(60) + .Label("Number of fruits") + .AddItem("Apple", 12) + .AddItem("Orange", 54) + .AddItem("Banana", 33)); + // Then + await Verifier.Verify(console.Output); } -} \ No newline at end of file + + [Fact] + [Expectation("Zero_Value")] + public async Task Should_Render_Correctly_2() + { + // Given + var console = new TestConsole(); + + // When + console.Write(new BarChart() + .Width(60) + .Label("Number of fruits") + .AddItem("Apple", 0) + .AddItem("Orange", 54) + .AddItem("Banana", 33)); + + // Then + await Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Fixed_Max_Value")] + public async Task Should_Render_Correctly_3() + { + // Given + var console = new TestConsole(); + + // When + console.Write(new BarChart() + .Width(60) + .WithMaxValue(100) + .Label("Number of fruits") + .AddItem("Apple", 12) + .AddItem("Orange", 54) + .AddItem("Banana", 33)); + + // Then + await Verifier.Verify(console.Output); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Widgets/BreakdownChartTests.cs b/test/Spectre.Console.Tests/Unit/Widgets/BreakdownChartTests.cs index a52ee38..ab92efb 100644 --- a/test/Spectre.Console.Tests/Unit/Widgets/BreakdownChartTests.cs +++ b/test/Spectre.Console.Tests/Unit/Widgets/BreakdownChartTests.cs @@ -1,150 +1,143 @@ -using System.Threading.Tasks; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("Widgets/BreakdownChart")] +public sealed class BreakdownChartTests { - [UsesVerify] - [ExpectationPath("Widgets/BreakdownChart")] - public sealed class BreakdownChartTests + [Fact] + [Expectation("Default")] + public async Task Should_Render_Correctly() { - [Fact] - [Expectation("Default")] - public async Task Should_Render_Correctly() + // Given + var console = new TestConsole(); + var chart = Fixture.GetChart(); + + // When + console.Write(chart); + + // Then + await Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Width")] + public async Task Should_Render_With_Specific_Width() + { + // Given + var console = new TestConsole(); + var chart = Fixture.GetChart().Width(60); + + // When + console.Write(chart); + + // Then + await Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("TagFormat")] + public async Task Should_Render_Correctly_With_Specific_Value_Formatter() + { + // Given + var console = new TestConsole(); + var chart = Fixture.GetChart() + .Width(60) + .Culture("sv-SE") + .UseValueFormatter((v, c) => string.Format(c, "{0}%", v)); + + // When + console.Write(chart); + + // Then + await Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("HideTags")] + public async Task Should_Render_Correctly_Without_Tags() + { + // Given + var console = new TestConsole(); + var chart = Fixture.GetChart().Width(60).HideTags(); + + // When + console.Write(chart); + + // Then + await Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("HideTagValues")] + public async Task Should_Render_Correctly_Without_Tag_Values() + { + // Given + var console = new TestConsole(); + var chart = Fixture.GetChart().Width(60).HideTagValues(); + + // When + console.Write(chart); + + // Then + await Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Culture")] + public async Task Should_Render_Correctly_With_Specific_Culture() + { + // Given + var console = new TestConsole(); + var chart = Fixture.GetChart().Width(60).Culture("sv-SE"); + + // When + console.Write(chart); + + // Then + await Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("FullSize")] + public async Task Should_Render_FullSize_Mode_Correctly() + { + // Given + var console = new TestConsole(); + var chart = Fixture.GetChart().Width(60).FullSize(); + + // When + console.Write(chart); + + // Then + await Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Ansi")] + public async Task Should_Render_Correct_Ansi() + { + // Given + var console = new TestConsole().EmitAnsiSequences(); + var chart = Fixture.GetChart().Width(60).FullSize(); + + // When + console.Write(chart); + + // Then + await Verifier.Verify(console.Output); + } + + public static class Fixture + { + public static BreakdownChart GetChart() { - // Given - var console = new TestConsole(); - var chart = Fixture.GetChart(); - - // When - console.Write(chart); - - // Then - await Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Width")] - public async Task Should_Render_With_Specific_Width() - { - // Given - var console = new TestConsole(); - var chart = Fixture.GetChart().Width(60); - - // When - console.Write(chart); - - // Then - await Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("TagFormat")] - public async Task Should_Render_Correctly_With_Specific_Value_Formatter() - { - // Given - var console = new TestConsole(); - var chart = Fixture.GetChart() - .Width(60) - .Culture("sv-SE") - .UseValueFormatter((v, c) => string.Format(c, "{0}%", v)); - - // When - console.Write(chart); - - // Then - await Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("HideTags")] - public async Task Should_Render_Correctly_Without_Tags() - { - // Given - var console = new TestConsole(); - var chart = Fixture.GetChart().Width(60).HideTags(); - - // When - console.Write(chart); - - // Then - await Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("HideTagValues")] - public async Task Should_Render_Correctly_Without_Tag_Values() - { - // Given - var console = new TestConsole(); - var chart = Fixture.GetChart().Width(60).HideTagValues(); - - // When - console.Write(chart); - - // Then - await Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Culture")] - public async Task Should_Render_Correctly_With_Specific_Culture() - { - // Given - var console = new TestConsole(); - var chart = Fixture.GetChart().Width(60).Culture("sv-SE"); - - // When - console.Write(chart); - - // Then - await Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("FullSize")] - public async Task Should_Render_FullSize_Mode_Correctly() - { - // Given - var console = new TestConsole(); - var chart = Fixture.GetChart().Width(60).FullSize(); - - // When - console.Write(chart); - - // Then - await Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Ansi")] - public async Task Should_Render_Correct_Ansi() - { - // Given - var console = new TestConsole().EmitAnsiSequences(); - var chart = Fixture.GetChart().Width(60).FullSize(); - - // When - console.Write(chart); - - // Then - await Verifier.Verify(console.Output); - } - - public static class Fixture - { - public static BreakdownChart GetChart() - { - return new BreakdownChart() - .AddItem("SCSS", 37, Color.Red) - .AddItem("HTML", 28.3, Color.Blue) - .AddItem("C#", 22.6, Color.Green) - .AddItem("JavaScript", 6, Color.Yellow) - .AddItem("Ruby", 6, Color.LightGreen) - .AddItem("Shell", 0.1, Color.Aqua); - } + return new BreakdownChart() + .AddItem("SCSS", 37, Color.Red) + .AddItem("HTML", 28.3, Color.Blue) + .AddItem("C#", 22.6, Color.Green) + .AddItem("JavaScript", 6, Color.Yellow) + .AddItem("Ruby", 6, Color.LightGreen) + .AddItem("Shell", 0.1, Color.Aqua); } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Unit/Widgets/CalendarTests.cs b/test/Spectre.Console.Tests/Unit/Widgets/CalendarTests.cs index 0d635d3..89df1e4 100644 --- a/test/Spectre.Console.Tests/Unit/Widgets/CalendarTests.cs +++ b/test/Spectre.Console.Tests/Unit/Widgets/CalendarTests.cs @@ -1,108 +1,100 @@ -using System; -using System.Threading.Tasks; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("Widgets/Calendar")] +public sealed class CalendarTests { - [UsesVerify] - [ExpectationPath("Widgets/Calendar")] - public sealed class CalendarTests + [Fact] + [Expectation("Render")] + public Task Should_Render_Calendar_Correctly() { - [Fact] - [Expectation("Render")] - public Task Should_Render_Calendar_Correctly() - { - // Given - var console = new TestConsole(); - var calendar = new Calendar(2020, 10) - .AddCalendarEvent(new DateTime(2020, 9, 1)) - .AddCalendarEvent(new DateTime(2020, 10, 3)) - .AddCalendarEvent(new DateTime(2020, 10, 12)); + // Given + var console = new TestConsole(); + var calendar = new Calendar(2020, 10) + .AddCalendarEvent(new DateTime(2020, 9, 1)) + .AddCalendarEvent(new DateTime(2020, 10, 3)) + .AddCalendarEvent(new DateTime(2020, 10, 12)); - // When - console.Write(calendar); + // When + console.Write(calendar); - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Centered")] - public Task Should_Center_Calendar_Correctly() - { - // Given - var console = new TestConsole(); - var calendar = new Calendar(2020, 10) - .Centered() - .AddCalendarEvent(new DateTime(2020, 9, 1)) - .AddCalendarEvent(new DateTime(2020, 10, 3)) - .AddCalendarEvent(new DateTime(2020, 10, 12)); - - // When - console.Write(calendar); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("LeftAligned")] - public Task Should_Left_Align_Calendar_Correctly() - { - // Given - var console = new TestConsole(); - var calendar = new Calendar(2020, 10) - .LeftAligned() - .AddCalendarEvent(new DateTime(2020, 9, 1)) - .AddCalendarEvent(new DateTime(2020, 10, 3)) - .AddCalendarEvent(new DateTime(2020, 10, 12)); - - // When - console.Write(calendar); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("RightAligned")] - public Task Should_Right_Align_Calendar_Correctly() - { - // Given - var console = new TestConsole(); - var calendar = new Calendar(2020, 10) - .RightAligned() - .AddCalendarEvent(new DateTime(2020, 9, 1)) - .AddCalendarEvent(new DateTime(2020, 10, 3)) - .AddCalendarEvent(new DateTime(2020, 10, 12)); - - // When - console.Write(calendar); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Culture")] - public Task Should_Render_Calendar_Correctly_For_Specific_Culture() - { - // Given - var console = new TestConsole(); - var calendar = new Calendar(2020, 10, 15) - .Culture("de-DE") - .AddCalendarEvent(new DateTime(2020, 9, 1)) - .AddCalendarEvent(new DateTime(2020, 10, 3)) - .AddCalendarEvent(new DateTime(2020, 10, 12)); - - // When - console.Write(calendar); - - // Then - return Verifier.Verify(console.Output); - } + // Then + return Verifier.Verify(console.Output); } -} \ No newline at end of file + + [Fact] + [Expectation("Centered")] + public Task Should_Center_Calendar_Correctly() + { + // Given + var console = new TestConsole(); + var calendar = new Calendar(2020, 10) + .Centered() + .AddCalendarEvent(new DateTime(2020, 9, 1)) + .AddCalendarEvent(new DateTime(2020, 10, 3)) + .AddCalendarEvent(new DateTime(2020, 10, 12)); + + // When + console.Write(calendar); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("LeftAligned")] + public Task Should_Left_Align_Calendar_Correctly() + { + // Given + var console = new TestConsole(); + var calendar = new Calendar(2020, 10) + .LeftAligned() + .AddCalendarEvent(new DateTime(2020, 9, 1)) + .AddCalendarEvent(new DateTime(2020, 10, 3)) + .AddCalendarEvent(new DateTime(2020, 10, 12)); + + // When + console.Write(calendar); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("RightAligned")] + public Task Should_Right_Align_Calendar_Correctly() + { + // Given + var console = new TestConsole(); + var calendar = new Calendar(2020, 10) + .RightAligned() + .AddCalendarEvent(new DateTime(2020, 9, 1)) + .AddCalendarEvent(new DateTime(2020, 10, 3)) + .AddCalendarEvent(new DateTime(2020, 10, 12)); + + // When + console.Write(calendar); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Culture")] + public Task Should_Render_Calendar_Correctly_For_Specific_Culture() + { + // Given + var console = new TestConsole(); + var calendar = new Calendar(2020, 10, 15) + .Culture("de-DE") + .AddCalendarEvent(new DateTime(2020, 9, 1)) + .AddCalendarEvent(new DateTime(2020, 10, 3)) + .AddCalendarEvent(new DateTime(2020, 10, 12)); + + // When + console.Write(calendar); + + // Then + return Verifier.Verify(console.Output); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Widgets/CanvasTests.cs b/test/Spectre.Console.Tests/Unit/Widgets/CanvasTests.cs index e306863..4b38a81 100644 --- a/test/Spectre.Console.Tests/Unit/Widgets/CanvasTests.cs +++ b/test/Spectre.Console.Tests/Unit/Widgets/CanvasTests.cs @@ -1,143 +1,134 @@ -using System; -using System.Threading.Tasks; -using Shouldly; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("Widgets/Canvas")] +public class CanvasTests { - [UsesVerify] - [ExpectationPath("Widgets/Canvas")] - public class CanvasTests + public sealed class TheConstructor { - public sealed class TheConstructor + [Fact] + public void Should_Throw_If_Width_Is_Less_Than_Zero() { - [Fact] - public void Should_Throw_If_Width_Is_Less_Than_Zero() - { - // Given, When - var result = Record.Exception(() => new Canvas(0, 1)); + // Given, When + var result = Record.Exception(() => new Canvas(0, 1)); - // Then - result.ShouldBeOfType() - .And(ex => ex.ParamName.ShouldBe("width")); - } - - [Fact] - public void Should_Throw_If_Height_Is_Less_Than_Zero() - { - // Given, When - var result = Record.Exception(() => new Canvas(1, 0)); - - // Then - result.ShouldBeOfType() - .And(ex => ex.ParamName.ShouldBe("height")); - } + // Then + result.ShouldBeOfType() + .And(ex => ex.ParamName.ShouldBe("width")); } [Fact] - [Expectation("Render")] - public async Task Should_Render_Canvas_Correctly() + public void Should_Throw_If_Height_Is_Less_Than_Zero() { - // Given - var console = new TestConsole() - .Colors(ColorSystem.Standard) - .EmitAnsiSequences(); - - var canvas = new Canvas(width: 5, height: 5); - canvas.SetPixel(0, 0, Color.Red); - canvas.SetPixel(4, 0, Color.Green); - canvas.SetPixel(0, 4, Color.Blue); - canvas.SetPixel(4, 4, Color.Yellow); - - // When - console.Write(canvas); + // Given, When + var result = Record.Exception(() => new Canvas(1, 0)); // Then - await Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Nested")] - public async Task Simple_Measure() - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.Standard) - .EmitAnsiSequences(); - - var panel = new Panel(new Canvas(width: 2, height: 2) - .SetPixel(0, 0, Color.Aqua) - .SetPixel(1, 1, Color.Grey)); - - // When - console.Write(panel); - - // Then - await Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_NarrowTerminal")] - public async Task Should_Scale_Down_Canvas_Is_Bigger_Than_Terminal() - { - // Given - var console = new TestConsole() - .Width(10) - .Colors(ColorSystem.Standard) - .EmitAnsiSequences(); - - var canvas = new Canvas(width: 20, height: 10); - canvas.SetPixel(0, 0, Color.Aqua); - canvas.SetPixel(19, 9, Color.Grey); - - // When - console.Write(canvas); - - // Then - await Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_MaxWidth")] - public async Task Should_Scale_Down_Canvas_If_MaxWidth_Is_Set() - { - // Given - var console = new TestConsole() - .Colors(ColorSystem.Standard) - .EmitAnsiSequences(); - - var canvas = new Canvas(width: 20, height: 10) { MaxWidth = 10 }; - canvas.SetPixel(0, 0, Color.Aqua); - canvas.SetPixel(19, 9, Color.Aqua); - - // When - console.Write(canvas); - - // Then - await Verifier.Verify(console.Output); - } - - [Fact] - public void Should_Not_Render_Canvas_If_Canvas_Cannot_Be_Scaled_Down() - { - // Given - var console = new TestConsole() - .Width(10) - .Colors(ColorSystem.Standard) - .EmitAnsiSequences(); - - var canvas = new Canvas(width: 20, height: 2); - canvas.SetPixel(0, 0, Color.Aqua); - canvas.SetPixel(19, 1, Color.Grey); - - // When - console.Write(canvas); - - // Then - console.Output.ShouldBeEmpty(); + result.ShouldBeOfType() + .And(ex => ex.ParamName.ShouldBe("height")); } } -} \ No newline at end of file + + [Fact] + [Expectation("Render")] + public async Task Should_Render_Canvas_Correctly() + { + // Given + var console = new TestConsole() + .Colors(ColorSystem.Standard) + .EmitAnsiSequences(); + + var canvas = new Canvas(width: 5, height: 5); + canvas.SetPixel(0, 0, Color.Red); + canvas.SetPixel(4, 0, Color.Green); + canvas.SetPixel(0, 4, Color.Blue); + canvas.SetPixel(4, 4, Color.Yellow); + + // When + console.Write(canvas); + + // Then + await Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Nested")] + public async Task Simple_Measure() + { + // Given + var console = new TestConsole() + .Colors(ColorSystem.Standard) + .EmitAnsiSequences(); + + var panel = new Panel(new Canvas(width: 2, height: 2) + .SetPixel(0, 0, Color.Aqua) + .SetPixel(1, 1, Color.Grey)); + + // When + console.Write(panel); + + // Then + await Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_NarrowTerminal")] + public async Task Should_Scale_Down_Canvas_Is_Bigger_Than_Terminal() + { + // Given + var console = new TestConsole() + .Width(10) + .Colors(ColorSystem.Standard) + .EmitAnsiSequences(); + + var canvas = new Canvas(width: 20, height: 10); + canvas.SetPixel(0, 0, Color.Aqua); + canvas.SetPixel(19, 9, Color.Grey); + + // When + console.Write(canvas); + + // Then + await Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_MaxWidth")] + public async Task Should_Scale_Down_Canvas_If_MaxWidth_Is_Set() + { + // Given + var console = new TestConsole() + .Colors(ColorSystem.Standard) + .EmitAnsiSequences(); + + var canvas = new Canvas(width: 20, height: 10) { MaxWidth = 10 }; + canvas.SetPixel(0, 0, Color.Aqua); + canvas.SetPixel(19, 9, Color.Aqua); + + // When + console.Write(canvas); + + // Then + await Verifier.Verify(console.Output); + } + + [Fact] + public void Should_Not_Render_Canvas_If_Canvas_Cannot_Be_Scaled_Down() + { + // Given + var console = new TestConsole() + .Width(10) + .Colors(ColorSystem.Standard) + .EmitAnsiSequences(); + + var canvas = new Canvas(width: 20, height: 2); + canvas.SetPixel(0, 0, Color.Aqua); + canvas.SetPixel(19, 1, Color.Grey); + + // When + console.Write(canvas); + + // Then + console.Output.ShouldBeEmpty(); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Widgets/ColumnsTests.cs b/test/Spectre.Console.Tests/Unit/Widgets/ColumnsTests.cs index 3f7f168..63afa78 100644 --- a/test/Spectre.Console.Tests/Unit/Widgets/ColumnsTests.cs +++ b/test/Spectre.Console.Tests/Unit/Widgets/ColumnsTests.cs @@ -1,48 +1,40 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("Widgets/Columns")] +public sealed class ColumnsTests { - [UsesVerify] - [ExpectationPath("Widgets/Columns")] - public sealed class ColumnsTests + private sealed class User { - private sealed class User - { - public string Name { get; set; } - public string Country { get; set; } - } - - [Fact] - [Expectation("Render")] - public Task Should_Render_Columns_Correctly() - { - // Given - var console = new TestConsole().Width(61); - var users = new[] - { - new User { Name = "Savannah Thompson", Country = "Australia" }, - new User { Name = "Sophie Ramos", Country = "United States" }, - new User { Name = "Katrin Goldberg", Country = "Germany" }, - }; - - var cards = new List(); - foreach (var user in users) - { - cards.Add( - new Panel($"[b]{user.Name}[/]\n[yellow]{user.Country}[/]") - .RoundedBorder().Expand()); - } - - // When - console.Write(new Columns(cards)); - - // Then - return Verifier.Verify(console.Output); - } + public string Name { get; set; } + public string Country { get; set; } } -} \ No newline at end of file + + [Fact] + [Expectation("Render")] + public Task Should_Render_Columns_Correctly() + { + // Given + var console = new TestConsole().Width(61); + var users = new[] + { + new User { Name = "Savannah Thompson", Country = "Australia" }, + new User { Name = "Sophie Ramos", Country = "United States" }, + new User { Name = "Katrin Goldberg", Country = "Germany" }, + }; + + var cards = new List(); + foreach (var user in users) + { + cards.Add( + new Panel($"[b]{user.Name}[/]\n[yellow]{user.Country}[/]") + .RoundedBorder().Expand()); + } + + // When + console.Write(new Columns(cards)); + + // Then + return Verifier.Verify(console.Output); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Widgets/FigletTests.cs b/test/Spectre.Console.Tests/Unit/Widgets/FigletTests.cs index b9a2d62..7df7b48 100644 --- a/test/Spectre.Console.Tests/Unit/Widgets/FigletTests.cs +++ b/test/Spectre.Console.Tests/Unit/Widgets/FigletTests.cs @@ -1,107 +1,100 @@ -using System.Threading.Tasks; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("Widgets/Figlet")] +public sealed class FigletTests { - [UsesVerify] - [ExpectationPath("Widgets/Figlet")] - public sealed class FigletTests + [Fact] + [Expectation("Load_Stream")] + public async Task Should_Load_Font_From_Stream() { - [Fact] - [Expectation("Load_Stream")] - public async Task Should_Load_Font_From_Stream() - { - // Given - var console = new TestConsole().Width(180); - var font = FigletFont.Load(EmbeddedResourceReader.LoadResourceStream("Spectre.Console.Tests/Data/starwars.flf")); - var text = new FigletText(font, "Patrik was here"); + // Given + var console = new TestConsole().Width(180); + var font = FigletFont.Load(EmbeddedResourceReader.LoadResourceStream("Spectre.Console.Tests/Data/starwars.flf")); + var text = new FigletText(font, "Patrik was here"); - // When - console.Write(text); + // When + console.Write(text); - // Then - await Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render")] - public async Task Should_Render_Text_Correctly() - { - // Given - var console = new TestConsole().Width(70); - var text = new FigletText(FigletFont.Default, "Patrik was here"); - - // When - console.Write(text); - - // Then - await Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Wrapped")] - public async Task Should_Render_Wrapped_Text_Correctly() - { - // Given - var console = new TestConsole().Width(70); - var text = new FigletText(FigletFont.Default, "Spectre.Console"); - - // When - console.Write(text); - - // Then - await Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_LeftAligned")] - public async Task Should_Render_Left_Aligned_Text_Correctly() - { - // Given - var console = new TestConsole().Width(120); - var text = new FigletText(FigletFont.Default, "Spectre.Console") - .Alignment(Justify.Left); - - // When - console.Write(text); - - // Then - await Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Centered")] - public async Task Should_Render_Centered_Text_Correctly() - { - // Given - var console = new TestConsole().Width(120); - var text = new FigletText(FigletFont.Default, "Spectre.Console") - .Alignment(Justify.Center); - - // When - console.Write(text); - - // Then - await Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_RightAligned")] - public async Task Should_Render_Right_Aligned_Text_Correctly() - { - // Given - var console = new TestConsole().Width(120); - var text = new FigletText(FigletFont.Default, "Spectre.Console") - .Alignment(Justify.Right); - - // When - console.Write(text); - - // Then - await Verifier.Verify(console.Output); - } + // Then + await Verifier.Verify(console.Output); } -} \ No newline at end of file + + [Fact] + [Expectation("Render")] + public async Task Should_Render_Text_Correctly() + { + // Given + var console = new TestConsole().Width(70); + var text = new FigletText(FigletFont.Default, "Patrik was here"); + + // When + console.Write(text); + + // Then + await Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Wrapped")] + public async Task Should_Render_Wrapped_Text_Correctly() + { + // Given + var console = new TestConsole().Width(70); + var text = new FigletText(FigletFont.Default, "Spectre.Console"); + + // When + console.Write(text); + + // Then + await Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_LeftAligned")] + public async Task Should_Render_Left_Aligned_Text_Correctly() + { + // Given + var console = new TestConsole().Width(120); + var text = new FigletText(FigletFont.Default, "Spectre.Console") + .Alignment(Justify.Left); + + // When + console.Write(text); + + // Then + await Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Centered")] + public async Task Should_Render_Centered_Text_Correctly() + { + // Given + var console = new TestConsole().Width(120); + var text = new FigletText(FigletFont.Default, "Spectre.Console") + .Alignment(Justify.Center); + + // When + console.Write(text); + + // Then + await Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_RightAligned")] + public async Task Should_Render_Right_Aligned_Text_Correctly() + { + // Given + var console = new TestConsole().Width(120); + var text = new FigletText(FigletFont.Default, "Spectre.Console") + .Alignment(Justify.Right); + + // When + console.Write(text); + + // Then + await Verifier.Verify(console.Output); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Widgets/GridTests.cs b/test/Spectre.Console.Tests/Unit/Widgets/GridTests.cs index c786ae7..5689c86 100644 --- a/test/Spectre.Console.Tests/Unit/Widgets/GridTests.cs +++ b/test/Spectre.Console.Tests/Unit/Widgets/GridTests.cs @@ -1,200 +1,91 @@ -using System; -using System.Threading.Tasks; -using Shouldly; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("Widgets/Grid")] +public sealed class GridTests { - [UsesVerify] - [ExpectationPath("Widgets/Grid")] - public sealed class GridTests + public sealed class TheAddColumnMethod { - public sealed class TheAddColumnMethod + [Fact] + public void Should_Throw_If_Rows_Are_Not_Empty() { - [Fact] - public void Should_Throw_If_Rows_Are_Not_Empty() - { - // Given - var grid = new Grid(); - grid.AddColumn(); - grid.AddRow("Hello World!"); + // Given + var grid = new Grid(); + grid.AddColumn(); + grid.AddRow("Hello World!"); - // When - var result = Record.Exception(() => grid.AddColumn()); + // When + var result = Record.Exception(() => grid.AddColumn()); - // Then - result.ShouldBeOfType() - .Message.ShouldBe("Cannot add new columns to grid with existing rows."); - } + // Then + result.ShouldBeOfType() + .Message.ShouldBe("Cannot add new columns to grid with existing rows."); + } + } + + public sealed class TheAddRowMethod + { + [Fact] + public void Should_Throw_If_Rows_Are_Null() + { + // Given + var grid = new Grid(); + + // When + var result = Record.Exception(() => grid.AddRow(null)); + + // Then + result.ShouldBeOfType() + .ParamName.ShouldBe("columns"); } - public sealed class TheAddRowMethod + [Fact] + public void Should_Add_Empty_Items_If_User_Provides_Less_Row_Items_Than_Columns() { - [Fact] - public void Should_Throw_If_Rows_Are_Null() - { - // Given - var grid = new Grid(); + // Given + var grid = new Grid(); + grid.AddColumn(); + grid.AddColumn(); - // When - var result = Record.Exception(() => grid.AddRow(null)); + // When + grid.AddRow("Foo"); - // Then - result.ShouldBeOfType() - .ParamName.ShouldBe("columns"); - } - - [Fact] - public void Should_Add_Empty_Items_If_User_Provides_Less_Row_Items_Than_Columns() - { - // Given - var grid = new Grid(); - grid.AddColumn(); - grid.AddColumn(); - - // When - grid.AddRow("Foo"); - - // Then - grid.Rows.Count.ShouldBe(1); - } - - [Fact] - public void Should_Throw_If_Row_Columns_Are_Greater_Than_Number_Of_Columns() - { - // Given - var grid = new Grid(); - grid.AddColumn(); - - // When - var result = Record.Exception(() => grid.AddRow("Foo", "Bar")); - - // Then - result.ShouldBeOfType(); - result.Message.ShouldBe("The number of row columns are greater than the number of grid columns."); - } + // Then + grid.Rows.Count.ShouldBe(1); } - [UsesVerify] - [ExpectationPath("AddEmptyRow")] - public sealed class TheAddEmptyRowMethod + [Fact] + public void Should_Throw_If_Row_Columns_Are_Greater_Than_Number_Of_Columns() { - [Fact] - [Expectation("Render")] - public Task Should_Add_Empty_Row() - { - // Given - var console = new TestConsole(); - var grid = new Grid(); - grid.AddColumns(2); - grid.AddRow("Foo", "Bar"); - grid.AddEmptyRow(); - grid.AddRow("Qux", "Corgi"); - grid.AddEmptyRow(); + // Given + var grid = new Grid(); + grid.AddColumn(); - // When - console.Write(grid); + // When + var result = Record.Exception(() => grid.AddRow("Foo", "Bar")); - // Then - return Verifier.Verify(console.Output); - } + // Then + result.ShouldBeOfType(); + result.Message.ShouldBe("The number of row columns are greater than the number of grid columns."); } + } + [UsesVerify] + [ExpectationPath("AddEmptyRow")] + public sealed class TheAddEmptyRowMethod + { [Fact] [Expectation("Render")] - public Task Should_Render_Grid_Correctly() + public Task Should_Add_Empty_Row() { // Given var console = new TestConsole(); var grid = new Grid(); - grid.AddColumn(); - grid.AddColumn(); - grid.AddColumn(); - grid.AddRow("Qux", "Corgi", "Waldo"); - grid.AddRow("Grault", "Garply", "Fred"); - - // When - console.Write(grid); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_2")] - public Task Should_Render_Grid_Correctly_2() - { - var console = new TestConsole(); - var grid = new Grid(); - grid.AddColumn(new GridColumn { NoWrap = true }); - grid.AddColumn(new GridColumn { Padding = new Padding(2, 0, 0, 0) }); - grid.AddRow("[bold]Options[/]", string.Empty); - grid.AddRow(" [blue]-h[/], [blue]--help[/]", "Show command line help."); - grid.AddRow(" [blue]-c[/], [blue]--configuration[/]", "The configuration to run for.\nThe default for most projects is [green]Debug[/]."); - - // When - console.Write(grid); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Alignment")] - public Task Should_Render_Grid_Column_Alignment_Correctly() - { - // Given - var console = new TestConsole(); - var grid = new Grid(); - grid.AddColumn(new GridColumn { Alignment = Justify.Right }); - grid.AddColumn(new GridColumn { Alignment = Justify.Center }); - grid.AddColumn(new GridColumn { Alignment = Justify.Left }); - grid.AddRow("Foo", "Bar", "Baz"); - grid.AddRow("Qux", "Corgi", "Waldo"); - grid.AddRow("Grault", "Garply", "Fred"); - - // When - console.Write(grid); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Padding")] - public Task Should_Use_Default_Padding() - { - // Given - var console = new TestConsole(); - var grid = new Grid(); - grid.AddColumns(3); - grid.AddRow("Foo", "Bar", "Baz"); - grid.AddRow("Qux", "Corgi", "Waldo"); - grid.AddRow("Grault", "Garply", "Fred"); - - // When - console.Write(grid); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_ExplicitPadding")] - public Task Should_Render_Explicit_Grid_Column_Padding_Correctly() - { - // Given - var console = new TestConsole(); - var grid = new Grid(); - grid.AddColumn(new GridColumn { Padding = new Padding(3, 0, 0, 0) }); - grid.AddColumn(new GridColumn { Padding = new Padding(0, 0, 0, 0) }); - grid.AddColumn(new GridColumn { Padding = new Padding(0, 0, 3, 0) }); - grid.AddRow("Foo", "Bar", "Baz"); - grid.AddRow("Qux", "Corgi", "Waldo"); - grid.AddRow("Grault", "Garply", "Fred"); + grid.AddColumns(2); + grid.AddRow("Foo", "Bar"); + grid.AddEmptyRow(); + grid.AddRow("Qux", "Corgi"); + grid.AddEmptyRow(); // When console.Write(grid); @@ -203,4 +94,104 @@ namespace Spectre.Console.Tests.Unit return Verifier.Verify(console.Output); } } -} \ No newline at end of file + + [Fact] + [Expectation("Render")] + public Task Should_Render_Grid_Correctly() + { + // Given + var console = new TestConsole(); + var grid = new Grid(); + grid.AddColumn(); + grid.AddColumn(); + grid.AddColumn(); + grid.AddRow("Qux", "Corgi", "Waldo"); + grid.AddRow("Grault", "Garply", "Fred"); + + // When + console.Write(grid); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_2")] + public Task Should_Render_Grid_Correctly_2() + { + var console = new TestConsole(); + var grid = new Grid(); + grid.AddColumn(new GridColumn { NoWrap = true }); + grid.AddColumn(new GridColumn { Padding = new Padding(2, 0, 0, 0) }); + grid.AddRow("[bold]Options[/]", string.Empty); + grid.AddRow(" [blue]-h[/], [blue]--help[/]", "Show command line help."); + grid.AddRow(" [blue]-c[/], [blue]--configuration[/]", "The configuration to run for.\nThe default for most projects is [green]Debug[/]."); + + // When + console.Write(grid); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Alignment")] + public Task Should_Render_Grid_Column_Alignment_Correctly() + { + // Given + var console = new TestConsole(); + var grid = new Grid(); + grid.AddColumn(new GridColumn { Alignment = Justify.Right }); + grid.AddColumn(new GridColumn { Alignment = Justify.Center }); + grid.AddColumn(new GridColumn { Alignment = Justify.Left }); + grid.AddRow("Foo", "Bar", "Baz"); + grid.AddRow("Qux", "Corgi", "Waldo"); + grid.AddRow("Grault", "Garply", "Fred"); + + // When + console.Write(grid); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Padding")] + public Task Should_Use_Default_Padding() + { + // Given + var console = new TestConsole(); + var grid = new Grid(); + grid.AddColumns(3); + grid.AddRow("Foo", "Bar", "Baz"); + grid.AddRow("Qux", "Corgi", "Waldo"); + grid.AddRow("Grault", "Garply", "Fred"); + + // When + console.Write(grid); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_ExplicitPadding")] + public Task Should_Render_Explicit_Grid_Column_Padding_Correctly() + { + // Given + var console = new TestConsole(); + var grid = new Grid(); + grid.AddColumn(new GridColumn { Padding = new Padding(3, 0, 0, 0) }); + grid.AddColumn(new GridColumn { Padding = new Padding(0, 0, 0, 0) }); + grid.AddColumn(new GridColumn { Padding = new Padding(0, 0, 3, 0) }); + grid.AddRow("Foo", "Bar", "Baz"); + grid.AddRow("Qux", "Corgi", "Waldo"); + grid.AddRow("Grault", "Garply", "Fred"); + + // When + console.Write(grid); + + // Then + return Verifier.Verify(console.Output); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Widgets/MarkupTests.cs b/test/Spectre.Console.Tests/Unit/Widgets/MarkupTests.cs index a566f5a..fc9220b 100644 --- a/test/Spectre.Console.Tests/Unit/Widgets/MarkupTests.cs +++ b/test/Spectre.Console.Tests/Unit/Widgets/MarkupTests.cs @@ -1,143 +1,137 @@ -using System; -using Shouldly; -using Spectre.Console.Testing; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +public sealed class MarkupTests { - public sealed class MarkupTests + public sealed class TheLengthProperty { - public sealed class TheLengthProperty - { - [Theory] - [InlineData("Hello", 5)] - [InlineData("Hello\nWorld", 11)] - [InlineData("[yellow]Hello[/]", 5)] - public void Should_Return_The_Number_Of_Characters(string input, int expected) - { - // Given - var markup = new Markup(input); - - // When - var result = markup.Length; - - // Then - result.ShouldBe(expected); - } - } - - public sealed class TheLinesProperty - { - [Theory] - [InlineData("Hello", 1)] - [InlineData("Hello\nWorld", 2)] - [InlineData("[yellow]Hello[/]\nWorld", 2)] - public void Should_Return_The_Number_Of_Lines(string input, int expected) - { - // Given - var markup = new Markup(input); - - // When - var result = markup.Lines; - - // Then - result.ShouldBe(expected); - } - } - - public sealed class TheEscapeMethod - { - [Theory] - [InlineData("Hello World", "Hello World")] - [InlineData("Hello World [", "Hello World [[")] - [InlineData("Hello World ]", "Hello World ]]")] - [InlineData("Hello [World]", "Hello [[World]]")] - [InlineData("Hello [[World]]", "Hello [[[[World]]]]")] - public void Should_Escape_Markup_As_Expected(string input, string expected) - { - // Given, When - var result = Markup.Escape(input); - - // Then - result.ShouldBe(expected); - } - } - - public sealed class TheRemoveMethod - { - [Theory] - [InlineData("Hello World", "Hello World")] - [InlineData("Hello [blue]World", "Hello World")] - [InlineData("Hello [blue]World[/]", "Hello World")] - public void Should_Remove_Markup_From_Text(string input, string expected) - { - // Given, When - var result = Markup.Remove(input); - - // Then - result.ShouldBe(expected); - } - } - [Theory] - [InlineData("Hello [[ World ]")] - [InlineData("Hello [[ World ] !")] - public void Should_Throw_If_Closing_Tag_Is_Not_Properly_Escaped(string input) + [InlineData("Hello", 5)] + [InlineData("Hello\nWorld", 11)] + [InlineData("[yellow]Hello[/]", 5)] + public void Should_Return_The_Number_Of_Characters(string input, int expected) { // Given - var console = new TestConsole(); - - // When - var result = Record.Exception(() => new Markup(input)); - - // Then - result.ShouldNotBeNull(); - result.ShouldBeOfType(); - result.Message.ShouldBe("Encountered unescaped ']' token at position 16"); - } - - [Fact] - public void Should_Escape_Markup_Blocks_As_Expected() - { - // Given - var console = new TestConsole(); - var markup = new Markup("Hello [[ World ]] !"); - - // When - console.Write(markup); - - // Then - console.Output.ShouldBe("Hello [ World ] !"); - } - - [Theory] - [InlineData("Hello [link=http://example.com]example.com[/]", "Hello example.com")] - [InlineData("Hello [link=http://example.com]http://example.com[/]", "Hello http://example.com")] - public void Should_Render_Links_As_Expected(string input, string output) - { - // Given - var console = new TestConsole(); var markup = new Markup(input); // When - console.Write(markup); + var result = markup.Length; // Then - console.Output.ShouldBe(output); - } - - [Fact] - public void Should_Not_Fail_With_Brackets_On_Calls_Without_Args() - { - // Given - var console = new TestConsole(); - - // When - console.MarkupLine("{"); - - // Then - console.Output.NormalizeLineEndings() - .ShouldBe("{\n"); + result.ShouldBe(expected); } } -} \ No newline at end of file + + public sealed class TheLinesProperty + { + [Theory] + [InlineData("Hello", 1)] + [InlineData("Hello\nWorld", 2)] + [InlineData("[yellow]Hello[/]\nWorld", 2)] + public void Should_Return_The_Number_Of_Lines(string input, int expected) + { + // Given + var markup = new Markup(input); + + // When + var result = markup.Lines; + + // Then + result.ShouldBe(expected); + } + } + + public sealed class TheEscapeMethod + { + [Theory] + [InlineData("Hello World", "Hello World")] + [InlineData("Hello World [", "Hello World [[")] + [InlineData("Hello World ]", "Hello World ]]")] + [InlineData("Hello [World]", "Hello [[World]]")] + [InlineData("Hello [[World]]", "Hello [[[[World]]]]")] + public void Should_Escape_Markup_As_Expected(string input, string expected) + { + // Given, When + var result = Markup.Escape(input); + + // Then + result.ShouldBe(expected); + } + } + + public sealed class TheRemoveMethod + { + [Theory] + [InlineData("Hello World", "Hello World")] + [InlineData("Hello [blue]World", "Hello World")] + [InlineData("Hello [blue]World[/]", "Hello World")] + public void Should_Remove_Markup_From_Text(string input, string expected) + { + // Given, When + var result = Markup.Remove(input); + + // Then + result.ShouldBe(expected); + } + } + + [Theory] + [InlineData("Hello [[ World ]")] + [InlineData("Hello [[ World ] !")] + public void Should_Throw_If_Closing_Tag_Is_Not_Properly_Escaped(string input) + { + // Given + var console = new TestConsole(); + + // When + var result = Record.Exception(() => new Markup(input)); + + // Then + result.ShouldNotBeNull(); + result.ShouldBeOfType(); + result.Message.ShouldBe("Encountered unescaped ']' token at position 16"); + } + + [Fact] + public void Should_Escape_Markup_Blocks_As_Expected() + { + // Given + var console = new TestConsole(); + var markup = new Markup("Hello [[ World ]] !"); + + // When + console.Write(markup); + + // Then + console.Output.ShouldBe("Hello [ World ] !"); + } + + [Theory] + [InlineData("Hello [link=http://example.com]example.com[/]", "Hello example.com")] + [InlineData("Hello [link=http://example.com]http://example.com[/]", "Hello http://example.com")] + public void Should_Render_Links_As_Expected(string input, string output) + { + // Given + var console = new TestConsole(); + var markup = new Markup(input); + + // When + console.Write(markup); + + // Then + console.Output.ShouldBe(output); + } + + [Fact] + public void Should_Not_Fail_With_Brackets_On_Calls_Without_Args() + { + // Given + var console = new TestConsole(); + + // When + console.MarkupLine("{"); + + // Then + console.Output.NormalizeLineEndings() + .ShouldBe("{\n"); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Widgets/PadderTests.cs b/test/Spectre.Console.Tests/Unit/Widgets/PadderTests.cs index ba65178..ccca14b 100644 --- a/test/Spectre.Console.Tests/Unit/Widgets/PadderTests.cs +++ b/test/Spectre.Console.Tests/Unit/Widgets/PadderTests.cs @@ -1,75 +1,68 @@ -using System.Threading.Tasks; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("Widgets/Padder")] +public sealed class PadderTests { - [UsesVerify] - [ExpectationPath("Widgets/Padder")] - public sealed class PadderTests + [Fact] + [Expectation("Render")] + public Task Should_Render_Padded_Object_Correctly() { - [Fact] - [Expectation("Render")] - public Task Should_Render_Padded_Object_Correctly() - { - // Given - var console = new TestConsole().Width(60); - var table = new Table(); - table.AddColumn("Foo"); - table.AddColumn("Bar"); - table.AddRow("Baz", "Qux"); - table.AddRow("Corgi", "Waldo"); + // Given + var console = new TestConsole().Width(60); + var table = new Table(); + table.AddColumn("Foo"); + table.AddColumn("Bar"); + table.AddRow("Baz", "Qux"); + table.AddRow("Corgi", "Waldo"); - // When - console.Write(new Padder(table).Padding(1, 2, 3, 4)); + // When + console.Write(new Padder(table).Padding(1, 2, 3, 4)); - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Expanded")] - public Task Should_Render_Expanded_Padded_Object_Correctly() - { - // Given - var console = new TestConsole().Width(60); - var table = new Table(); - table.AddColumn("Foo"); - table.AddColumn("Bar"); - table.AddRow("Baz", "Qux"); - table.AddRow("Corgi", "Waldo"); - - // When - console.Write(new Padder(table) - .Padding(1, 2, 3, 4) - .Expand()); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Nested")] - public Task Should_Render_Padded_Object_Correctly_When_Nested_Within_Other_Object() - { - // Given - var console = new TestConsole().Width(60); - var table = new Table(); - table.AddColumn("Foo"); - table.AddColumn("Bar", c => c.PadLeft(0).PadRight(0)); - table.AddRow("Baz", "Qux"); - table.AddRow(new Text("Corgi"), new Padder(new Panel("Waldo")) - .Padding(2, 1)); - - // When - console.Write(new Padder(table) - .Padding(1, 2, 3, 4) - .Expand()); - - // Then - return Verifier.Verify(console.Output); - } + // Then + return Verifier.Verify(console.Output); } -} \ No newline at end of file + + [Fact] + [Expectation("Render_Expanded")] + public Task Should_Render_Expanded_Padded_Object_Correctly() + { + // Given + var console = new TestConsole().Width(60); + var table = new Table(); + table.AddColumn("Foo"); + table.AddColumn("Bar"); + table.AddRow("Baz", "Qux"); + table.AddRow("Corgi", "Waldo"); + + // When + console.Write(new Padder(table) + .Padding(1, 2, 3, 4) + .Expand()); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Nested")] + public Task Should_Render_Padded_Object_Correctly_When_Nested_Within_Other_Object() + { + // Given + var console = new TestConsole().Width(60); + var table = new Table(); + table.AddColumn("Foo"); + table.AddColumn("Bar", c => c.PadLeft(0).PadRight(0)); + table.AddRow("Baz", "Qux"); + table.AddRow(new Text("Corgi"), new Padder(new Panel("Waldo")) + .Padding(2, 1)); + + // When + console.Write(new Padder(table) + .Padding(1, 2, 3, 4) + .Expand()); + + // Then + return Verifier.Verify(console.Output); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Widgets/PanelTests.cs b/test/Spectre.Console.Tests/Unit/Widgets/PanelTests.cs index 0520c7f..73a2ca9 100644 --- a/test/Spectre.Console.Tests/Unit/Widgets/PanelTests.cs +++ b/test/Spectre.Console.Tests/Unit/Widgets/PanelTests.cs @@ -1,309 +1,300 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Spectre.Console.Rendering; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("Widgets/Panel")] +public sealed class PanelTests { - [UsesVerify] - [ExpectationPath("Widgets/Panel")] - public sealed class PanelTests + [Fact] + [Expectation("Render")] + public Task Should_Render_Panel() { - [Fact] - [Expectation("Render")] - public Task Should_Render_Panel() - { - // Given - var console = new TestConsole(); + // Given + var console = new TestConsole(); - // When - console.Write(new Panel(new Text("Hello World"))); + // When + console.Write(new Panel(new Text("Hello World"))); - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_ZeroPadding")] - public Task Should_Render_Panel_With_Padding_Set_To_Zero() - { - // Given - var console = new TestConsole(); - - // When - console.Write(new Panel(new Text("Hello World")) - { - Padding = new Padding(0, 0, 0, 0), - }); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Padding")] - public Task Should_Render_Panel_With_Padding() - { - // Given - var console = new TestConsole(); - - // When - console.Write(new Panel(new Text("Hello World")) - { - Padding = new Padding(3, 1, 5, 2), - }); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Header")] - public Task Should_Render_Panel_With_Header() - { - // Given - var console = new TestConsole(); - - // When - console.Write(new Panel("Hello World") - { - Header = new PanelHeader("Greeting"), - Expand = true, - Padding = new Padding(2, 0, 2, 0), - }); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Header_LeftAligned")] - public Task Should_Render_Panel_With_Left_Aligned_Header() - { - // Given - var console = new TestConsole(); - - // When - console.Write(new Panel("Hello World") - { - Header = new PanelHeader("Greeting").LeftAligned(), - Expand = true, - }); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Header_Centered")] - public Task Should_Render_Panel_With_Centered_Header() - { - // Given - var console = new TestConsole(); - - // When - console.Write(new Panel("Hello World") - { - Header = new PanelHeader("Greeting").Centered(), - Expand = true, - }); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Header_RightAligned")] - public Task Should_Render_Panel_With_Right_Aligned_Header() - { - // Given - var console = new TestConsole(); - - // When - console.Write(new Panel("Hello World") - { - Header = new PanelHeader("Greeting").RightAligned(), - Expand = true, - }); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Header_Collapse")] - public Task Should_Collapse_Header_If_It_Will_Not_Fit() - { - // Given - var console = new TestConsole().Width(10); - - // When - console.Write(new Panel("Hello World") - { - Header = new PanelHeader("Greeting"), - Expand = true, - }); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Unicode")] - public Task Should_Render_Panel_With_Unicode_Correctly() - { - // Given - var console = new TestConsole(); - - // When - console.Write(new Panel(new Text(" \n💩\n "))); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Multiline")] - public Task Should_Render_Panel_With_Multiple_Lines() - { - // Given - var console = new TestConsole(); - - // When - console.Write(new Panel(new Text("Hello World\nFoo Bar"))); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_LineEndings")] - public Task Should_Preserve_Explicit_Line_Ending() - { - // Given - var console = new TestConsole(); - var text = new Panel( - new Markup("I heard [underline on blue]you[/] like 📦\n\n\n\nSo I put a 📦 in a 📦")); - - // When - console.Write(text); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Expand")] - public Task Should_Expand_Panel_If_Enabled() - { - // Given - var console = new TestConsole(); - - // When - console.Write(new Panel(new Text("Hello World")) - { - Expand = true, - }); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Child_RightAligned")] - public Task Should_Justify_Child_To_Right_Correctly() - { - // Given - var console = new TestConsole().Width(25); - - // When - console.Write( - new Panel(new Text("Hello World").RightAligned()) - { - Expand = true, - }); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Child_Centered")] - public Task Should_Center_Child_Correctly() - { - // Given - var console = new TestConsole().Width(25); - - // When - console.Write( - new Panel(new Text("Hello World").Centered()) - { - Expand = true, - }); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Child_Panel")] - public Task Should_Render_Panel_Inside_Panel_Correctly() - { - // Given - var console = new TestConsole(); - - // When - console.Write(new Panel(new Panel(new Text("Hello World")))); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Wrap")] - public Task Should_Wrap_Content_Correctly() - { - // Given - var console = new TestConsole().Width(84); - var rows = new List(); - var grid = new Grid(); - grid.AddColumn(new GridColumn().PadLeft(2).PadRight(0)); - grid.AddColumn(new GridColumn().PadLeft(1).PadRight(0)); - grid.AddRow("at", "[grey]System.Runtime.CompilerServices.TaskAwaiter.[/][yellow]HandleNonSuccessAndDebuggerNotification[/]([blue]Task[/] task)"); - rows.Add(grid); - - var panel = new Panel(grid) - .Expand().RoundedBorder() - .BorderStyle(new Style().Foreground(Color.Grey)) - .Header("[grey]Short paths[/]"); - - // When - console.Write(panel); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_CJK")] - public Task Should_Wrap_Table_With_CJK_Tables_In_Panel_Correctly() - { - // Given - var console = new TestConsole(); - - var table = new Table(); - table.AddColumn("测试"); - table.AddRow("测试"); - var panel = new Panel(table); - - // When - console.Write(panel); - - // Then - return Verifier.Verify(console.Output); - } + // Then + return Verifier.Verify(console.Output); } -} \ No newline at end of file + + [Fact] + [Expectation("Render_ZeroPadding")] + public Task Should_Render_Panel_With_Padding_Set_To_Zero() + { + // Given + var console = new TestConsole(); + + // When + console.Write(new Panel(new Text("Hello World")) + { + Padding = new Padding(0, 0, 0, 0), + }); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Padding")] + public Task Should_Render_Panel_With_Padding() + { + // Given + var console = new TestConsole(); + + // When + console.Write(new Panel(new Text("Hello World")) + { + Padding = new Padding(3, 1, 5, 2), + }); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Header")] + public Task Should_Render_Panel_With_Header() + { + // Given + var console = new TestConsole(); + + // When + console.Write(new Panel("Hello World") + { + Header = new PanelHeader("Greeting"), + Expand = true, + Padding = new Padding(2, 0, 2, 0), + }); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Header_LeftAligned")] + public Task Should_Render_Panel_With_Left_Aligned_Header() + { + // Given + var console = new TestConsole(); + + // When + console.Write(new Panel("Hello World") + { + Header = new PanelHeader("Greeting").LeftAligned(), + Expand = true, + }); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Header_Centered")] + public Task Should_Render_Panel_With_Centered_Header() + { + // Given + var console = new TestConsole(); + + // When + console.Write(new Panel("Hello World") + { + Header = new PanelHeader("Greeting").Centered(), + Expand = true, + }); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Header_RightAligned")] + public Task Should_Render_Panel_With_Right_Aligned_Header() + { + // Given + var console = new TestConsole(); + + // When + console.Write(new Panel("Hello World") + { + Header = new PanelHeader("Greeting").RightAligned(), + Expand = true, + }); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Header_Collapse")] + public Task Should_Collapse_Header_If_It_Will_Not_Fit() + { + // Given + var console = new TestConsole().Width(10); + + // When + console.Write(new Panel("Hello World") + { + Header = new PanelHeader("Greeting"), + Expand = true, + }); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Unicode")] + public Task Should_Render_Panel_With_Unicode_Correctly() + { + // Given + var console = new TestConsole(); + + // When + console.Write(new Panel(new Text(" \n💩\n "))); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Multiline")] + public Task Should_Render_Panel_With_Multiple_Lines() + { + // Given + var console = new TestConsole(); + + // When + console.Write(new Panel(new Text("Hello World\nFoo Bar"))); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_LineEndings")] + public Task Should_Preserve_Explicit_Line_Ending() + { + // Given + var console = new TestConsole(); + var text = new Panel( + new Markup("I heard [underline on blue]you[/] like 📦\n\n\n\nSo I put a 📦 in a 📦")); + + // When + console.Write(text); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Expand")] + public Task Should_Expand_Panel_If_Enabled() + { + // Given + var console = new TestConsole(); + + // When + console.Write(new Panel(new Text("Hello World")) + { + Expand = true, + }); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Child_RightAligned")] + public Task Should_Justify_Child_To_Right_Correctly() + { + // Given + var console = new TestConsole().Width(25); + + // When + console.Write( + new Panel(new Text("Hello World").RightAligned()) + { + Expand = true, + }); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Child_Centered")] + public Task Should_Center_Child_Correctly() + { + // Given + var console = new TestConsole().Width(25); + + // When + console.Write( + new Panel(new Text("Hello World").Centered()) + { + Expand = true, + }); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Child_Panel")] + public Task Should_Render_Panel_Inside_Panel_Correctly() + { + // Given + var console = new TestConsole(); + + // When + console.Write(new Panel(new Panel(new Text("Hello World")))); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Wrap")] + public Task Should_Wrap_Content_Correctly() + { + // Given + var console = new TestConsole().Width(84); + var rows = new List(); + var grid = new Grid(); + grid.AddColumn(new GridColumn().PadLeft(2).PadRight(0)); + grid.AddColumn(new GridColumn().PadLeft(1).PadRight(0)); + grid.AddRow("at", "[grey]System.Runtime.CompilerServices.TaskAwaiter.[/][yellow]HandleNonSuccessAndDebuggerNotification[/]([blue]Task[/] task)"); + rows.Add(grid); + + var panel = new Panel(grid) + .Expand().RoundedBorder() + .BorderStyle(new Style().Foreground(Color.Grey)) + .Header("[grey]Short paths[/]"); + + // When + console.Write(panel); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_CJK")] + public Task Should_Wrap_Table_With_CJK_Tables_In_Panel_Correctly() + { + // Given + var console = new TestConsole(); + + var table = new Table(); + table.AddColumn("测试"); + table.AddRow("测试"); + var panel = new Panel(table); + + // When + console.Write(panel); + + // Then + return Verifier.Verify(console.Output); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Widgets/RowsTests.cs b/test/Spectre.Console.Tests/Unit/Widgets/RowsTests.cs index 45a52e8..9ebb6f9 100644 --- a/test/Spectre.Console.Tests/Unit/Widgets/RowsTests.cs +++ b/test/Spectre.Console.Tests/Unit/Widgets/RowsTests.cs @@ -1,83 +1,75 @@ -using System.Threading.Tasks; -using Spectre.Console.Rendering; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("Widgets/Rows")] +public sealed class RowsTests { - [UsesVerify] - [ExpectationPath("Widgets/Rows")] - public sealed class RowsTests + [Fact] + [Expectation("Render")] + public Task Should_Render_Rows() { - [Fact] - [Expectation("Render")] - public Task Should_Render_Rows() - { - // Given - var console = new TestConsole().Width(60); - var rows = new Rows( - new IRenderable[] - { + // Given + var console = new TestConsole().Width(60); + var rows = new Rows( + new IRenderable[] + { new Markup("Hello"), new Table() .AddColumns("Foo", "Bar") .AddRow("Baz", "Qux"), new Markup("World"), - }); + }); - // When - console.Write(rows); + // When + console.Write(rows); - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Nested")] - public Task Should_Render_Rows_Correctly_Inside_Other_Widget() - { - // Given - var console = new TestConsole().Width(60); - var table = new Table() - .AddColumns("Foo", "Bar") - .AddRow("HELLO WORLD") - .AddRow( - new Rows(new IRenderable[] - { - new Markup("Hello"), - new Markup("World"), - }), new Text("Qux")); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Expanded_And_Nested")] - public Task Should_Render_Rows_Correctly_Inside_Other_Widget_When_Expanded() - { - // Given - var console = new TestConsole().Width(60); - var table = new Table() - .AddColumns("Foo", "Bar") - .AddRow("HELLO WORLD") - .AddRow( - new Rows(new IRenderable[] - { - new Markup("Hello"), - new Markup("World"), - }).Expand(), new Text("Qux")); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } + // Then + return Verifier.Verify(console.Output); } -} \ No newline at end of file + + [Fact] + [Expectation("Render_Nested")] + public Task Should_Render_Rows_Correctly_Inside_Other_Widget() + { + // Given + var console = new TestConsole().Width(60); + var table = new Table() + .AddColumns("Foo", "Bar") + .AddRow("HELLO WORLD") + .AddRow( + new Rows(new IRenderable[] + { + new Markup("Hello"), + new Markup("World"), + }), new Text("Qux")); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Expanded_And_Nested")] + public Task Should_Render_Rows_Correctly_Inside_Other_Widget_When_Expanded() + { + // Given + var console = new TestConsole().Width(60); + var table = new Table() + .AddColumns("Foo", "Bar") + .AddRow("HELLO WORLD") + .AddRow( + new Rows(new IRenderable[] + { + new Markup("Hello"), + new Markup("World"), + }).Expand(), new Text("Qux")); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Widgets/RuleTests.cs b/test/Spectre.Console.Tests/Unit/Widgets/RuleTests.cs index 647a88a..fbff7b5 100644 --- a/test/Spectre.Console.Tests/Unit/Widgets/RuleTests.cs +++ b/test/Spectre.Console.Tests/Unit/Widgets/RuleTests.cs @@ -1,158 +1,150 @@ -using System.Threading.Tasks; -using Shouldly; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("Widgets/Rule")] +public sealed class RuleTests { - [UsesVerify] - [ExpectationPath("Widgets/Rule")] - public sealed class RuleTests + [Fact] + [Expectation("Render")] + public Task Should_Render_Default_Rule_Without_Title() { - [Fact] - [Expectation("Render")] - public Task Should_Render_Default_Rule_Without_Title() - { - // Given - var console = new TestConsole().Width(40); + // Given + var console = new TestConsole().Width(40); - // When - console.Write(new Rule()); + // When + console.Write(new Rule()); - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Border_NoHeader")] - public Task Should_Render_Default_Rule_With_Specified_Border() - { - // Given - var console = new TestConsole().Width(40); - - // When - console.Write(new Rule().DoubleBorder()); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Border_Header")] - public Task Should_Render_With_Specified_Box() - { - // Given - var console = new TestConsole().Width(40); - - // When - console.Write(new Rule("Hello World").DoubleBorder()); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Header_DefaultAlignment")] - public Task Should_Render_Default_Rule_With_Title_Centered_By_Default() - { - // Given - var console = new TestConsole().Width(40); - - // When - console.Write(new Rule("Hello World")); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Header_LeftAligned")] - public Task Should_Render_Default_Rule_With_Title_Left_Aligned() - { - // Given - var console = new TestConsole().Width(40); - - // When - console.Write(new Rule("Hello World") - { - Alignment = Justify.Left, - }); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Header_RightAligned")] - public Task Should_Render_Default_Rule_With_Title_Right_Aligned() - { - // Given - var console = new TestConsole().Width(40); - - // When - console.Write(new Rule("Hello World") - { - Alignment = Justify.Right, - }); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Linebreaks")] - public Task Should_Convert_Line_Breaks_In_Title_To_Spaces() - { - // Given - var console = new TestConsole().Width(40); - - // When - console.Write(new Rule("Hello\nWorld\r\n!")); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Truncate")] - public Task Should_Truncate_Title() - { - // Given - var console = new TestConsole().Width(40); - - // When - console.Write(new Rule(" Hello World ")); - - // Then - return Verifier.Verify(console.Output); - } - - [Theory] - [InlineData(1, "Hello World Hello World Hello World Hello World Hello World", "─")] - [InlineData(2, "Hello World Hello World Hello World Hello World Hello World", "──")] - [InlineData(3, "Hello World Hello World Hello World Hello World Hello World", "───")] - [InlineData(4, "Hello World Hello World Hello World Hello World Hello World", "────")] - [InlineData(5, "Hello World Hello World Hello World Hello World Hello World", "─────")] - [InlineData(6, "Hello World Hello World Hello World Hello World Hello World", "──────")] - [InlineData(7, "Hello World Hello World Hello World Hello World Hello World", "───────")] - [InlineData(8, "Hello World Hello World Hello World Hello World Hello World", "── H… ──")] - [InlineData(8, "A", "── A ───")] - [InlineData(8, "AB", "── AB ──")] - [InlineData(8, "ABC", "── A… ──")] - [InlineData(40, "Hello World Hello World Hello World Hello World Hello World", "──── Hello World Hello World Hello… ────")] - public void Should_Truncate_Too_Long_Title(int width, string input, string expected) - { - // Given - var console = new TestConsole().Width(width); - - // When - console.Write(new Rule(input)); - - // Then - console.Lines.Count.ShouldBe(1); - console.Lines[0].ShouldBe(expected); - } + // Then + return Verifier.Verify(console.Output); } -} \ No newline at end of file + + [Fact] + [Expectation("Render_Border_NoHeader")] + public Task Should_Render_Default_Rule_With_Specified_Border() + { + // Given + var console = new TestConsole().Width(40); + + // When + console.Write(new Rule().DoubleBorder()); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Border_Header")] + public Task Should_Render_With_Specified_Box() + { + // Given + var console = new TestConsole().Width(40); + + // When + console.Write(new Rule("Hello World").DoubleBorder()); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Header_DefaultAlignment")] + public Task Should_Render_Default_Rule_With_Title_Centered_By_Default() + { + // Given + var console = new TestConsole().Width(40); + + // When + console.Write(new Rule("Hello World")); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Header_LeftAligned")] + public Task Should_Render_Default_Rule_With_Title_Left_Aligned() + { + // Given + var console = new TestConsole().Width(40); + + // When + console.Write(new Rule("Hello World") + { + Alignment = Justify.Left, + }); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Header_RightAligned")] + public Task Should_Render_Default_Rule_With_Title_Right_Aligned() + { + // Given + var console = new TestConsole().Width(40); + + // When + console.Write(new Rule("Hello World") + { + Alignment = Justify.Right, + }); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Linebreaks")] + public Task Should_Convert_Line_Breaks_In_Title_To_Spaces() + { + // Given + var console = new TestConsole().Width(40); + + // When + console.Write(new Rule("Hello\nWorld\r\n!")); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Truncate")] + public Task Should_Truncate_Title() + { + // Given + var console = new TestConsole().Width(40); + + // When + console.Write(new Rule(" Hello World ")); + + // Then + return Verifier.Verify(console.Output); + } + + [Theory] + [InlineData(1, "Hello World Hello World Hello World Hello World Hello World", "─")] + [InlineData(2, "Hello World Hello World Hello World Hello World Hello World", "──")] + [InlineData(3, "Hello World Hello World Hello World Hello World Hello World", "───")] + [InlineData(4, "Hello World Hello World Hello World Hello World Hello World", "────")] + [InlineData(5, "Hello World Hello World Hello World Hello World Hello World", "─────")] + [InlineData(6, "Hello World Hello World Hello World Hello World Hello World", "──────")] + [InlineData(7, "Hello World Hello World Hello World Hello World Hello World", "───────")] + [InlineData(8, "Hello World Hello World Hello World Hello World Hello World", "── H… ──")] + [InlineData(8, "A", "── A ───")] + [InlineData(8, "AB", "── AB ──")] + [InlineData(8, "ABC", "── A… ──")] + [InlineData(40, "Hello World Hello World Hello World Hello World Hello World", "──── Hello World Hello World Hello… ────")] + public void Should_Truncate_Too_Long_Title(int width, string input, string expected) + { + // Given + var console = new TestConsole().Width(width); + + // When + console.Write(new Rule(input)); + + // Then + console.Lines.Count.ShouldBe(1); + console.Lines[0].ShouldBe(expected); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Widgets/Table/TableRowCollectionExtensionsTests.cs b/test/Spectre.Console.Tests/Unit/Widgets/Table/TableRowCollectionExtensionsTests.cs index 2819011..d1d609e 100644 --- a/test/Spectre.Console.Tests/Unit/Widgets/Table/TableRowCollectionExtensionsTests.cs +++ b/test/Spectre.Console.Tests/Unit/Widgets/Table/TableRowCollectionExtensionsTests.cs @@ -1,131 +1,119 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("Widgets/Table/Rows/Extensions")] +public sealed class TableRowCollectionExtensionsTests { [UsesVerify] - [ExpectationPath("Widgets/Table/Rows/Extensions")] - public sealed class TableRowCollectionExtensionsTests + public sealed class TheAddRowMethod { - [UsesVerify] - public sealed class TheAddRowMethod + [Fact] + [Expectation("Add", "Renderables")] + public Task Should_Add_Renderables() { - [Fact] - [Expectation("Add", "Renderables")] - public Task Should_Add_Renderables() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.AddColumn("Column #1"); - table.AddColumn("Column #2"); - table.AddRow(new[] { new Text("1"), new Text("1-2") }); - table.AddRow(new[] { new Text("2"), new Text("2-2") }); - table.AddRow(new[] { new Text("3"), new Text("3-2") }); + // Given + var console = new TestConsole(); + var table = new Table(); + table.AddColumn("Column #1"); + table.AddColumn("Column #2"); + table.AddRow(new[] { new Text("1"), new Text("1-2") }); + table.AddRow(new[] { new Text("2"), new Text("2-2") }); + table.AddRow(new[] { new Text("3"), new Text("3-2") }); - // When - console.Write(table); + // When + console.Write(table); - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Add", "Strings")] - public Task Should_Add_Strings() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.AddColumn("Column #1"); - table.AddColumn("Column #2"); - table.AddRow("1", "1-2"); - table.AddRow("2", "2-2"); - table.AddRow("3", "3-2"); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } + // Then + return Verifier.Verify(console.Output); } - [UsesVerify] - public sealed class TheInsertRowMethod + [Fact] + [Expectation("Add", "Strings")] + public Task Should_Add_Strings() { - [Fact] - [Expectation("Insert", "Renderables")] - public Task Should_Insert_Renderables() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.AddColumn("Column #1"); - table.AddColumn("Column #2"); - table.AddRow(new[] { new Text("1"), new Text("1-2") }); - table.AddRow(new[] { new Text("2"), new Text("2-2") }); + // Given + var console = new TestConsole(); + var table = new Table(); + table.AddColumn("Column #1"); + table.AddColumn("Column #2"); + table.AddRow("1", "1-2"); + table.AddRow("2", "2-2"); + table.AddRow("3", "3-2"); - // When - table.InsertRow(1, new[] { new Text("3"), new Text("3-2") }); + // When + console.Write(table); - // Then - console.Write(table); - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Insert", "Strings")] - public Task Should_Insert_Strings() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.AddColumn("Column #1"); - table.AddColumn("Column #2"); - table.AddRow("1", "1-2"); - table.AddRow("2", "2-2"); - - // When - table.InsertRow(1, "3", "3-2"); - - - // Then - console.Write(table); - return Verifier.Verify(console.Output); - } - } - - [UsesVerify] - public sealed class TheRemoveRowMethod - { - [Fact] - [Expectation("Remove")] - public Task Should_Remove_Row() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.AddColumn("Column #1"); - table.AddColumn("Column #2"); - table.AddRow(new[] { new Text("1"), new Text("1-2") }); - table.AddRow(new[] { new Text("2"), new Text("2-2") }); - table.AddRow(new[] { new Text("3"), new Text("3-2") }); - - // When - table.RemoveRow(1); - - // Then - console.Write(table); - return Verifier.Verify(console.Output); - } + // Then + return Verifier.Verify(console.Output); } } -} \ No newline at end of file + + [UsesVerify] + public sealed class TheInsertRowMethod + { + [Fact] + [Expectation("Insert", "Renderables")] + public Task Should_Insert_Renderables() + { + // Given + var console = new TestConsole(); + var table = new Table(); + table.AddColumn("Column #1"); + table.AddColumn("Column #2"); + table.AddRow(new[] { new Text("1"), new Text("1-2") }); + table.AddRow(new[] { new Text("2"), new Text("2-2") }); + + // When + table.InsertRow(1, new[] { new Text("3"), new Text("3-2") }); + + // Then + console.Write(table); + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Insert", "Strings")] + public Task Should_Insert_Strings() + { + // Given + var console = new TestConsole(); + var table = new Table(); + table.AddColumn("Column #1"); + table.AddColumn("Column #2"); + table.AddRow("1", "1-2"); + table.AddRow("2", "2-2"); + + // When + table.InsertRow(1, "3", "3-2"); + + // Then + console.Write(table); + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class TheRemoveRowMethod + { + [Fact] + [Expectation("Remove")] + public Task Should_Remove_Row() + { + // Given + var console = new TestConsole(); + var table = new Table(); + table.AddColumn("Column #1"); + table.AddColumn("Column #2"); + table.AddRow(new[] { new Text("1"), new Text("1-2") }); + table.AddRow(new[] { new Text("2"), new Text("2-2") }); + table.AddRow(new[] { new Text("3"), new Text("3-2") }); + + // When + table.RemoveRow(1); + + // Then + console.Write(table); + return Verifier.Verify(console.Output); + } + } +} diff --git a/test/Spectre.Console.Tests/Unit/Widgets/Table/TableRowCollectionTests.cs b/test/Spectre.Console.Tests/Unit/Widgets/Table/TableRowCollectionTests.cs index 6f44475..12952eb 100644 --- a/test/Spectre.Console.Tests/Unit/Widgets/Table/TableRowCollectionTests.cs +++ b/test/Spectre.Console.Tests/Unit/Widgets/Table/TableRowCollectionTests.cs @@ -1,366 +1,353 @@ -using System; -using System.Threading.Tasks; -using Shouldly; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[ExpectationPath("Widgets/Table/Rows")] +public sealed class TableRowCollectionTests { - [ExpectationPath("Widgets/Table/Rows")] - public sealed class TableRowCollectionTests + [UsesVerify] + public sealed class TheAddMethod { - [UsesVerify] - public sealed class TheAddMethod + [Fact] + public void Should_Throw_If_Columns_Are_Null() { - [Fact] - public void Should_Throw_If_Columns_Are_Null() - { - // Given - var table = new Table(); + // Given + var table = new Table(); - // When - var result = Record.Exception(() => table.Rows.Add(null)); + // When + var result = Record.Exception(() => table.Rows.Add(null)); - // Then - result.ShouldBeOfType() - .ParamName.ShouldBe("columns"); - } - - [Fact] - public void Should_Add_Row_To_Collection() - { - // Given - var table = new Table(); - table.AddColumn("Column #1"); - - // When - table.Rows.Add(new[] { Text.Empty }); - - // Then - table.Rows.Count.ShouldBe(1); - } - - [Fact] - public void Should_Return_Index_Of_Added_Row() - { - // Given - var table = new Table(); - table.AddColumn("Column #1"); - table.Rows.Add(new[] { Text.Empty }); - - // When - var result = table.Rows.Add(new[] { Text.Empty }); - - // Then - result.ShouldBe(1); - } - - [Fact] - [Expectation("Add")] - public Task Should_Add_Item_At_Correct_Place() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.AddColumn("Column #1"); - table.Rows.Add(new[] { new Text("1") }); - table.Rows.Add(new[] { new Text("2") }); - table.Rows.Add(new[] { new Text("3") }); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } + // Then + result.ShouldBeOfType() + .ParamName.ShouldBe("columns"); } - [UsesVerify] - public sealed class TheInsertMethod + [Fact] + public void Should_Add_Row_To_Collection() { - [Fact] - public void Should_Throw_If_Columns_Are_Null() - { - // Given - var table = new Table(); + // Given + var table = new Table(); + table.AddColumn("Column #1"); - // When - var result = Record.Exception(() => table.Rows.Insert(0, null)); + // When + table.Rows.Add(new[] { Text.Empty }); - // Then - result.ShouldBeOfType() - .ParamName.ShouldBe("columns"); - } - - [Fact] - public void Should_Insert_Row() - { - // Given - var table = new Table(); - table.AddColumn("Column #1"); - table.Rows.Add(new[] { Text.Empty }); - - // When - table.Rows.Insert(0, new[] { Text.Empty }); - - // Then - table.Rows.Count.ShouldBe(2); - } - - [Fact] - public void Should_Return_Index_Of_Inserted_Row() - { - // Given - var table = new Table(); - table.AddColumn("Column #1"); - table.Rows.Add(new[] { new Text("1") }); - table.Rows.Add(new[] { new Text("2") }); - - // When - var result = table.Rows.Insert(1, new[] { new Text("3") }); - - // Then - result.ShouldBe(1); - } - - [Fact] - [Expectation("Insert")] - public Task Should_Insert_Item_At_Correct_Place() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.AddColumn("Column #1"); - table.Rows.Add(new[] { new Text("1") }); - table.Rows.Add(new[] { new Text("2") }); - table.Rows.Insert(1, new[] { new Text("3") }); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } + // Then + table.Rows.Count.ShouldBe(1); } - [UsesVerify] - public sealed class TheRemoveMethod + [Fact] + public void Should_Return_Index_Of_Added_Row() { - [Fact] - public void Should_Throw_If_Index_Is_Negative() - { - // Given - var table = new Table(); - table.AddColumn("Column #1"); + // Given + var table = new Table(); + table.AddColumn("Column #1"); + table.Rows.Add(new[] { Text.Empty }); - // When - var result = Record.Exception(() => table.Rows.RemoveAt(-1)); + // When + var result = table.Rows.Add(new[] { Text.Empty }); - // Then - result.ShouldBeOfType() - .Message.ShouldBe("Table row index cannot be negative."); - } - - [Fact] - public void Should_Throw_If_Index_Is_Larger_Than_Number_Of_Rows() - { - // Given - var table = new Table(); - table.AddColumn("Column #1"); - table.Rows.Add(new[] { new Text("1") }); - table.Rows.Add(new[] { new Text("2") }); - table.Rows.Add(new[] { new Text("3") }); - - // When - var result = Record.Exception(() => table.Rows.RemoveAt(3)); - - // Then - result.ShouldBeOfType() - .Message.ShouldBe("Table row index cannot exceed the number of rows in the table."); - } - - [Fact] - [Expectation("Remove")] - public Task Should_Remove_Row() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.AddColumn("Column #1"); - table.Rows.Add(new[] { new Text("1") }); - table.Rows.Add(new[] { new Text("2") }); - table.Rows.Add(new[] { new Text("3") }); - table.Rows.RemoveAt(1); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } + // Then + result.ShouldBe(1); } - public sealed class TheClearMethod + [Fact] + [Expectation("Add")] + public Task Should_Add_Item_At_Correct_Place() { - [Fact] - public void Should_Remove_All_Rows() - { - // Given - var table = new Table(); - table.AddColumn("Column #1"); - table.Rows.Add(new[] { new Text("1") }); - table.Rows.Add(new[] { new Text("2") }); - table.Rows.Add(new[] { new Text("3") }); - table.Rows.Clear(); + // Given + var console = new TestConsole(); + var table = new Table(); + table.AddColumn("Column #1"); + table.Rows.Add(new[] { new Text("1") }); + table.Rows.Add(new[] { new Text("2") }); + table.Rows.Add(new[] { new Text("3") }); - // When - var result = table.Rows.Count; + // When + console.Write(table); - // Then - result.ShouldBe(0); - } - } - - [UsesVerify] - public sealed class TheUpdateMethod - { - [Fact] - public Task Should_Update_Row_With_String() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.AddColumn("Column #1"); - table.AddColumn("Column #2"); - table.AddColumn("Column #3"); - table.Rows.Add(new[] { new Text("1") }); - table.Rows.Add(new[] { new Text("2") }); - table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") }); - - table.UpdateCell(2, 2, "5"); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - public Task Should_Update_Row_With_Renderable() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.AddColumn("Column #1"); - table.AddColumn("Column #2"); - table.AddColumn("Column #3"); - table.Rows.Add(new[] { new Text("1") }); - table.Rows.Add(new[] { new Text("2") }); - table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") }); - - table.UpdateCell(2, 2, new Markup("5")); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - public void Should_Throw_If_Index_Is_Larger_Than_Number_Of_Rows() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.AddColumn("Column #1"); - table.AddColumn("Column #2"); - table.AddColumn("Column #3"); - table.Rows.Add(new[] { new Text("1") }); - table.Rows.Add(new[] { new Text("2") }); - table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") }); - table.UpdateCell(2, 2, "5"); - - - // When - var result = Record.Exception(() => table.UpdateCell(5, 2, "5")); - - // Then - result.ShouldBeOfType() - .Message.ShouldBe("Table row index cannot exceed the number of rows in the table."); - } - - [Fact] - public void Should_Throw_If_Index_Is_Larger_Than_Number_Of_Columns() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.AddColumn("Column #1"); - table.AddColumn("Column #2"); - table.AddColumn("Column #3"); - table.Rows.Add(new[] { new Text("1") }); - table.Rows.Add(new[] { new Text("2") }); - table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") }); - table.UpdateCell(2, 2, "5"); - - - // When - var result = Record.Exception(() => table.UpdateCell(2, 5, "5")); - - // Then - result.ShouldBeOfType() - .Message.ShouldBe("Table column index cannot exceed the number of rows in the table."); - } - - [Fact] - public void Should_Throw_If_Index_Row_Is_Negative() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.AddColumn("Column #1"); - table.AddColumn("Column #2"); - table.AddColumn("Column #3"); - table.Rows.Add(new[] { new Text("1") }); - table.Rows.Add(new[] { new Text("2") }); - table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") }); - table.UpdateCell(2, 2, "5"); - - - // When - var result = Record.Exception(() => table.UpdateCell(-1, 2, "5")); - - // Then - result.ShouldBeOfType() - .Message.ShouldBe("Table row index cannot be negative."); - } - - [Fact] - public void Should_Throw_If_Index_Column_Is_Negative() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.AddColumn("Column #1"); - table.AddColumn("Column #2"); - table.AddColumn("Column #3"); - table.Rows.Add(new[] { new Text("1") }); - table.Rows.Add(new[] { new Text("2") }); - table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") }); - table.UpdateCell(2, 2, "5"); - - - // When - var result = Record.Exception(() => table.UpdateCell(2, -1, "5")); - - // Then - result.ShouldBeOfType() - .Message.ShouldBe("Table column index cannot be negative."); - } + // Then + return Verifier.Verify(console.Output); } } -} \ No newline at end of file + + [UsesVerify] + public sealed class TheInsertMethod + { + [Fact] + public void Should_Throw_If_Columns_Are_Null() + { + // Given + var table = new Table(); + + // When + var result = Record.Exception(() => table.Rows.Insert(0, null)); + + // Then + result.ShouldBeOfType() + .ParamName.ShouldBe("columns"); + } + + [Fact] + public void Should_Insert_Row() + { + // Given + var table = new Table(); + table.AddColumn("Column #1"); + table.Rows.Add(new[] { Text.Empty }); + + // When + table.Rows.Insert(0, new[] { Text.Empty }); + + // Then + table.Rows.Count.ShouldBe(2); + } + + [Fact] + public void Should_Return_Index_Of_Inserted_Row() + { + // Given + var table = new Table(); + table.AddColumn("Column #1"); + table.Rows.Add(new[] { new Text("1") }); + table.Rows.Add(new[] { new Text("2") }); + + // When + var result = table.Rows.Insert(1, new[] { new Text("3") }); + + // Then + result.ShouldBe(1); + } + + [Fact] + [Expectation("Insert")] + public Task Should_Insert_Item_At_Correct_Place() + { + // Given + var console = new TestConsole(); + var table = new Table(); + table.AddColumn("Column #1"); + table.Rows.Add(new[] { new Text("1") }); + table.Rows.Add(new[] { new Text("2") }); + table.Rows.Insert(1, new[] { new Text("3") }); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + } + + [UsesVerify] + public sealed class TheRemoveMethod + { + [Fact] + public void Should_Throw_If_Index_Is_Negative() + { + // Given + var table = new Table(); + table.AddColumn("Column #1"); + + // When + var result = Record.Exception(() => table.Rows.RemoveAt(-1)); + + // Then + result.ShouldBeOfType() + .Message.ShouldBe("Table row index cannot be negative."); + } + + [Fact] + public void Should_Throw_If_Index_Is_Larger_Than_Number_Of_Rows() + { + // Given + var table = new Table(); + table.AddColumn("Column #1"); + table.Rows.Add(new[] { new Text("1") }); + table.Rows.Add(new[] { new Text("2") }); + table.Rows.Add(new[] { new Text("3") }); + + // When + var result = Record.Exception(() => table.Rows.RemoveAt(3)); + + // Then + result.ShouldBeOfType() + .Message.ShouldBe("Table row index cannot exceed the number of rows in the table."); + } + + [Fact] + [Expectation("Remove")] + public Task Should_Remove_Row() + { + // Given + var console = new TestConsole(); + var table = new Table(); + table.AddColumn("Column #1"); + table.Rows.Add(new[] { new Text("1") }); + table.Rows.Add(new[] { new Text("2") }); + table.Rows.Add(new[] { new Text("3") }); + table.Rows.RemoveAt(1); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + } + + public sealed class TheClearMethod + { + [Fact] + public void Should_Remove_All_Rows() + { + // Given + var table = new Table(); + table.AddColumn("Column #1"); + table.Rows.Add(new[] { new Text("1") }); + table.Rows.Add(new[] { new Text("2") }); + table.Rows.Add(new[] { new Text("3") }); + table.Rows.Clear(); + + // When + var result = table.Rows.Count; + + // Then + result.ShouldBe(0); + } + } + + [UsesVerify] + public sealed class TheUpdateMethod + { + [Fact] + public Task Should_Update_Row_With_String() + { + // Given + var console = new TestConsole(); + var table = new Table(); + table.AddColumn("Column #1"); + table.AddColumn("Column #2"); + table.AddColumn("Column #3"); + table.Rows.Add(new[] { new Text("1") }); + table.Rows.Add(new[] { new Text("2") }); + table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") }); + + table.UpdateCell(2, 2, "5"); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + public Task Should_Update_Row_With_Renderable() + { + // Given + var console = new TestConsole(); + var table = new Table(); + table.AddColumn("Column #1"); + table.AddColumn("Column #2"); + table.AddColumn("Column #3"); + table.Rows.Add(new[] { new Text("1") }); + table.Rows.Add(new[] { new Text("2") }); + table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") }); + + table.UpdateCell(2, 2, new Markup("5")); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + public void Should_Throw_If_Index_Is_Larger_Than_Number_Of_Rows() + { + // Given + var console = new TestConsole(); + var table = new Table(); + table.AddColumn("Column #1"); + table.AddColumn("Column #2"); + table.AddColumn("Column #3"); + table.Rows.Add(new[] { new Text("1") }); + table.Rows.Add(new[] { new Text("2") }); + table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") }); + table.UpdateCell(2, 2, "5"); + + // When + var result = Record.Exception(() => table.UpdateCell(5, 2, "5")); + + // Then + result.ShouldBeOfType() + .Message.ShouldBe("Table row index cannot exceed the number of rows in the table."); + } + + [Fact] + public void Should_Throw_If_Index_Is_Larger_Than_Number_Of_Columns() + { + // Given + var console = new TestConsole(); + var table = new Table(); + table.AddColumn("Column #1"); + table.AddColumn("Column #2"); + table.AddColumn("Column #3"); + table.Rows.Add(new[] { new Text("1") }); + table.Rows.Add(new[] { new Text("2") }); + table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") }); + table.UpdateCell(2, 2, "5"); + + // When + var result = Record.Exception(() => table.UpdateCell(2, 5, "5")); + + // Then + result.ShouldBeOfType() + .Message.ShouldBe("Table column index cannot exceed the number of rows in the table."); + } + + [Fact] + public void Should_Throw_If_Index_Row_Is_Negative() + { + // Given + var console = new TestConsole(); + var table = new Table(); + table.AddColumn("Column #1"); + table.AddColumn("Column #2"); + table.AddColumn("Column #3"); + table.Rows.Add(new[] { new Text("1") }); + table.Rows.Add(new[] { new Text("2") }); + table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") }); + table.UpdateCell(2, 2, "5"); + + // When + var result = Record.Exception(() => table.UpdateCell(-1, 2, "5")); + + // Then + result.ShouldBeOfType() + .Message.ShouldBe("Table row index cannot be negative."); + } + + [Fact] + public void Should_Throw_If_Index_Column_Is_Negative() + { + // Given + var console = new TestConsole(); + var table = new Table(); + table.AddColumn("Column #1"); + table.AddColumn("Column #2"); + table.AddColumn("Column #3"); + table.Rows.Add(new[] { new Text("1") }); + table.Rows.Add(new[] { new Text("2") }); + table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") }); + table.UpdateCell(2, 2, "5"); + + // When + var result = Record.Exception(() => table.UpdateCell(2, -1, "5")); + + // Then + result.ShouldBeOfType() + .Message.ShouldBe("Table column index cannot be negative."); + } + } +} diff --git a/test/Spectre.Console.Tests/Unit/Widgets/Table/TableTests.cs b/test/Spectre.Console.Tests/Unit/Widgets/Table/TableTests.cs index 62b67bc..2716fbb 100644 --- a/test/Spectre.Console.Tests/Unit/Widgets/Table/TableTests.cs +++ b/test/Spectre.Console.Tests/Unit/Widgets/Table/TableTests.cs @@ -1,139 +1,111 @@ -using System; -using System.Threading.Tasks; -using Shouldly; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("Widgets/Table")] +public sealed class TableTests { - [UsesVerify] - [ExpectationPath("Widgets/Table")] - public sealed class TableTests + public sealed class TheAddColumnMethod { - public sealed class TheAddColumnMethod + [Fact] + public void Should_Throw_If_Column_Is_Null() { - [Fact] - public void Should_Throw_If_Column_Is_Null() - { - // Given - var table = new Table(); + // Given + var table = new Table(); - // When - var result = Record.Exception(() => table.AddColumn((string)null)); + // When + var result = Record.Exception(() => table.AddColumn((string)null)); - // Then - result.ShouldBeOfType() - .ParamName.ShouldBe("column"); - } - - [Fact] - public void Should_Throw_If_Rows_Are_Not_Empty() - { - // Given - var grid = new Table(); - grid.AddColumn("Foo"); - grid.AddRow("Hello World"); - - // When - var result = Record.Exception(() => grid.AddColumn("Bar")); - - // Then - result.ShouldBeOfType() - .Message.ShouldBe("Cannot add new columns to table with existing rows."); - } - } - - public sealed class TheAddColumnsMethod - { - [Fact] - public void Should_Throw_If_Columns_Are_Null() - { - // Given - var table = new Table(); - - // When - var result = Record.Exception(() => table.AddColumns((string[])null)); - - // Then - result.ShouldBeOfType() - .ParamName.ShouldBe("columns"); - } - } - - public sealed class TheAddRowMethod - { - [Fact] - public void Should_Throw_If_String_Rows_Are_Null() - { - // Given - var table = new Table(); - - // When - var result = Record.Exception(() => table.AddRow((string[])null)); - - // Then - result.ShouldBeOfType() - .ParamName.ShouldBe("columns"); - } - - [Fact] - public void Should_Add_Empty_Items_If_User_Provides_Less_Row_Items_Than_Columns() - { - // Given - var table = new Table(); - table.AddColumn("Hello"); - table.AddColumn("World"); - - // When - table.AddRow("Foo"); - - // Then - table.Rows.Count.ShouldBe(1); - } - - [Fact] - public void Should_Throw_If_Row_Columns_Are_Greater_Than_Number_Of_Columns() - { - // Given - var table = new Table(); - table.AddColumn("Hello"); - - // When - var result = Record.Exception(() => table.AddRow("Foo", "Bar")); - - // Then - result.ShouldBeOfType(); - result.Message.ShouldBe("The number of row columns are greater than the number of table columns."); - } - } - - [UsesVerify] - public sealed class TheAddEmptyRowMethod - { - [Fact] - [Expectation("AddEmptyRow")] - public Task Should_Render_Table_Correctly() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.AddColumns("Foo", "Bar", "Baz"); - table.AddRow("Qux", "Corgi", "Waldo"); - table.AddEmptyRow(); - table.AddRow("Grault", "Garply", "Fred"); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } + // Then + result.ShouldBeOfType() + .ParamName.ShouldBe("column"); } [Fact] - [Expectation("Render")] + public void Should_Throw_If_Rows_Are_Not_Empty() + { + // Given + var grid = new Table(); + grid.AddColumn("Foo"); + grid.AddRow("Hello World"); + + // When + var result = Record.Exception(() => grid.AddColumn("Bar")); + + // Then + result.ShouldBeOfType() + .Message.ShouldBe("Cannot add new columns to table with existing rows."); + } + } + + public sealed class TheAddColumnsMethod + { + [Fact] + public void Should_Throw_If_Columns_Are_Null() + { + // Given + var table = new Table(); + + // When + var result = Record.Exception(() => table.AddColumns((string[])null)); + + // Then + result.ShouldBeOfType() + .ParamName.ShouldBe("columns"); + } + } + + public sealed class TheAddRowMethod + { + [Fact] + public void Should_Throw_If_String_Rows_Are_Null() + { + // Given + var table = new Table(); + + // When + var result = Record.Exception(() => table.AddRow((string[])null)); + + // Then + result.ShouldBeOfType() + .ParamName.ShouldBe("columns"); + } + + [Fact] + public void Should_Add_Empty_Items_If_User_Provides_Less_Row_Items_Than_Columns() + { + // Given + var table = new Table(); + table.AddColumn("Hello"); + table.AddColumn("World"); + + // When + table.AddRow("Foo"); + + // Then + table.Rows.Count.ShouldBe(1); + } + + [Fact] + public void Should_Throw_If_Row_Columns_Are_Greater_Than_Number_Of_Columns() + { + // Given + var table = new Table(); + table.AddColumn("Hello"); + + // When + var result = Record.Exception(() => table.AddRow("Foo", "Bar")); + + // Then + result.ShouldBeOfType(); + result.Message.ShouldBe("The number of row columns are greater than the number of table columns."); + } + } + + [UsesVerify] + public sealed class TheAddEmptyRowMethod + { + [Fact] + [Expectation("AddEmptyRow")] public Task Should_Render_Table_Correctly() { // Given @@ -141,6 +113,7 @@ namespace Spectre.Console.Tests.Unit var table = new Table(); table.AddColumns("Foo", "Bar", "Baz"); table.AddRow("Qux", "Corgi", "Waldo"); + table.AddEmptyRow(); table.AddRow("Grault", "Garply", "Fred"); // When @@ -149,377 +122,395 @@ namespace Spectre.Console.Tests.Unit // Then return Verifier.Verify(console.Output); } - - [Fact] - [Expectation("Render_EA_Character")] - public Task Should_Render_Table_With_EA_Character_Correctly() - { - // Given - var console = new TestConsole().Width(48); - var table = new Table(); - table.AddColumns("Foo", "Bar", "Baz"); - table.AddRow("中文", "日本語", "한국어"); - table.AddRow("这是中文测试字符串", "これは日本語のテスト文字列です", "이것은한국어테스트문자열입니다"); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Footers")] - public Task Should_Render_Table_With_Footers_Correctly() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.AddColumn(new TableColumn("Foo").Footer("Oof").RightAligned()); - table.AddColumn("Bar"); - table.AddColumns(new TableColumn("Baz").Footer("Zab")); - table.AddRow("Qux", "Corgi", "Waldo"); - table.AddRow("Grault", "Garply", "Fred"); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_LeftAligned")] - public Task Should_Left_Align_Table_Correctly() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.Alignment = Justify.Left; - table.AddColumns("Foo", "Bar", "Baz"); - table.AddRow("Qux", "Corgi", "Waldo"); - table.AddRow("Grault", "Garply", "Fred"); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Centered")] - public Task Should_Center_Table_Correctly() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.Alignment = Justify.Center; - table.AddColumns("Foo", "Bar", "Baz"); - table.AddRow("Qux", "Corgi", "Waldo"); - table.AddRow("Grault", "Garply", "Fred"); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_RightAligned")] - public Task Should_Right_Align_Table_Correctly() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.Alignment = Justify.Right; - table.AddColumns("Foo", "Bar", "Baz"); - table.AddRow("Qux", "Corgi", "Waldo"); - table.AddRow("Grault", "Garply", "Fred"); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Nested")] - public Task Should_Render_Table_Nested_In_Panels_Correctly() - { - // A simple table - var console = new TestConsole(); - var table = new Table() { Border = TableBorder.Rounded }; - table.AddColumn("Foo"); - table.AddColumn("Bar"); - table.AddColumn(new TableColumn("Baz") { Alignment = Justify.Right }); - table.AddRow("Qux\nQuuuuuux", "[blue]Corgi[/]", "Waldo"); - table.AddRow("Grault", "Garply", "Fred"); - - // Render a table in some panels. - console.Write(new Panel(new Panel(table) - { - Border = BoxBorder.Ascii, - })); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_ColumnJustification")] - public Task Should_Render_Table_With_Column_Justification_Correctly() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.AddColumn(new TableColumn("Foo") { Alignment = Justify.Left }); - table.AddColumn(new TableColumn("Bar") { Alignment = Justify.Right }); - table.AddColumn(new TableColumn("Baz") { Alignment = Justify.Center }); - table.AddRow("Qux", "Corgi", "Waldo"); - table.AddRow("Grault", "Garply", "Lorem ipsum dolor sit amet"); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Expand")] - public Task Should_Expand_Table_To_Available_Space_If_Specified() - { - // Given - var console = new TestConsole(); - var table = new Table() { Expand = true }; - table.AddColumns("Foo", "Bar", "Baz"); - table.AddRow("Qux", "Corgi", "Waldo"); - table.AddRow("Grault", "Garply", "Fred"); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Multiline")] - public Task Should_Render_Table_With_Multiple_Rows_In_Cell_Correctly() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.AddColumns("Foo", "Bar", "Baz"); - table.AddRow("Qux\nQuuux", "Corgi", "Waldo"); - table.AddRow("Grault", "Garply", "Fred"); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_CellPadding")] - public Task Should_Render_Table_With_Cell_Padding_Correctly() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.AddColumns("Foo", "Bar"); - table.AddColumn(new TableColumn("Baz") { Padding = new Padding(3, 0, 2, 0) }); - table.AddRow("Qux\nQuuux", "Corgi", "Waldo"); - table.AddRow("Grault", "Garply", "Fred"); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_NoRows")] - public Task Should_Render_Table_Without_Rows() - { - // Given - var console = new TestConsole(); - var table = new Table(); - table.AddColumns("Foo", "Bar"); - table.AddColumn(new TableColumn("Baz") { Padding = new Padding(3, 0, 2, 0) }); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Impossible")] - public Task Should_Not_Draw_Tables_That_Are_Impossible_To_Draw() - { - // Given - var console = new TestConsole().Width(25); - - var first = new Table().Border(TableBorder.Rounded).BorderColor(Color.Red); - first.AddColumn(new TableColumn("[u]PS1[/]").Centered()); - first.AddColumn(new TableColumn("[u]PS2[/]")); - first.AddColumn(new TableColumn("[u]PS3[/]")); - first.AddRow("Hello", "[red]World[/]", string.Empty); - first.AddRow("[blue]Bonjour[/]", "[white]le[/]", "[red]monde![/]"); - first.AddRow("[blue]Hej[/]", "[yellow]Världen[/]", string.Empty); - - var second = new Table().Border(TableBorder.Square).BorderColor(Color.Green); - second.AddColumn(new TableColumn("[u]Foo[/]")); - second.AddColumn(new TableColumn("[u]Bar[/]")); - second.AddColumn(new TableColumn("[u]Baz[/]")); - second.AddRow("Hello", "[red]World[/]", string.Empty); - second.AddRow(first, new Text("Whaaat"), new Text("Lolz")); - second.AddRow("[blue]Hej[/]", "[yellow]Världen[/]", string.Empty); - - var table = new Table().Border(TableBorder.Rounded); - table.AddColumn(new TableColumn(new Panel("[u]ABC[/]").BorderColor(Color.Red))); - table.AddColumn(new TableColumn(new Panel("[u]DEF[/]").BorderColor(Color.Green))); - table.AddColumn(new TableColumn(new Panel("[u]GHI[/]").BorderColor(Color.Blue))); - table.AddRow(new Text("Hello").Centered(), new Markup("[red]World[/]"), Text.Empty); - table.AddRow(second, new Text("Whaat"), new Text("Lol").RightAligned()); - table.AddRow(new Markup("[blue]Hej[/]"), new Markup("[yellow]Världen[/]"), Text.Empty); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Title_Caption")] - public Task Should_Render_Table_With_Title_And_Caption_Correctly() - { - // Given - var console = new TestConsole(); - var table = new Table { Border = TableBorder.Rounded }; - table.Title = new TableTitle("Hello World"); - table.Caption = new TableTitle("Goodbye World"); - table.AddColumns("Foo", "Bar", "Baz"); - table.AddRow("Qux", "Corgi", "Waldo"); - table.AddRow("Grault", "Garply", "Fred"); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Title_Caption_LeftAligned")] - public Task Should_Left_Align_Table_With_Title_And_Caption_Correctly() - { - // Given - var console = new TestConsole(); - var table = new Table { Border = TableBorder.Rounded }; - table.LeftAligned(); - table.Title = new TableTitle("Hello World"); - table.Caption = new TableTitle("Goodbye World"); - table.AddColumns("Foo", "Bar", "Baz"); - table.AddRow("Qux", "Corgi", "Waldo"); - table.AddRow("Grault", "Garply", "Fred"); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Title_Caption_Centered")] - public Task Should_Center_Table_With_Title_And_Caption_Correctly() - { - // Given - var console = new TestConsole(); - var table = new Table { Border = TableBorder.Rounded }; - table.Centered(); - table.Title = new TableTitle("Hello World"); - table.Caption = new TableTitle("Goodbye World"); - table.AddColumns("Foo", "Bar", "Baz"); - table.AddRow("Qux", "Corgi", "Waldo"); - table.AddRow("Grault", "Garply", "Fred"); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Title_Caption_RightAligned")] - public Task Should_Right_Align_Table_With_Title_And_Caption_Correctly() - { - // Given - var console = new TestConsole(); - var table = new Table { Border = TableBorder.Rounded }; - table.RightAligned(); - table.Title = new TableTitle("Hello World"); - table.Caption = new TableTitle("Goodbye World"); - table.AddColumns("Foo", "Bar", "Baz"); - table.AddRow("Qux", "Corgi", "Waldo"); - table.AddRow("Grault", "Garply", "Fred"); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Title_Caption_LowerCase")] - public Task Should_Render_Table_Without_Capitalizing_First_Letter() - { - // Given - var console = new TestConsole(); - var table = new Table { Border = TableBorder.Rounded }; - table.Title = new TableTitle("hello world"); - table.Caption = new TableTitle("goodbye world"); - table.AddColumns("Foo", "Bar", "Baz"); - table.AddRow("Qux", "Corgi", "Waldo"); - table.AddRow("Grault", "Garply", "Fred"); - - // When - console.Write(table); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_Fold")] - public Task Should_Render_With_Folded_Text_Table_Correctly() - { - // Given - var console = new TestConsole().Width(30); - var table = new Table(); - table.AddColumns("Foo", "Bar", "Baz"); - table.AddRow("Qux With A Long Description", "Corgi", "Waldo"); - table.AddRow("Grault", "Garply", "Fred On A Long Long Walk"); - - var panel = new Panel(table); - panel.Border = BoxBorder.Double; - - // When - console.Write(panel); - - // Then - return Verifier.Verify(console.Output); - } } -} \ No newline at end of file + + [Fact] + [Expectation("Render")] + public Task Should_Render_Table_Correctly() + { + // Given + var console = new TestConsole(); + var table = new Table(); + table.AddColumns("Foo", "Bar", "Baz"); + table.AddRow("Qux", "Corgi", "Waldo"); + table.AddRow("Grault", "Garply", "Fred"); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_EA_Character")] + public Task Should_Render_Table_With_EA_Character_Correctly() + { + // Given + var console = new TestConsole().Width(48); + var table = new Table(); + table.AddColumns("Foo", "Bar", "Baz"); + table.AddRow("中文", "日本語", "한국어"); + table.AddRow("这是中文测试字符串", "これは日本語のテスト文字列です", "이것은한국어테스트문자열입니다"); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Footers")] + public Task Should_Render_Table_With_Footers_Correctly() + { + // Given + var console = new TestConsole(); + var table = new Table(); + table.AddColumn(new TableColumn("Foo").Footer("Oof").RightAligned()); + table.AddColumn("Bar"); + table.AddColumns(new TableColumn("Baz").Footer("Zab")); + table.AddRow("Qux", "Corgi", "Waldo"); + table.AddRow("Grault", "Garply", "Fred"); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_LeftAligned")] + public Task Should_Left_Align_Table_Correctly() + { + // Given + var console = new TestConsole(); + var table = new Table(); + table.Alignment = Justify.Left; + table.AddColumns("Foo", "Bar", "Baz"); + table.AddRow("Qux", "Corgi", "Waldo"); + table.AddRow("Grault", "Garply", "Fred"); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Centered")] + public Task Should_Center_Table_Correctly() + { + // Given + var console = new TestConsole(); + var table = new Table(); + table.Alignment = Justify.Center; + table.AddColumns("Foo", "Bar", "Baz"); + table.AddRow("Qux", "Corgi", "Waldo"); + table.AddRow("Grault", "Garply", "Fred"); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_RightAligned")] + public Task Should_Right_Align_Table_Correctly() + { + // Given + var console = new TestConsole(); + var table = new Table(); + table.Alignment = Justify.Right; + table.AddColumns("Foo", "Bar", "Baz"); + table.AddRow("Qux", "Corgi", "Waldo"); + table.AddRow("Grault", "Garply", "Fred"); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Nested")] + public Task Should_Render_Table_Nested_In_Panels_Correctly() + { + // A simple table + var console = new TestConsole(); + var table = new Table() { Border = TableBorder.Rounded }; + table.AddColumn("Foo"); + table.AddColumn("Bar"); + table.AddColumn(new TableColumn("Baz") { Alignment = Justify.Right }); + table.AddRow("Qux\nQuuuuuux", "[blue]Corgi[/]", "Waldo"); + table.AddRow("Grault", "Garply", "Fred"); + + // Render a table in some panels. + console.Write(new Panel(new Panel(table) + { + Border = BoxBorder.Ascii, + })); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_ColumnJustification")] + public Task Should_Render_Table_With_Column_Justification_Correctly() + { + // Given + var console = new TestConsole(); + var table = new Table(); + table.AddColumn(new TableColumn("Foo") { Alignment = Justify.Left }); + table.AddColumn(new TableColumn("Bar") { Alignment = Justify.Right }); + table.AddColumn(new TableColumn("Baz") { Alignment = Justify.Center }); + table.AddRow("Qux", "Corgi", "Waldo"); + table.AddRow("Grault", "Garply", "Lorem ipsum dolor sit amet"); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Expand")] + public Task Should_Expand_Table_To_Available_Space_If_Specified() + { + // Given + var console = new TestConsole(); + var table = new Table() { Expand = true }; + table.AddColumns("Foo", "Bar", "Baz"); + table.AddRow("Qux", "Corgi", "Waldo"); + table.AddRow("Grault", "Garply", "Fred"); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Multiline")] + public Task Should_Render_Table_With_Multiple_Rows_In_Cell_Correctly() + { + // Given + var console = new TestConsole(); + var table = new Table(); + table.AddColumns("Foo", "Bar", "Baz"); + table.AddRow("Qux\nQuuux", "Corgi", "Waldo"); + table.AddRow("Grault", "Garply", "Fred"); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_CellPadding")] + public Task Should_Render_Table_With_Cell_Padding_Correctly() + { + // Given + var console = new TestConsole(); + var table = new Table(); + table.AddColumns("Foo", "Bar"); + table.AddColumn(new TableColumn("Baz") { Padding = new Padding(3, 0, 2, 0) }); + table.AddRow("Qux\nQuuux", "Corgi", "Waldo"); + table.AddRow("Grault", "Garply", "Fred"); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_NoRows")] + public Task Should_Render_Table_Without_Rows() + { + // Given + var console = new TestConsole(); + var table = new Table(); + table.AddColumns("Foo", "Bar"); + table.AddColumn(new TableColumn("Baz") { Padding = new Padding(3, 0, 2, 0) }); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Impossible")] + public Task Should_Not_Draw_Tables_That_Are_Impossible_To_Draw() + { + // Given + var console = new TestConsole().Width(25); + + var first = new Table().Border(TableBorder.Rounded).BorderColor(Color.Red); + first.AddColumn(new TableColumn("[u]PS1[/]").Centered()); + first.AddColumn(new TableColumn("[u]PS2[/]")); + first.AddColumn(new TableColumn("[u]PS3[/]")); + first.AddRow("Hello", "[red]World[/]", string.Empty); + first.AddRow("[blue]Bonjour[/]", "[white]le[/]", "[red]monde![/]"); + first.AddRow("[blue]Hej[/]", "[yellow]Världen[/]", string.Empty); + + var second = new Table().Border(TableBorder.Square).BorderColor(Color.Green); + second.AddColumn(new TableColumn("[u]Foo[/]")); + second.AddColumn(new TableColumn("[u]Bar[/]")); + second.AddColumn(new TableColumn("[u]Baz[/]")); + second.AddRow("Hello", "[red]World[/]", string.Empty); + second.AddRow(first, new Text("Whaaat"), new Text("Lolz")); + second.AddRow("[blue]Hej[/]", "[yellow]Världen[/]", string.Empty); + + var table = new Table().Border(TableBorder.Rounded); + table.AddColumn(new TableColumn(new Panel("[u]ABC[/]").BorderColor(Color.Red))); + table.AddColumn(new TableColumn(new Panel("[u]DEF[/]").BorderColor(Color.Green))); + table.AddColumn(new TableColumn(new Panel("[u]GHI[/]").BorderColor(Color.Blue))); + table.AddRow(new Text("Hello").Centered(), new Markup("[red]World[/]"), Text.Empty); + table.AddRow(second, new Text("Whaat"), new Text("Lol").RightAligned()); + table.AddRow(new Markup("[blue]Hej[/]"), new Markup("[yellow]Världen[/]"), Text.Empty); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Title_Caption")] + public Task Should_Render_Table_With_Title_And_Caption_Correctly() + { + // Given + var console = new TestConsole(); + var table = new Table { Border = TableBorder.Rounded }; + table.Title = new TableTitle("Hello World"); + table.Caption = new TableTitle("Goodbye World"); + table.AddColumns("Foo", "Bar", "Baz"); + table.AddRow("Qux", "Corgi", "Waldo"); + table.AddRow("Grault", "Garply", "Fred"); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Title_Caption_LeftAligned")] + public Task Should_Left_Align_Table_With_Title_And_Caption_Correctly() + { + // Given + var console = new TestConsole(); + var table = new Table { Border = TableBorder.Rounded }; + table.LeftAligned(); + table.Title = new TableTitle("Hello World"); + table.Caption = new TableTitle("Goodbye World"); + table.AddColumns("Foo", "Bar", "Baz"); + table.AddRow("Qux", "Corgi", "Waldo"); + table.AddRow("Grault", "Garply", "Fred"); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Title_Caption_Centered")] + public Task Should_Center_Table_With_Title_And_Caption_Correctly() + { + // Given + var console = new TestConsole(); + var table = new Table { Border = TableBorder.Rounded }; + table.Centered(); + table.Title = new TableTitle("Hello World"); + table.Caption = new TableTitle("Goodbye World"); + table.AddColumns("Foo", "Bar", "Baz"); + table.AddRow("Qux", "Corgi", "Waldo"); + table.AddRow("Grault", "Garply", "Fred"); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Title_Caption_RightAligned")] + public Task Should_Right_Align_Table_With_Title_And_Caption_Correctly() + { + // Given + var console = new TestConsole(); + var table = new Table { Border = TableBorder.Rounded }; + table.RightAligned(); + table.Title = new TableTitle("Hello World"); + table.Caption = new TableTitle("Goodbye World"); + table.AddColumns("Foo", "Bar", "Baz"); + table.AddRow("Qux", "Corgi", "Waldo"); + table.AddRow("Grault", "Garply", "Fred"); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Title_Caption_LowerCase")] + public Task Should_Render_Table_Without_Capitalizing_First_Letter() + { + // Given + var console = new TestConsole(); + var table = new Table { Border = TableBorder.Rounded }; + table.Title = new TableTitle("hello world"); + table.Caption = new TableTitle("goodbye world"); + table.AddColumns("Foo", "Bar", "Baz"); + table.AddRow("Qux", "Corgi", "Waldo"); + table.AddRow("Grault", "Garply", "Fred"); + + // When + console.Write(table); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + [Expectation("Render_Fold")] + public Task Should_Render_With_Folded_Text_Table_Correctly() + { + // Given + var console = new TestConsole().Width(30); + var table = new Table(); + table.AddColumns("Foo", "Bar", "Baz"); + table.AddRow("Qux With A Long Description", "Corgi", "Waldo"); + table.AddRow("Grault", "Garply", "Fred On A Long Long Walk"); + + var panel = new Panel(table); + panel.Border = BoxBorder.Double; + + // When + console.Write(panel); + + // Then + return Verifier.Verify(console.Output); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Widgets/TextTests.cs b/test/Spectre.Console.Tests/Unit/Widgets/TextTests.cs index 1447d01..cf08e23 100644 --- a/test/Spectre.Console.Tests/Unit/Widgets/TextTests.cs +++ b/test/Spectre.Console.Tests/Unit/Widgets/TextTests.cs @@ -1,158 +1,152 @@ -using Shouldly; -using Spectre.Console.Rendering; -using Spectre.Console.Testing; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +public sealed class TextTests { - public sealed class TextTests + public sealed class TheLengthProperty { - public sealed class TheLengthProperty - { - [Theory] - [InlineData("Hello", 5)] - [InlineData("Hello\nWorld", 11)] - public void Should_Return_The_Number_Of_Characters(string input, int expected) - { - // Given - var markup = new Text(input); - - // When - var result = markup.Length; - - // Then - result.ShouldBe(expected); - } - } - - public sealed class TheLinesProperty - { - [Theory] - [InlineData("Hello", 1)] - [InlineData("Hello\nWorld", 2)] - public void Should_Return_The_Number_Of_Lines(string input, int expected) - { - // Given - var markup = new Text(input); - - // When - var result = markup.Lines; - - // Then - result.ShouldBe(expected); - } - } - - [Fact] - public void Should_Consider_The_Longest_Word_As_Minimum_Width() - { - // Given - var caps = new TestCapabilities { Unicode = true }; - var text = new Text("Foo Bar Baz\nQux\nLol mobile"); - - // When - var result = ((IRenderable)text).Measure(caps.CreateRenderContext(), 80); - - // Then - result.Min.ShouldBe(6); - } - - [Fact] - public void Should_Consider_The_Longest_Line_As_Maximum_Width() - { - // Given - var caps = new TestCapabilities { Unicode = true }; - var text = new Text("Foo Bar Baz\nQux\nLol mobile"); - - // When - var result = ((IRenderable)text).Measure(caps.CreateRenderContext(), 80); - - // Then - result.Max.ShouldBe(11); - } - - [Fact] - public void Should_Render_Unstyled_Text_As_Expected() - { - // Given - var console = new TestConsole(); - var text = new Text("Hello World"); - - // When - console.Write(text); - - // Then - console.Output.ShouldBe("Hello World"); - } - [Theory] - [InlineData("Hello\n\nWorld\n\n")] - [InlineData("Hello\r\n\r\nWorld\r\n\r\n")] - public void Should_Write_Line_Breaks(string input) + [InlineData("Hello", 5)] + [InlineData("Hello\nWorld", 11)] + public void Should_Return_The_Number_Of_Characters(string input, int expected) { // Given - var console = new TestConsole(); - var text = new Text(input); + var markup = new Text(input); // When - console.Write(text); + var result = markup.Length; // Then - console.Output.ShouldBe("Hello\n\nWorld\n\n"); - } - - [Fact] - public void Should_Render_Panel_2() - { - // Given - var console = new TestConsole(); - - // When - console.Write(new Markup("[b]Hello World[/]\n[yellow]Hello World[/]")); - - // Then - console.Lines.Count.ShouldBe(2); - console.Lines[0].ShouldBe("Hello World"); - console.Lines[1].ShouldBe("Hello World"); - } - - [Theory] - [InlineData(5, "Hello World", "Hello\nWorld")] - [InlineData(10, "Hello Sweet Nice World", "Hello \nSweet Nice\nWorld")] - public void Should_Split_Unstyled_Text_To_New_Lines_If_Width_Exceeds_Console_Width( - int width, string input, string expected) - { - // Given - var console = new TestConsole().Width(width); - var text = new Text(input); - - // When - console.Write(text); - - // Then - console.Output - .NormalizeLineEndings() - .ShouldBe(expected); - } - - [Theory] - [InlineData(Overflow.Fold, "foo \npneumonoultram\nicroscopicsili\ncovolcanoconio\nsis bar qux")] - [InlineData(Overflow.Crop, "foo \npneumonoultram\nbar qux")] - [InlineData(Overflow.Ellipsis, "foo \npneumonoultra…\nbar qux")] - public void Should_Overflow_Text_Correctly(Overflow overflow, string expected) - { - // Given - var console = new TestConsole().Width(14); - var text = new Text("foo pneumonoultramicroscopicsilicovolcanoconiosis bar qux") - .Overflow(overflow); - - // When - console.Write(text); - - // Then - console.Output - .NormalizeLineEndings() - .ShouldBe(expected); + result.ShouldBe(expected); } } -} \ No newline at end of file + + public sealed class TheLinesProperty + { + [Theory] + [InlineData("Hello", 1)] + [InlineData("Hello\nWorld", 2)] + public void Should_Return_The_Number_Of_Lines(string input, int expected) + { + // Given + var markup = new Text(input); + + // When + var result = markup.Lines; + + // Then + result.ShouldBe(expected); + } + } + + [Fact] + public void Should_Consider_The_Longest_Word_As_Minimum_Width() + { + // Given + var caps = new TestCapabilities { Unicode = true }; + var text = new Text("Foo Bar Baz\nQux\nLol mobile"); + + // When + var result = ((IRenderable)text).Measure(caps.CreateRenderContext(), 80); + + // Then + result.Min.ShouldBe(6); + } + + [Fact] + public void Should_Consider_The_Longest_Line_As_Maximum_Width() + { + // Given + var caps = new TestCapabilities { Unicode = true }; + var text = new Text("Foo Bar Baz\nQux\nLol mobile"); + + // When + var result = ((IRenderable)text).Measure(caps.CreateRenderContext(), 80); + + // Then + result.Max.ShouldBe(11); + } + + [Fact] + public void Should_Render_Unstyled_Text_As_Expected() + { + // Given + var console = new TestConsole(); + var text = new Text("Hello World"); + + // When + console.Write(text); + + // Then + console.Output.ShouldBe("Hello World"); + } + + [Theory] + [InlineData("Hello\n\nWorld\n\n")] + [InlineData("Hello\r\n\r\nWorld\r\n\r\n")] + public void Should_Write_Line_Breaks(string input) + { + // Given + var console = new TestConsole(); + var text = new Text(input); + + // When + console.Write(text); + + // Then + console.Output.ShouldBe("Hello\n\nWorld\n\n"); + } + + [Fact] + public void Should_Render_Panel_2() + { + // Given + var console = new TestConsole(); + + // When + console.Write(new Markup("[b]Hello World[/]\n[yellow]Hello World[/]")); + + // Then + console.Lines.Count.ShouldBe(2); + console.Lines[0].ShouldBe("Hello World"); + console.Lines[1].ShouldBe("Hello World"); + } + + [Theory] + [InlineData(5, "Hello World", "Hello\nWorld")] + [InlineData(10, "Hello Sweet Nice World", "Hello \nSweet Nice\nWorld")] + public void Should_Split_Unstyled_Text_To_New_Lines_If_Width_Exceeds_Console_Width( + int width, string input, string expected) + { + // Given + var console = new TestConsole().Width(width); + var text = new Text(input); + + // When + console.Write(text); + + // Then + console.Output + .NormalizeLineEndings() + .ShouldBe(expected); + } + + [Theory] + [InlineData(Overflow.Fold, "foo \npneumonoultram\nicroscopicsili\ncovolcanoconio\nsis bar qux")] + [InlineData(Overflow.Crop, "foo \npneumonoultram\nbar qux")] + [InlineData(Overflow.Ellipsis, "foo \npneumonoultra…\nbar qux")] + public void Should_Overflow_Text_Correctly(Overflow overflow, string expected) + { + // Given + var console = new TestConsole().Width(14); + var text = new Text("foo pneumonoultramicroscopicsilicovolcanoconiosis bar qux") + .Overflow(overflow); + + // When + console.Write(text); + + // Then + console.Output + .NormalizeLineEndings() + .ShouldBe(expected); + } +} diff --git a/test/Spectre.Console.Tests/Unit/Widgets/TreeTests.cs b/test/Spectre.Console.Tests/Unit/Widgets/TreeTests.cs index 761aaca..14dde78 100644 --- a/test/Spectre.Console.Tests/Unit/Widgets/TreeTests.cs +++ b/test/Spectre.Console.Tests/Unit/Widgets/TreeTests.cs @@ -1,85 +1,76 @@ -using System.Linq; -using System.Threading.Tasks; -using Shouldly; -using Spectre.Console.Testing; -using Spectre.Verify.Extensions; -using VerifyXunit; -using Xunit; +namespace Spectre.Console.Tests.Unit; -namespace Spectre.Console.Tests.Unit +[UsesVerify] +[ExpectationPath("Widgets/Tree")] +public class TreeTests { - [UsesVerify] - [ExpectationPath("Widgets/Tree")] - public class TreeTests + [Fact] + [Expectation("Render")] + public Task Should_Render_Tree_Correctly() { - [Fact] - [Expectation("Render")] - public Task Should_Render_Tree_Correctly() - { - // Given - var console = new TestConsole(); + // Given + var console = new TestConsole(); - var tree = new Tree(new Text("Root node")).Guide(TreeGuide.DoubleLine); + var tree = new Tree(new Text("Root node")).Guide(TreeGuide.DoubleLine); - var nestedChildren = Enumerable.Range(0, 10).Select(x => new Text($"multiple\nline {x}")); - var child2 = new TreeNode(new Text("child2")); - var child2Child = new TreeNode(new Text("child2-1")); - child2.AddNode(child2Child); - child2Child.AddNode(new TreeNode(new Text("Child2-1-1\nchild"))); - var child3 = new TreeNode(new Text("child3")); - var child3Child = new TreeNode(new Text("single leaf\nmultiline")); - child3Child.AddNode(new TreeNode(new Calendar(2021, 01))); - child3.AddNode(child3Child); + var nestedChildren = Enumerable.Range(0, 10).Select(x => new Text($"multiple\nline {x}")); + var child2 = new TreeNode(new Text("child2")); + var child2Child = new TreeNode(new Text("child2-1")); + child2.AddNode(child2Child); + child2Child.AddNode(new TreeNode(new Text("Child2-1-1\nchild"))); + var child3 = new TreeNode(new Text("child3")); + var child3Child = new TreeNode(new Text("single leaf\nmultiline")); + child3Child.AddNode(new TreeNode(new Calendar(2021, 01))); + child3.AddNode(child3Child); - tree.AddNode("child1").AddNodes(nestedChildren); - tree.AddNode(child2); - tree.AddNode(child3); - tree.AddNode("child4"); + tree.AddNode("child1").AddNodes(nestedChildren); + tree.AddNode(child2); + tree.AddNode(child3); + tree.AddNode("child4"); - // When - console.Write(tree); + // When + console.Write(tree); - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - [Expectation("Render_NoChildren")] - public Task Should_Render_Tree_With_No_Child_Nodes_Correctly() - { - // Given - var console = new TestConsole(); - var tree = new Tree(new Text("Root node")); - - // When - console.Write(tree); - - // Then - return Verifier.Verify(console.Output); - } - - [Fact] - public void Should_Throw_If_Tree_Contains_Cycles() - { - // Given - var console = new TestConsole(); - - var child2 = new TreeNode(new Text("child 2")); - var child3 = new TreeNode(new Text("child 3")); - var child1 = new TreeNode(new Text("child 1")); - child1.AddNodes(child2, child3); - var root = new TreeNode(new Text("Branch Node")); - root.AddNodes(child1); - child2.AddNode(root); - - var tree = new Tree("root node"); - tree.AddNodes(root); - - // When - var result = Record.Exception(() => console.Write(tree)); - - // Then - result.ShouldBeOfType(); - } + // Then + return Verifier.Verify(console.Output); } -} \ No newline at end of file + + [Fact] + [Expectation("Render_NoChildren")] + public Task Should_Render_Tree_With_No_Child_Nodes_Correctly() + { + // Given + var console = new TestConsole(); + var tree = new Tree(new Text("Root node")); + + // When + console.Write(tree); + + // Then + return Verifier.Verify(console.Output); + } + + [Fact] + public void Should_Throw_If_Tree_Contains_Cycles() + { + // Given + var console = new TestConsole(); + + var child2 = new TreeNode(new Text("child 2")); + var child3 = new TreeNode(new Text("child 3")); + var child1 = new TreeNode(new Text("child 1")); + child1.AddNodes(child2, child3); + var root = new TreeNode(new Text("Branch Node")); + root.AddNodes(child1); + child2.AddNode(root); + + var tree = new Tree("root node"); + tree.AddNodes(root); + + // When + var result = Record.Exception(() => console.Write(tree)); + + // Then + result.ShouldBeOfType(); + } +} diff --git a/test/Spectre.Console.Tests/Utilities/EmbeddedResourceReader.cs b/test/Spectre.Console.Tests/Utilities/EmbeddedResourceReader.cs index 889666a..5246b5e 100644 --- a/test/Spectre.Console.Tests/Utilities/EmbeddedResourceReader.cs +++ b/test/Spectre.Console.Tests/Utilities/EmbeddedResourceReader.cs @@ -1,38 +1,33 @@ -using System; -using System.IO; -using System.Reflection; +namespace Spectre.Console.Tests; -namespace Spectre.Console.Tests +public static class EmbeddedResourceReader { - public static class EmbeddedResourceReader + public static Stream LoadResourceStream(string resourceName) { - public static Stream LoadResourceStream(string resourceName) + if (resourceName is null) { - if (resourceName is null) - { - throw new ArgumentNullException(nameof(resourceName)); - } - - var assembly = Assembly.GetCallingAssembly(); - resourceName = resourceName.Replace("/", "."); - - return assembly.GetManifestResourceStream(resourceName); + throw new ArgumentNullException(nameof(resourceName)); } - public static Stream LoadResourceStream(Assembly assembly, string resourceName) - { - if (assembly is null) - { - throw new ArgumentNullException(nameof(assembly)); - } + var assembly = Assembly.GetCallingAssembly(); + resourceName = resourceName.Replace("/", "."); - if (resourceName is null) - { - throw new ArgumentNullException(nameof(resourceName)); - } - - resourceName = resourceName.Replace("/", "."); - return assembly.GetManifestResourceStream(resourceName); - } + return assembly.GetManifestResourceStream(resourceName); } -} \ No newline at end of file + + public static Stream LoadResourceStream(Assembly assembly, string resourceName) + { + if (assembly is null) + { + throw new ArgumentNullException(nameof(assembly)); + } + + if (resourceName is null) + { + throw new ArgumentNullException(nameof(resourceName)); + } + + resourceName = resourceName.Replace("/", "."); + return assembly.GetManifestResourceStream(resourceName); + } +} diff --git a/test/Spectre.Console.Tests/Utilities/Extensions/CommandContextExtensions.cs b/test/Spectre.Console.Tests/Utilities/Extensions/CommandContextExtensions.cs index 8975fd6..6809cd2 100644 --- a/test/Spectre.Console.Tests/Utilities/Extensions/CommandContextExtensions.cs +++ b/test/Spectre.Console.Tests/Utilities/Extensions/CommandContextExtensions.cs @@ -1,30 +1,25 @@ -using System; -using System.Linq; -using Shouldly; +namespace Spectre.Console.Cli; -namespace Spectre.Console.Cli +public static class CommandContextExtensions { - public static class CommandContextExtensions + public static void ShouldHaveRemainingArgument(this CommandContext context, string name, string[] values) { - public static void ShouldHaveRemainingArgument(this CommandContext context, string name, string[] values) + if (context == null) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + throw new ArgumentNullException(nameof(context)); + } - if (values == null) - { - throw new ArgumentNullException(nameof(values)); - } + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } - context.Remaining.Parsed.Contains(name).ShouldBeTrue(); - context.Remaining.Parsed[name].Count().ShouldBe(values.Length); + context.Remaining.Parsed.Contains(name).ShouldBeTrue(); + context.Remaining.Parsed[name].Count().ShouldBe(values.Length); - foreach (var value in values) - { - context.Remaining.Parsed[name].ShouldContain(value); - } + foreach (var value in values) + { + context.Remaining.Parsed[name].ShouldContain(value); } } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Utilities/Extensions/ShouldlyExtensions.cs b/test/Spectre.Console.Tests/Utilities/Extensions/ShouldlyExtensions.cs index 04156bd..fc84316 100644 --- a/test/Spectre.Console.Tests/Utilities/Extensions/ShouldlyExtensions.cs +++ b/test/Spectre.Console.Tests/Utilities/Extensions/ShouldlyExtensions.cs @@ -1,20 +1,16 @@ -using System; -using System.Diagnostics; +namespace Spectre.Console; -namespace Spectre.Console +public static class ShouldlyExtensions { - public static class ShouldlyExtensions + [DebuggerStepThrough] + public static T And(this T item, Action action) { - [DebuggerStepThrough] - public static T And(this T item, Action action) + if (action == null) { - if (action == null) - { - throw new ArgumentNullException(nameof(action)); - } - - action(item); - return item; + throw new ArgumentNullException(nameof(action)); } + + action(item); + return item; } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Utilities/Extensions/TestConsoleExtensions.cs b/test/Spectre.Console.Tests/Utilities/Extensions/TestConsoleExtensions.cs index 2bb8402..29711a7 100644 --- a/test/Spectre.Console.Tests/Utilities/Extensions/TestConsoleExtensions.cs +++ b/test/Spectre.Console.Tests/Utilities/Extensions/TestConsoleExtensions.cs @@ -1,44 +1,38 @@ -using System; -using System.Linq; -using System.Text.RegularExpressions; -using Spectre.Console.Testing; +namespace Spectre.Console.Tests; -namespace Spectre.Console.Tests +public static class TestConsoleExtensions { - public static class TestConsoleExtensions + private static readonly Regex _lineNumberRegex = new Regex(":\\d+", RegexOptions.Singleline); + private static readonly Regex _filenameRegex = new Regex("\\sin\\s.*cs:nn", RegexOptions.Multiline); + + public static string WriteNormalizedException(this TestConsole console, Exception ex, ExceptionFormats formats = ExceptionFormats.Default) { - private static readonly Regex _lineNumberRegex = new Regex(":\\d+", RegexOptions.Singleline); - private static readonly Regex _filenameRegex = new Regex("\\sin\\s.*cs:nn", RegexOptions.Multiline); - - public static string WriteNormalizedException(this TestConsole console, Exception ex, ExceptionFormats formats = ExceptionFormats.Default) + if (!string.IsNullOrWhiteSpace(console.Output)) { - if (!string.IsNullOrWhiteSpace(console.Output)) - { - throw new InvalidOperationException("Output buffer is not empty."); - } - - console.WriteException(ex, formats); - return string.Join("\n", NormalizeStackTrace(console.Output) - .NormalizeLineEndings() - .Split(new char[] { '\n' }) - .Select(line => line.TrimEnd())); + throw new InvalidOperationException("Output buffer is not empty."); } - public static string NormalizeStackTrace(string text) - { - text = _lineNumberRegex.Replace(text, match => - { - return ":nn"; - }); - - return _filenameRegex.Replace(text, match => - { - var value = match.Value; - var index = value.LastIndexOfAny(new[] { '\\', '/' }); - var filename = value.Substring(index + 1, value.Length - index - 1); - - return $" in /xyz/{filename}"; - }); - } + console.WriteException(ex, formats); + return string.Join("\n", NormalizeStackTrace(console.Output) + .NormalizeLineEndings() + .Split(new char[] { '\n' }) + .Select(line => line.TrimEnd())); } -} \ No newline at end of file + + public static string NormalizeStackTrace(string text) + { + text = _lineNumberRegex.Replace(text, match => + { + return ":nn"; + }); + + return _filenameRegex.Replace(text, match => + { + var value = match.Value; + var index = value.LastIndexOfAny(new[] { '\\', '/' }); + var filename = value.Substring(index + 1, value.Length - index - 1); + + return $" in /xyz/{filename}"; + }); + } +} diff --git a/test/Spectre.Console.Tests/Utilities/FakeTypeRegistrar.cs b/test/Spectre.Console.Tests/Utilities/FakeTypeRegistrar.cs index 1639d0e..38645c0 100644 --- a/test/Spectre.Console.Tests/Utilities/FakeTypeRegistrar.cs +++ b/test/Spectre.Console.Tests/Utilities/FakeTypeRegistrar.cs @@ -1,57 +1,52 @@ -using System; -using System.Collections.Generic; -using Spectre.Console.Cli; +namespace Spectre.Console.Testing; -namespace Spectre.Console.Testing +public sealed class FakeTypeRegistrar : ITypeRegistrar { - public sealed class FakeTypeRegistrar : ITypeRegistrar + public Dictionary> Registrations { get; } + public Dictionary> Instances { get; } + public Func>, Dictionary>, ITypeResolver> TypeResolverFactory { get; set; } + + public FakeTypeRegistrar() { - public Dictionary> Registrations { get; } - public Dictionary> Instances { get; } - public Func>, Dictionary>, ITypeResolver> TypeResolverFactory { get; set; } + Registrations = new Dictionary>(); + Instances = new Dictionary>(); + } - public FakeTypeRegistrar() + public void Register(Type service, Type implementation) + { + if (!Registrations.ContainsKey(service)) { - Registrations = new Dictionary>(); - Instances = new Dictionary>(); + Registrations.Add(service, new List { implementation }); } - - public void Register(Type service, Type implementation) + else { - if (!Registrations.ContainsKey(service)) - { - Registrations.Add(service, new List { implementation }); - } - else - { - Registrations[service].Add(implementation); - } - } - - public void RegisterInstance(Type service, object implementation) - { - if (!Instances.ContainsKey(service)) - { - Instances.Add(service, new List { implementation }); - } - } - - public void RegisterLazy(Type service, Func factory) - { - if (factory is null) - { - throw new ArgumentNullException(nameof(factory)); - } - - if (!Instances.ContainsKey(service)) - { - Instances.Add(service, new List { factory() }); - } - } - - public ITypeResolver Build() - { - return TypeResolverFactory?.Invoke(Registrations, Instances); + Registrations[service].Add(implementation); } } -} \ No newline at end of file + + public void RegisterInstance(Type service, object implementation) + { + if (!Instances.ContainsKey(service)) + { + Instances.Add(service, new List { implementation }); + } + } + + public void RegisterLazy(Type service, Func factory) + { + if (factory is null) + { + throw new ArgumentNullException(nameof(factory)); + } + + if (!Instances.ContainsKey(service)) + { + Instances.Add(service, new List { factory() }); + } + } + + public ITypeResolver Build() + { + return TypeResolverFactory?.Invoke(Registrations, Instances); + } +} diff --git a/test/Spectre.Console.Tests/Utilities/FakeTypeResolver.cs b/test/Spectre.Console.Tests/Utilities/FakeTypeResolver.cs index 05dbe29..dc147c6 100644 --- a/test/Spectre.Console.Tests/Utilities/FakeTypeResolver.cs +++ b/test/Spectre.Console.Tests/Utilities/FakeTypeResolver.cs @@ -1,41 +1,35 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Spectre.Console.Cli; +namespace Spectre.Console.Testing; -namespace Spectre.Console.Testing +public sealed class FakeTypeResolver : ITypeResolver { - public sealed class FakeTypeResolver : ITypeResolver + private readonly Dictionary> _registrations; + private readonly Dictionary> _instances; + + public FakeTypeResolver( + Dictionary> registrations, + Dictionary> instances) { - private readonly Dictionary> _registrations; - private readonly Dictionary> _instances; - - public FakeTypeResolver( - Dictionary> registrations, - Dictionary> instances) - { - _registrations = registrations ?? throw new ArgumentNullException(nameof(registrations)); - _instances = instances ?? throw new ArgumentNullException(nameof(instances)); - } - - public static Func>, Dictionary>, ITypeResolver> Factory => - (r, i) => new FakeTypeResolver(r, i); - - public object Resolve(Type type) - { - if (_instances.TryGetValue(type, out var instances)) - { - return instances.FirstOrDefault(); - } - - if (_registrations.TryGetValue(type, out var registrations)) - { - return registrations.Count == 0 - ? null - : Activator.CreateInstance(type); - } - - return null; - } + _registrations = registrations ?? throw new ArgumentNullException(nameof(registrations)); + _instances = instances ?? throw new ArgumentNullException(nameof(instances)); } -} \ No newline at end of file + + public static Func>, Dictionary>, ITypeResolver> Factory => + (r, i) => new FakeTypeResolver(r, i); + + public object Resolve(Type type) + { + if (_instances.TryGetValue(type, out var instances)) + { + return instances.FirstOrDefault(); + } + + if (_registrations.TryGetValue(type, out var registrations)) + { + return registrations.Count == 0 + ? null + : Activator.CreateInstance(type); + } + + return null; + } +} diff --git a/test/Spectre.Console.Tests/Utilities/GitHubIssueAttribute.cs b/test/Spectre.Console.Tests/Utilities/GitHubIssueAttribute.cs index c33fc04..c01ce95 100644 --- a/test/Spectre.Console.Tests/Utilities/GitHubIssueAttribute.cs +++ b/test/Spectre.Console.Tests/Utilities/GitHubIssueAttribute.cs @@ -1,14 +1,12 @@ -using System; +namespace Spectre.Console.Tests; -namespace Spectre.Console.Tests +[AttributeUsage(AttributeTargets.Method)] +public sealed class GitHubIssueAttribute : Attribute { - public sealed class GitHubIssueAttribute : Attribute - { - public int IssueId { get; } + public int IssueId { get; } - public GitHubIssueAttribute(int issueId) - { - IssueId = issueId; - } + public GitHubIssueAttribute(int issueId) + { + IssueId = issueId; } -} \ No newline at end of file +} diff --git a/test/Spectre.Console.Tests/Utilities/ModuleInitializerAttribute.cs b/test/Spectre.Console.Tests/Utilities/ModuleInitializerAttribute.cs new file mode 100644 index 0000000..6f93cb4 --- /dev/null +++ b/test/Spectre.Console.Tests/Utilities/ModuleInitializerAttribute.cs @@ -0,0 +1,8 @@ +#if !NET5_0_OR_GREATER +namespace System.Runtime.CompilerServices; + +[AttributeUsage(AttributeTargets.Method, Inherited = false)] +public sealed class ModuleInitializerAttribute : Attribute +{ +} +#endif \ No newline at end of file diff --git a/test/Spectre.Console.Tests/VerifyConfiguration.cs b/test/Spectre.Console.Tests/VerifyConfiguration.cs index 8e323ae..770ec2b 100644 --- a/test/Spectre.Console.Tests/VerifyConfiguration.cs +++ b/test/Spectre.Console.Tests/VerifyConfiguration.cs @@ -1,25 +1,10 @@ -using System.Runtime.CompilerServices; -using Spectre.Verify.Extensions; -using VerifyTests; +namespace Spectre.Console.Tests; -namespace Spectre.Console.Tests +public static class VerifyConfiguration { - public static class VerifyConfiguration + [ModuleInitializer] + public static void Init() { - [ModuleInitializer] - public static void Init() - { - VerifierSettings.DerivePathInfo(Expectations.Initialize); - } + VerifierSettings.DerivePathInfo(Expectations.Initialize); } } - -#if !NET5_0_OR_GREATER -namespace System.Runtime.CompilerServices -{ - [AttributeUsage(AttributeTargets.Method, Inherited = false)] - public sealed class ModuleInitializerAttribute : Attribute - { - } -} -#endif \ No newline at end of file