mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
fix: accept semicolonless script using directives - #3196
fix: accept semicolonless script using directives
This commit is contained in:
commit
7b100a3149
2 changed files with 21 additions and 1 deletions
14
MinecraftClient.Tests/CSharpRunnerTests.cs
Normal file
14
MinecraftClient.Tests/CSharpRunnerTests.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
using MinecraftClient.Scripting;
|
||||||
|
|
||||||
|
namespace MinecraftClient.Tests;
|
||||||
|
|
||||||
|
public sealed class CSharpRunnerTests
|
||||||
|
{
|
||||||
|
[Theory]
|
||||||
|
[InlineData("//using MinecraftClient.CommandHandler", "using MinecraftClient.CommandHandler;")]
|
||||||
|
[InlineData("//using MinecraftClient.CommandHandler;", "using MinecraftClient.CommandHandler;")]
|
||||||
|
public void NormalizeUsingDirectiveAddsMissingSemicolon(string directive, string expected)
|
||||||
|
{
|
||||||
|
Assert.Equal(expected, CSharpRunner.NormalizeUsingDirective(directive));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -60,7 +60,7 @@ namespace MinecraftClient.Scripting
|
||||||
string line = lines[i];
|
string line = lines[i];
|
||||||
if (line.StartsWith("//using"))
|
if (line.StartsWith("//using"))
|
||||||
{
|
{
|
||||||
libs.Add(line.Replace("//", "").Trim());
|
libs.Add(NormalizeUsingDirective(line));
|
||||||
}
|
}
|
||||||
else if (line.StartsWith("//dll"))
|
else if (line.StartsWith("//dll"))
|
||||||
{
|
{
|
||||||
|
|
@ -125,6 +125,12 @@ namespace MinecraftClient.Scripting
|
||||||
else return null;
|
else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static string NormalizeUsingDirective(string line)
|
||||||
|
{
|
||||||
|
string directive = line[2..].Trim();
|
||||||
|
return directive.EndsWith(';') ? directive : $"{directive};";
|
||||||
|
}
|
||||||
|
|
||||||
private static string BuildScriptCode(string scriptName, IEnumerable<ScriptSourceLine> script, IEnumerable<ScriptSourceLine> extensions, IEnumerable<string> libs, bool hasImplicitReturn)
|
private static string BuildScriptCode(string scriptName, IEnumerable<ScriptSourceLine> script, IEnumerable<ScriptSourceLine> extensions, IEnumerable<string> libs, bool hasImplicitReturn)
|
||||||
{
|
{
|
||||||
StringBuilder codeBuilder = new();
|
StringBuilder codeBuilder = new();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue