Files
RobustToolbox/Robust.UnitTesting/Shared/Toolshed/TestCommands.cs
T
Leon FriedrichandGitHub 9af119f57a Toolshed Rejig (#5455)
* Toolshed Rejig

* shorten hint string

* Try fix conflicts. Ill make with work later

* bodge

* Fix ProtoIdTypeParser assert

* comment

* AllEntities

* Remove more linq from WhereCommand

* better help strings

* Add ContainsCommand

* loc strings

* Add contains command description

* Add $self variable

* Errors for writing to readonly variables

* A
2024-12-21 17:49:11 +11:00

91 lines
2.5 KiB
C#

using System;
using Robust.Shared.Console;
using Robust.Shared.Toolshed;
using Robust.Shared.Toolshed.Syntax;
using Robust.Shared.Toolshed.TypeParsers;
namespace Robust.UnitTesting.Shared.Toolshed;
// This file just contains a collection of various test commands for use in other tests.
[ToolshedCommand]
public sealed class TestVoidCommand : ToolshedCommand
{
[CommandImplementation] public void Impl() {}
}
[ToolshedCommand]
public sealed class TestIntCommand : ToolshedCommand
{
[CommandImplementation] public int Impl() => 1;
}
[ToolshedCommand]
public sealed class TestTypeArgCommand : ToolshedCommand
{
public override Type[] TypeParameterParsers => [typeof(TypeTypeParser)];
[CommandImplementation] public string Impl<T>() => typeof(T).Name;
}
[ToolshedCommand]
public sealed class TestMultiTypeArgCommand : ToolshedCommand
{
public override Type[] TypeParameterParsers => [typeof(TypeTypeParser), typeof(TypeTypeParser)];
[CommandImplementation] public string Impl<T1, T2>(int i)
=> $"{typeof(T1).Name}, {typeof(T2).Name}, {i}";
}
[ToolshedCommand]
public sealed class TestIntStrArgCommand : ToolshedCommand
{
[CommandImplementation] public int Impl(int i, string str) => i;
}
[ToolshedCommand]
public sealed class TestPipedIntCommand : ToolshedCommand
{
[CommandImplementation] public int Impl([PipedArgument] int i) => i;
}
[ToolshedCommand]
public sealed class TestCustomVarRefParserCommand : ToolshedCommand
{
[CommandImplementation]
public int Impl([CommandArgument(typeof(Parser))] int i) => i;
[Virtual]
public class Parser : CustomTypeParser<int>
{
public override bool TryParse(ParserContext ctx, out int result)
{
result = default;
if (!Toolshed.TryParse(ctx, out int _))
return false;
// Disregard the parsed value and always return 1
result = 1;
return true;
}
public override CompletionResult TryAutocomplete(ParserContext ctx, string? argName)
{
return new CompletionResult([new("A")], "B");
}
}
}
[ToolshedCommand]
public sealed class TestCustomParserCommand : ToolshedCommand
{
[CommandImplementation]
public int Impl([CommandArgument(typeof(Parser))] int i) => i;
public sealed class Parser : TestCustomVarRefParserCommand.Parser
{
// Disable ValueRef support.
// I.e., this parser will not not try to parse variables or blocks
public override bool EnableValueRef => false;
}
}