diff --git a/UndertaleModLib.Tests/AssemblyInfo.cs b/UndertaleModLib.Tests/AssemblyInfo.cs new file mode 100644 index 000000000..29994aacf --- /dev/null +++ b/UndertaleModLib.Tests/AssemblyInfo.cs @@ -0,0 +1,2 @@ +// This makes so tests run in one collection by default, meaning they will not run in parallel. This is slower but necessary since static variables are used in multiple places, which when running things in parallel can override one another. +[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly)] \ No newline at end of file diff --git a/UndertaleModLib.Tests/GameScriptTests.cs b/UndertaleModLib.Tests/GameScriptTests.cs index 051e3dbcc..0b3eaa63c 100644 --- a/UndertaleModLib.Tests/GameScriptTests.cs +++ b/UndertaleModLib.Tests/GameScriptTests.cs @@ -1,8 +1,9 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Reflection; -using System.Text; +using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.CSharp.Scripting; using Microsoft.CodeAnalysis.Scripting; @@ -19,6 +20,20 @@ protected GameScriptTestBase(string path, string md5) : base(path, md5) { } + public UndertaleData Data => data; + public string FilePath => path; + public object Highlighted => throw new NotImplementedException(); + public object Selected => throw new NotImplementedException(); + public bool CanSave => throw new NotImplementedException(); + public string ScriptPath => throw new NotImplementedException(); + public bool ScriptExecutionSuccess => throw new NotImplementedException(); + public string ScriptErrorMessage => throw new NotImplementedException(); + public string ExePath => throw new NotImplementedException(); + public string ScriptErrorType => throw new NotImplementedException(); + public bool GMLCacheEnabled => throw new NotImplementedException(); + + public bool IsAppClosed => throw new NotImplementedException(); + protected async Task RunScript(string path) { string scriptpath = Path.Combine("../../../../UndertaleModTool/Scripts/Builtin Scripts/", path); @@ -31,345 +46,279 @@ protected async Task RunScript(string path) .WithReferences(typeof(UndertaleObject).GetTypeInfo().Assembly), typeof(IScriptInterface), loader); - return await script.RunAsync(this); + var result = await script.RunAsync(this); + return result; } } - public void EnsureDataLoaded() + public void ChangeSelection(object newSelection, bool inNewTab = false) { } - public bool AreFilesIdentical(string file1, string file2) + public void EnsureDataLoaded() { - string output = "AreFilesIdentical(): " + file1 + ", " + file2; - Console.Write(output); - return true; } - - public bool DummyBool() + public async Task MakeNewDataFile() { + await Task.Delay(1); //dummy await return true; } - - public void DummyVoid() - { - } - - public string DummyString() + public void ReplaceTempWithMain(bool imAnExpertBtw = false) { - return ""; } - - public UndertaleData Data => data; - - public string FilePath => path; - - public string ScriptPath => throw new NotImplementedException(); - - public object Highlighted => throw new NotImplementedException(); - - public object Selected => throw new NotImplementedException(); - - public bool CanSave => throw new NotImplementedException(); - - public bool ScriptExecutionSuccess => throw new NotImplementedException(); - - public string ScriptErrorMessage => throw new NotImplementedException(); - - public string ExePath => throw new NotImplementedException(); - - public string ScriptErrorType => throw new NotImplementedException(); - - public bool GMLCacheEnabled => throw new NotImplementedException(); - - public bool IsAppClosed => throw new NotImplementedException(); - - public void AddProgress(int amount) + public void ReplaceMainWithTemp(bool imAnExpertBtw = false) { - Console.WriteLine($"AddProgress(): {amount}"); } - - public void AddProgressParallel(int amount) + public void ReplaceTempWithCorrections(bool imAnExpertBtw = false) { - Console.WriteLine($"AddProgressParallel(): {amount}"); } - - public void ChangeSelection(object newSelection, bool inNewTab = false) + public void ReplaceCorrectionsWithTemp(bool imAnExpertBtw = false) { - Console.WriteLine($"ChangeSelection(): {newSelection}, {inNewTab}"); } - - public async Task ClickableSearchOutput(string title, string query, int resultsCount, IOrderedEnumerable>> resultsDict, bool showInDecompiledView, IOrderedEnumerable? failedList = null) + public void UpdateCorrections(bool imAnExpertBtw = false) { - Console.WriteLine($"ClickableSearchOutput(): \"{title}\", \"{query}\", {resultsCount}, *resultsDict* (length - {resultsDict.Count()}), {showInDecompiledView.ToString().ToLower()}" - + (failedList is not null ? $", *failedList* (length - {failedList.Count()})" : string.Empty)); - await Task.Delay(1); //dummy await } - - public async Task ClickableSearchOutput(string title, string query, int resultsCount, IDictionary> resultsDict, bool showInDecompiledView, IEnumerable? failedList = null) + public void ReapplyProfileCode() { - Console.WriteLine($"ClickableSearchOutput(): \"{title}\", \"{query}\", {resultsCount}, *resultsDict* (length - {resultsDict.Count}), {showInDecompiledView.ToString().ToLower()}" - + (failedList is not null ? $", *failedList* (length - {failedList.Count()})" : string.Empty)); - await Task.Delay(1); //dummy await } - - public void DisableAllSyncBindings() + public void InitializeScriptDialog() { - Console.WriteLine($"Disabling all enabled synced bindings."); } - - public void EnableUI() + public bool RunUMTScript(string path) { - Console.WriteLine("Enabling UI."); + Console.WriteLine(path); + return true; } - - public async Task GenerateGMLCache(ThreadLocal? decompileContext = null, object? dialog = null, bool clearGMLEditedBefore = false) + public bool LintUMTScript(string path) { - Console.WriteLine(String.Format("GenerateGMLCache(): *decompileContext*{0}, *dialog*{1}, {2}", - decompileContext is null ? " (null)" : "", - dialog is null ? " (null)" : "", - clearGMLEditedBefore.ToString().ToLower()) - ); - - await Task.Delay(1); //dummy await - - return false; + Console.WriteLine(path); + return true; } - public string GetDecompiledText(string codeName, GlobalDecompileContext context = null) + public void ScriptMessage(string message) { - string output = "GetDecompiledText(): " + codeName; - Console.Write(output); - return output; + Console.WriteLine(message); } - public string GetDecompiledText(UndertaleCode code, GlobalDecompileContext context = null) + public bool ScriptQuestion(string message) { - string output = "GetDecompiledText(): " + code?.ToString(); - Console.Write(output); - return output; + Console.WriteLine(message); + return true; } - - public string GetDisassemblyText(string codeName) + public void ScriptOpenURL(string url) { - string output = "GetDisassemblyText(): " + codeName; - Console.Write(output); - return output; + Console.WriteLine("Open: " + url); } - - public string GetDisassemblyText(UndertaleCode code) + public void NukeProfileGML(string codeName) { - string output = "GetDisassemblyText(): " + code?.ToString(); - Console.Write(output); - return output; + Console.WriteLine("NukeProfileGML(): " + codeName); } - - public int GetProgress() + public void UpdateProgressBar(string message, string status, double progressValue, double maxValue) { - Console.WriteLine("GetProgress()"); - return -1; + Console.WriteLine("UpdateProgressBar(): " + progressValue + " / " + maxValue + ", Message: " + message + ", Status: " + status); } - - public void HideProgressBar() + public void SetProgressBar(string message, string status, double progressValue, double maxValue) { - Console.WriteLine("Hiding Progress Bar."); + Console.WriteLine("SetProgressBar(): " + progressValue + " / " + maxValue + ", Message: " + message + ", Status: " + status); } - - public void ImportASMFile(string fileName, bool doParse = true, bool nukeProfile = true, bool checkDecompiler = false, bool throwOnError = false) + public void SetProgressBar() { - Console.Write($"ImportASMFile(): \"{fileName}\", {doParse}, {nukeProfile}, {checkDecompiler}, {throwOnError}"); + Console.WriteLine("SetProgressBar()"); } - - public void ImportASMString(string codeName, string gmlCode, bool doParse = true, bool nukeProfile = true, bool checkDecompiler = false) + public void UpdateProgressValue(double progressValue) { - Console.Write("ImportASMString(): " + codeName + ", " + gmlCode + ", " + doParse.ToString()); + Console.WriteLine($"UpdateProgressValue(): {progressValue}"); } - - public void ImportGMLFile(string fileName, bool doParse = true, bool checkDecompiler = false, bool throwOnError = false) + public void UpdateProgressStatus(string status) { - Console.Write($"ImportGMLFile(): \"{fileName}\", {doParse}, {checkDecompiler}, {throwOnError}"); + Console.WriteLine($"UpdateProgressStatus(): {status}"); } - public void ImportGMLString(string codeName, string gmlCode, bool doParse = true, bool checkDecompiler = false) + public void AddProgress(int amount) { - Console.Write("ImportGMLString(): " + codeName + ", " + gmlCode + ", " + doParse.ToString()); + Console.WriteLine($"AddProgress(): {amount}"); } - public void IncrementProgress() { Console.WriteLine("IncrementProgress()"); } - + public void AddProgressParallel(int amount) + { + Console.WriteLine($"AddProgressParallel(): {amount}"); + } public void IncrementProgressParallel() { Console.WriteLine("IncrementProgressParallel()"); } - - public void InitializeScriptDialog() + public int GetProgress() { + Console.WriteLine("GetProgress()"); + return -1; } - - public bool LintUMTScript(string path) + public void SetProgress(int value) { - Console.WriteLine(path); - return true; + Console.WriteLine($"SetProgress(): {value}"); } - public async Task MakeNewDataFile() + public string ScriptInputDialog(string title, string label, string defaultInput, string cancelText, string submitText, bool isMultiline, bool preventClose) { - await Task.Delay(1); //dummy await - return true; - } + Console.Write(label + " "); + // Probably a bad idea + //string ret = Console.ReadLine(); - public void NukeProfileGML(string codeName) + //return ret; + return ""; + } + public string SimpleTextInput(string titleText, string labelText, string defaultInputBoxText, bool isMultiline, bool showDialog = true) { - Console.WriteLine("NukeProfileGML(): " + codeName); + return ScriptInputDialog(titleText, labelText, defaultInputBoxText, "Cancel", "Submit", isMultiline, false); } - - public string PromptChooseDirectory() + public void SimpleTextOutput(string titleText, string labelText, string message, bool isMultiline) { - throw new NotImplementedException(); + Console.WriteLine($"SimpleTextOutput(): \"{titleText}\", \"{labelText}\", *defaultInputBoxText* (length - {message.Length}), {isMultiline}"); } - - public string PromptLoadFile(string defaultExt, string filter) + public async Task ClickableSearchOutput(string title, string query, int resultsCount, IOrderedEnumerable>> resultsDict, bool showInDecompiledView, IOrderedEnumerable failedList = null) { - throw new NotImplementedException(); + Console.WriteLine($"ClickableSearchOutput(): \"{title}\", \"{query}\", {resultsCount}, *resultsDict* (length - {resultsDict.Count()}), {showInDecompiledView.ToString().ToLower()}" + + failedList is not null ? $", *failedList* (length - {failedList.Count()})" : string.Empty); + await Task.Delay(1); //dummy await } - - public void ReapplyProfileCode() + public async Task ClickableSearchOutput(string title, string query, int resultsCount, IDictionary> resultsDict, bool showInDecompiledView, IEnumerable failedList = null) { + Console.WriteLine($"ClickableSearchOutput(): \"{title}\", \"{query}\", {resultsCount}, *resultsDict* (length - {resultsDict.Count}), {showInDecompiledView.ToString().ToLower()}" + + failedList is not null ? $", *failedList* (length - {failedList.Count()})" : string.Empty); + await Task.Delay(1); //dummy await } - public void ReplaceCorrectionsWithTemp(bool imAnExpertBtw = false) + public void SetUMTConsoleText(string message) { + Console.Write("SetUMTConsoleText(): " + message); } - - public void ReplaceMainWithTemp(bool imAnExpertBtw = false) + public void ReplaceTextInGML(string codeName, string keyword, string replacement, bool caseSensitive = false, bool isRegex = false, GlobalDecompileContext context = null) { + Console.Write("ReplaceTextInGML(): " + codeName + ", " + keyword + ", " + replacement + ", " + caseSensitive.ToString() + ", " + isRegex.ToString() + ", " + context?.ToString()); } - - public void ReplaceTempWithCorrections(bool imAnExpertBtw = false) + public void ReplaceTextInGML(UndertaleCode code, string keyword, string replacement, bool caseSensitive = false, bool isRegex = false, GlobalDecompileContext context = null) { + Console.Write("ReplaceTextInGML(): " + code.ToString() + ", " + keyword + ", " + replacement + ", " + caseSensitive.ToString() + ", " + isRegex.ToString() + ", " + context?.ToString()); } - - public void ReplaceTempWithMain(bool imAnExpertBtw = false) + public void ImportGMLString(string codeName, string gmlCode, bool doParse = true, bool checkDecompiler = false) { + Console.Write("ImportGMLString(): " + codeName + ", " + gmlCode + ", " + doParse.ToString()); } - - public void ReplaceTextInGML(string codeName, string keyword, string replacement, bool caseSensitive = false, bool isRegex = false, GlobalDecompileContext context = null) + public void ImportASMString(string codeName, string gmlCode, bool doParse = true, bool nukeProfile = true, bool checkDecompiler = false) { - Console.Write("ReplaceTextInGML(): " + codeName + ", " + keyword + ", " + replacement + ", " + caseSensitive.ToString() + ", " + isRegex.ToString() + ", " + context?.ToString()); + Console.Write("ImportASMString(): " + codeName + ", " + gmlCode + ", " + doParse.ToString()); } - - public void ReplaceTextInGML(UndertaleCode code, string keyword, string replacement, bool caseSensitive = false, bool isRegex = false, GlobalDecompileContext context = null) + public void ImportGMLFile(string fileName, bool doParse = true, bool checkDecompiler = false, bool throwOnError = false) { - Console.Write("ReplaceTextInGML(): " + code.ToString() + ", " + keyword + ", " + replacement + ", " + caseSensitive.ToString() + ", " + isRegex.ToString() + ", " + context?.ToString()); + Console.Write($"ImportGMLFile(): \"{fileName}\", {doParse}, {checkDecompiler}, {throwOnError}"); } - - public bool RunUMTScript(string path) + public void ImportASMFile(string fileName, bool doParse = true, bool nukeProfile = true, bool checkDecompiler = false, bool throwOnError = false) { - Console.WriteLine(path); - return true; + Console.Write($"ImportASMFile(): \"{fileName}\", {doParse}, {nukeProfile}, {checkDecompiler}, {throwOnError}"); } - public void ScriptError(string error, string title = "Error", bool SetConsoleText = true) + public void SetFinishedMessage(bool isFinishedMessageEnabled) { - throw new NotImplementedException(); + Console.Write("SetFinishedMessage(): " + isFinishedMessageEnabled.ToString()); } - public string ScriptInputDialog(string title, string label, string defaultInput, string cancelText, string submitText, bool isMultiline, bool preventClose) + public void HideProgressBar() { - Console.Write(label + " "); - // Probably a bad idea - // string ret = Console.ReadLine(); - // return ret; - return ""; + Console.WriteLine("Hiding Progress Bar."); } - public void ScriptMessage(string message) + public void EnableUI() { - Console.WriteLine(message); + Console.WriteLine("Enabling UI."); } - - public void ScriptOpenURL(string url) + public void SyncBinding(string resourceType, bool enable) { - Console.WriteLine("Open: " + url); + Console.WriteLine($"SyncBinding(): \"{resourceType}\", {enable}"); } - - public bool ScriptQuestion(string message) + public void DisableAllSyncBindings() { - Console.WriteLine(message); - return true; + Console.WriteLine($"Disabling all enabled synced bindings."); } - - public void SetFinishedMessage(bool isFinishedMessageEnabled) + public void StartProgressBarUpdater() { - Console.Write("SetFinishedMessage(): " + isFinishedMessageEnabled.ToString()); + Console.WriteLine("Starting progress bar updater..."); } - - public void SetProgress(int value) + public async Task StopProgressBarUpdater() { - Console.WriteLine($"SetProgress(): {value}"); + Console.WriteLine("Stopping progress bar updater..."); + await Task.Delay(1); //dummy await } - public void SetProgressBar(string message, string status, double progressValue, double maxValue) + public async Task GenerateGMLCache(ThreadLocal decompileContext = null, object dialog = null, bool clearGMLEditedBefore = false) { - Console.WriteLine("SetProgressBar(): " + progressValue + " / " + maxValue + ", Message: " + message + ", Status: " + status); + Console.WriteLine(String.Format("GenerateGMLCache(): *decompileContext*{0}, *dialog*{1}, {2}", + decompileContext is null ? " (null)" : "", + dialog is null ? " (null)" : "", + clearGMLEditedBefore.ToString().ToLower()) + ); + + await Task.Delay(1); //dummy await + + return false; } - public void SetProgressBar() + public void ScriptError(string error, string title = "Error", bool SetConsoleText = true) { - Console.WriteLine("SetProgressBar()"); + throw new NotImplementedException(); } - public void SetUMTConsoleText(string message) + public string PromptChooseDirectory() { - Console.Write("SetUMTConsoleText(): " + message); + throw new NotImplementedException(); } - public string SimpleTextInput(string title, string label, string defaultValue, bool allowMultiline, bool showDialog = true) + public string GetDecompiledText(string codeName, GlobalDecompileContext context = null) { - return ScriptInputDialog(title, label, defaultValue, "Cancel", "Submit", allowMultiline, false); + string output = "GetDecompiledText(): " + codeName; + Console.Write(output); + return output; } - - public void SimpleTextOutput(string title, string label, string message, bool allowMultiline) + public string GetDecompiledText(UndertaleCode code, GlobalDecompileContext context = null) { - Console.WriteLine($"SimpleTextOutput(): \"{title}\", \"{label}\", *defaultInputBoxText* (length - {message.Length}), {allowMultiline}"); + string output = "GetDecompiledText(): " + code?.ToString(); + Console.Write(output); + return output; } - - public void StartProgressBarUpdater() + public string GetDisassemblyText(string codeName) { - Console.WriteLine("Starting progress bar updater..."); + string output = "GetDisassemblyText(): " + codeName; + Console.Write(output); + return output; } - - public async Task StopProgressBarUpdater() + public string GetDisassemblyText(UndertaleCode code) { - Console.WriteLine("Stopping progress bar updater..."); - await Task.Delay(1); //dummy await + string output = "GetDisassemblyText(): " + code?.ToString(); + Console.Write(output); + return output; } - - public void SyncBinding(string resourceType, bool enable) + public bool AreFilesIdentical(string file1, string file2) { - Console.WriteLine($"SyncBinding(): \"{resourceType}\", {enable}"); + string output = "AreFilesIdentical(): " + file1 + ", " + file2; + Console.Write(output); + return true; } - - public void UpdateCorrections(bool imAnExpertBtw = false) + public string PromptLoadFile(string defaultExt, string filter) { + throw new NotImplementedException(); } - - public void UpdateProgressBar(string message, string status, double progressValue, double maxValue) + public bool DummyBool() { - Console.WriteLine("UpdateProgressBar(): " + progressValue + " / " + maxValue + ", Message: " + message + ", Status: " + status); + return true; } - public void UpdateProgressStatus(string status) + public void DummyVoid() { - Console.WriteLine($"UpdateProgressStatus(): {status}"); } - - public void UpdateProgressValue(double progressValue) + public string DummyString() { - Console.WriteLine($"UpdateProgressValue(): {progressValue}"); + return ""; } } @@ -433,4 +382,4 @@ public async Task RunScriptTest(string scriptName) await RunScript(scriptName); } } - } \ No newline at end of file +} \ No newline at end of file