From de0631d3708b38cdd8b6a0dc973cf71990a80b10 Mon Sep 17 00:00:00 2001 From: MASSHUU12 Date: Tue, 19 Mar 2024 12:09:17 +0100 Subject: [PATCH 01/14] Add Chickensoft.GoDotTest --- godot-yat.csproj | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/godot-yat.csproj b/godot-yat.csproj index a5a1f95d..1741b415 100644 --- a/godot-yat.csproj +++ b/godot-yat.csproj @@ -22,6 +22,9 @@ - + + + + From a935a6ec3e00c5375f4191e3f5f304adb9b5b2eb Mon Sep 17 00:00:00 2001 From: MASSHUU12 Date: Tue, 19 Mar 2024 12:09:28 +0100 Subject: [PATCH 02/14] Move old tests to test/old folder --- test/Test.cs | 0 test/{ => old}/classes/TestExtensible.cs | 0 test/{ => old}/classes/TestLruCache.cs | 0 test/{ => old}/classes/TestParser.cs | 0 test/{ => old}/helpers/TestAttributeHelper.cs | 0 test/{ => old}/helpers/TestNumeric.cs | 0 test/{ => old}/helpers/TestScene.cs | 0 test/{ => old}/helpers/TestText.cs | 0 test/{ => old}/scenes/TestRegisteredCommands.cs | 0 9 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/Test.cs rename test/{ => old}/classes/TestExtensible.cs (100%) rename test/{ => old}/classes/TestLruCache.cs (100%) rename test/{ => old}/classes/TestParser.cs (100%) rename test/{ => old}/helpers/TestAttributeHelper.cs (100%) rename test/{ => old}/helpers/TestNumeric.cs (100%) rename test/{ => old}/helpers/TestScene.cs (100%) rename test/{ => old}/helpers/TestText.cs (100%) rename test/{ => old}/scenes/TestRegisteredCommands.cs (100%) diff --git a/test/Test.cs b/test/Test.cs new file mode 100644 index 00000000..e69de29b diff --git a/test/classes/TestExtensible.cs b/test/old/classes/TestExtensible.cs similarity index 100% rename from test/classes/TestExtensible.cs rename to test/old/classes/TestExtensible.cs diff --git a/test/classes/TestLruCache.cs b/test/old/classes/TestLruCache.cs similarity index 100% rename from test/classes/TestLruCache.cs rename to test/old/classes/TestLruCache.cs diff --git a/test/classes/TestParser.cs b/test/old/classes/TestParser.cs similarity index 100% rename from test/classes/TestParser.cs rename to test/old/classes/TestParser.cs diff --git a/test/helpers/TestAttributeHelper.cs b/test/old/helpers/TestAttributeHelper.cs similarity index 100% rename from test/helpers/TestAttributeHelper.cs rename to test/old/helpers/TestAttributeHelper.cs diff --git a/test/helpers/TestNumeric.cs b/test/old/helpers/TestNumeric.cs similarity index 100% rename from test/helpers/TestNumeric.cs rename to test/old/helpers/TestNumeric.cs diff --git a/test/helpers/TestScene.cs b/test/old/helpers/TestScene.cs similarity index 100% rename from test/helpers/TestScene.cs rename to test/old/helpers/TestScene.cs diff --git a/test/helpers/TestText.cs b/test/old/helpers/TestText.cs similarity index 100% rename from test/helpers/TestText.cs rename to test/old/helpers/TestText.cs diff --git a/test/scenes/TestRegisteredCommands.cs b/test/old/scenes/TestRegisteredCommands.cs similarity index 100% rename from test/scenes/TestRegisteredCommands.cs rename to test/old/scenes/TestRegisteredCommands.cs From 28a18c4c578dd5353c606fb324440837bbeaa8fb Mon Sep 17 00:00:00 2001 From: MASSHUU12 Date: Tue, 19 Mar 2024 12:34:53 +0100 Subject: [PATCH 03/14] Create Main scene --- example/scenes/Main.cs | 34 ++++++++++++++++++++++++++++++++++ example/scenes/Main.tscn | 6 ++++++ 2 files changed, 40 insertions(+) create mode 100644 example/scenes/Main.cs create mode 100644 example/scenes/Main.tscn diff --git a/example/scenes/Main.cs b/example/scenes/Main.cs new file mode 100644 index 00000000..2abb573e --- /dev/null +++ b/example/scenes/Main.cs @@ -0,0 +1,34 @@ +using Godot; + +#if DEBUG +using System.Reflection; +using Chickensoft.GoDotTest; +#endif + +public partial class Main : Node2D +{ +#if DEBUG + public TestEnvironment Environment = default!; +#endif + + public override void _Ready() + { +#if DEBUG + // If this is a debug build, use GoDotTest to examine the + // command line arguments and determine if we should run tests. + Environment = TestEnvironment.From(OS.GetCmdlineArgs()); + if (Environment.ShouldRunTests) + { + CallDeferred("RunTests"); + return; + } +#endif + // If we don't need to run tests, we can just switch to the game scene. + GetTree().ChangeSceneToFile("uid://d4fqgp0bjijcv"); + } + +#if DEBUG + private void RunTests() + => _ = GoTest.RunTests(Assembly.GetExecutingAssembly(), this, Environment); +#endif +} diff --git a/example/scenes/Main.tscn b/example/scenes/Main.tscn new file mode 100644 index 00000000..314f6825 --- /dev/null +++ b/example/scenes/Main.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://dnl3qrgvrl2f6"] + +[ext_resource type="Script" path="res://example/scenes/Main.cs" id="1_tw1m4"] + +[node name="Main" type="Node2D"] +script = ExtResource("1_tw1m4") From 70f44d6d9f151ffe3f170e64720e4aebe6d3c417 Mon Sep 17 00:00:00 2001 From: MASSHUU12 Date: Tue, 19 Mar 2024 12:35:33 +0100 Subject: [PATCH 04/14] Update launch configuration --- .vscode/launch.json | 28 ++++++++++++++++++++++++++++ .vscode/tasks.json | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 5ee07449..ab75b181 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -51,6 +51,34 @@ "args": ["${fileDirname}/${fileBasenameNoExtension}.tscn"], "cwd": "${workspaceFolder}", "stopAtEntry": false + }, + { + "name": "Debug Tests", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${env:GODOT}", + "args": [ + // These command line flags are used by GoDotTest to run tests. + "--run-tests", + "--quit-on-finish" + ], + "cwd": "${workspaceFolder}", + "stopAtEntry": false + }, + { + "name": "Debug Current Test", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${env:GODOT}", + "args": [ + // These command line flags are used by GoDotTest to run tests. + "--run-tests=${fileBasenameNoExtension}", + "--quit-on-finish" + ], + "cwd": "${workspaceFolder}", + "stopAtEntry": false } ] } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 6abe047d..add27f10 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -5,7 +5,7 @@ "label": "build", "command": "dotnet", "type": "process", - "args": ["build"], + "args": ["build", "--no-restore"], "problemMatcher": "$msCompile", "presentation": { "echo": true, From 8cf700892b77b027fce7e211249b959d333b4124 Mon Sep 17 00:00:00 2001 From: MASSHUU12 Date: Tue, 19 Mar 2024 12:35:50 +0100 Subject: [PATCH 05/14] Change main scene --- project.godot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.godot b/project.godot index f2033804..abb30c7c 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="godot-yat" config/tags=PackedStringArray("addon") -run/main_scene="res://example/scenes/main_menu/MainMenu.tscn" +run/main_scene="res://example/scenes/Main.tscn" config/features=PackedStringArray("4.3", "C#") config/icon="res://yat_icon.png" From 934c409b38332073d5d02dace3d27f8a6e66d98a Mon Sep 17 00:00:00 2001 From: MASSHUU12 Date: Tue, 19 Mar 2024 12:36:00 +0100 Subject: [PATCH 06/14] Create ExampleTest --- test/ExampleTest.cs | 29 +++++++++++++++++++++++++++++ test/Test.cs | 0 2 files changed, 29 insertions(+) create mode 100644 test/ExampleTest.cs delete mode 100644 test/Test.cs diff --git a/test/ExampleTest.cs b/test/ExampleTest.cs new file mode 100644 index 00000000..06ae63fb --- /dev/null +++ b/test/ExampleTest.cs @@ -0,0 +1,29 @@ +using Godot; +using Chickensoft.GoDotTest; +using Chickensoft.GoDotLog; + +public class ExampleTest : TestClass +{ + private readonly ILog _log = new GDLog(nameof(ExampleTest)); + + public ExampleTest(Node testScene) : base(testScene) { } + + [SetupAll] + public void SetupAll() => _log.Print("Setup everything"); + + [Setup] + public void Setup() => _log.Print("Setup"); + + [Test] + public void Test() => _log.Print("Test"); + + [Cleanup] + public void Cleanup() => _log.Print("Cleanup"); + + [CleanupAll] + public void CleanupAll() => _log.Print("Cleanup everything"); + + [Failure] + public void Failure() => + _log.Print("Runs whenever any of the tests in this suite fail."); +} diff --git a/test/Test.cs b/test/Test.cs deleted file mode 100644 index e69de29b..00000000 From 47af770df5eff005ba24d22167e38e24a00c2fa6 Mon Sep 17 00:00:00 2001 From: MASSHUU12 Date: Tue, 19 Mar 2024 14:52:43 +0100 Subject: [PATCH 07/14] Add Shouldly package reference --- godot-yat.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/godot-yat.csproj b/godot-yat.csproj index 1741b415..adfd2a12 100644 --- a/godot-yat.csproj +++ b/godot-yat.csproj @@ -26,5 +26,6 @@ + From 09ab58743471436e0c490e0003038708b9798ff7 Mon Sep 17 00:00:00 2001 From: MASSHUU12 Date: Tue, 19 Mar 2024 14:58:54 +0100 Subject: [PATCH 08/14] Remove need for Main scene --- .vscode/launch.json | 6 ++++-- example/scenes/Main.tscn | 6 ------ project.godot | 2 +- test/ExampleTest.cs | 29 -------------------------- example/scenes/Main.cs => test/Test.cs | 6 ++++-- test/Test.tscn | 6 ++++++ 6 files changed, 15 insertions(+), 40 deletions(-) delete mode 100644 example/scenes/Main.tscn delete mode 100644 test/ExampleTest.cs rename example/scenes/Main.cs => test/Test.cs (86%) create mode 100644 test/Test.tscn diff --git a/.vscode/launch.json b/.vscode/launch.json index ab75b181..d52f8ee8 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -53,12 +53,13 @@ "stopAtEntry": false }, { - "name": "Debug Tests", + "name": "🧪 Debug Tests", "type": "coreclr", "request": "launch", "preLaunchTask": "build", "program": "${env:GODOT}", "args": [ + "uid://2x6cfhujoahs", // These command line flags are used by GoDotTest to run tests. "--run-tests", "--quit-on-finish" @@ -67,12 +68,13 @@ "stopAtEntry": false }, { - "name": "Debug Current Test", + "name": "🧪 Debug Current Test", "type": "coreclr", "request": "launch", "preLaunchTask": "build", "program": "${env:GODOT}", "args": [ + "uid://2x6cfhujoahs", // These command line flags are used by GoDotTest to run tests. "--run-tests=${fileBasenameNoExtension}", "--quit-on-finish" diff --git a/example/scenes/Main.tscn b/example/scenes/Main.tscn deleted file mode 100644 index 314f6825..00000000 --- a/example/scenes/Main.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://dnl3qrgvrl2f6"] - -[ext_resource type="Script" path="res://example/scenes/Main.cs" id="1_tw1m4"] - -[node name="Main" type="Node2D"] -script = ExtResource("1_tw1m4") diff --git a/project.godot b/project.godot index abb30c7c..f2033804 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="godot-yat" config/tags=PackedStringArray("addon") -run/main_scene="res://example/scenes/Main.tscn" +run/main_scene="res://example/scenes/main_menu/MainMenu.tscn" config/features=PackedStringArray("4.3", "C#") config/icon="res://yat_icon.png" diff --git a/test/ExampleTest.cs b/test/ExampleTest.cs deleted file mode 100644 index 06ae63fb..00000000 --- a/test/ExampleTest.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Godot; -using Chickensoft.GoDotTest; -using Chickensoft.GoDotLog; - -public class ExampleTest : TestClass -{ - private readonly ILog _log = new GDLog(nameof(ExampleTest)); - - public ExampleTest(Node testScene) : base(testScene) { } - - [SetupAll] - public void SetupAll() => _log.Print("Setup everything"); - - [Setup] - public void Setup() => _log.Print("Setup"); - - [Test] - public void Test() => _log.Print("Test"); - - [Cleanup] - public void Cleanup() => _log.Print("Cleanup"); - - [CleanupAll] - public void CleanupAll() => _log.Print("Cleanup everything"); - - [Failure] - public void Failure() => - _log.Print("Runs whenever any of the tests in this suite fail."); -} diff --git a/example/scenes/Main.cs b/test/Test.cs similarity index 86% rename from example/scenes/Main.cs rename to test/Test.cs index 2abb573e..231d83bd 100644 --- a/example/scenes/Main.cs +++ b/test/Test.cs @@ -5,7 +5,9 @@ using Chickensoft.GoDotTest; #endif -public partial class Main : Node2D +namespace Test; + +public partial class Test : Node { #if DEBUG public TestEnvironment Environment = default!; @@ -24,7 +26,7 @@ public override void _Ready() } #endif // If we don't need to run tests, we can just switch to the game scene. - GetTree().ChangeSceneToFile("uid://d4fqgp0bjijcv"); + // GetTree().ChangeSceneToFile("uid://d4fqgp0bjijcv"); } #if DEBUG diff --git a/test/Test.tscn b/test/Test.tscn new file mode 100644 index 00000000..483f478a --- /dev/null +++ b/test/Test.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://2x6cfhujoahs"] + +[ext_resource type="Script" path="res://test/Test.cs" id="1_wogky"] + +[node name="Test" type="Node"] +script = ExtResource("1_wogky") From 94093c232f3dc75781ffd12a5534d8909f48ad09 Mon Sep 17 00:00:00 2001 From: MASSHUU12 Date: Tue, 19 Mar 2024 15:03:58 +0100 Subject: [PATCH 09/14] Update path to the Test scene --- .vscode/launch.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index d52f8ee8..70122450 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -59,7 +59,7 @@ "preLaunchTask": "build", "program": "${env:GODOT}", "args": [ - "uid://2x6cfhujoahs", + "res://test/Test.tscn", // These command line flags are used by GoDotTest to run tests. "--run-tests", "--quit-on-finish" @@ -74,7 +74,7 @@ "preLaunchTask": "build", "program": "${env:GODOT}", "args": [ - "uid://2x6cfhujoahs", + "res://test/Test.tscn", // These command line flags are used by GoDotTest to run tests. "--run-tests=${fileBasenameNoExtension}", "--quit-on-finish" From 3af30715c4d56bd6d453fe728b643a761c3d0418 Mon Sep 17 00:00:00 2001 From: MASSHUU12 Date: Tue, 19 Mar 2024 15:04:26 +0100 Subject: [PATCH 10/14] Port TestAttributeHelper to GoDotTest --- test/helpers/TestAttributeHelper.cs | 77 +++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 test/helpers/TestAttributeHelper.cs diff --git a/test/helpers/TestAttributeHelper.cs b/test/helpers/TestAttributeHelper.cs new file mode 100644 index 00000000..91ffa5e3 --- /dev/null +++ b/test/helpers/TestAttributeHelper.cs @@ -0,0 +1,77 @@ +using Chickensoft.GoDotTest; +using Godot; +using YAT.Attributes; +using YAT.Helpers; +using Shouldly; + +namespace Test; + +public class TestAttributeHelper : TestClass +{ + public TestAttributeHelper(Node testScene) : base(testScene) { } + + [Command("test")] + [Argument("arg1", "string")] + [Argument("arg3", "string")] + [Argument("arg3", "string")] + private class TestClass { } + + [Test] + public void TestGetAttribute_AttributePresent() + { + var obj = new TestClass(); + var attribute = Reflection.GetAttribute(obj); + + attribute.ShouldNotBeNull(); + attribute.Name.ShouldBe("test"); + } + + [Test] + public void TestGetAttribute_AttributeNotPresent() + { + var obj = new TestClass(); + var attribute = Reflection.GetAttribute(obj); + + attribute.ShouldBeNull(); + } + + [Test] + public void TestGetAttribute_AttributesPresent() + { + var obj = new TestClass(); + var attributes = Reflection.GetAttributes(obj); + + attributes.ShouldNotBeNull(); + attributes.Length.ShouldBe(3); + attributes[0].Name.ToString().ShouldBe("arg1"); + attributes[1].Name.ToString().ShouldBe("arg3"); + attributes[2].Name.ToString().ShouldBe("arg3"); + } + + [Test] + public void TestGetAttribute_AttributesNotPresent() + { + var obj = new TestClass(); + var attributes = Reflection.GetAttributes(obj); + + attributes.ShouldBeEmpty(); + } + + [Test] + public void TestHasAttribute_AttributePresent() + { + var obj = new TestClass(); + var hasAttribute = Reflection.HasAttribute(obj); + + hasAttribute.ShouldBeTrue(); + } + + [Test] + public void TestHasAttribute_AttributeNotPresent() + { + var obj = new TestClass(); + var hasAttribute = Reflection.HasAttribute(obj); + + hasAttribute.ShouldBeFalse(); + } +} From f260aec2616437e9f4eaf7dd41886f48840ddfb9 Mon Sep 17 00:00:00 2001 From: MASSHUU12 Date: Tue, 19 Mar 2024 15:19:18 +0100 Subject: [PATCH 11/14] Convert TestNumeric to GoDotTest --- test/helpers/TestNumeric.cs | 93 +++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 test/helpers/TestNumeric.cs diff --git a/test/helpers/TestNumeric.cs b/test/helpers/TestNumeric.cs new file mode 100644 index 00000000..dce4e0fa --- /dev/null +++ b/test/helpers/TestNumeric.cs @@ -0,0 +1,93 @@ +using Chickensoft.GoDotTest; +using Godot; +using YAT.Helpers; +using Shouldly; +using System; + +namespace Test; + +public class TestNumeric : TestClass +{ + public TestNumeric(Node testScene) : base(testScene) { } + + #region TestIsWithinRange + [Test] + public static void TestIsWithinRange() + { + IsWithinRange(5, 0, 10, true); + IsWithinRange(0, 0, 10, true); + IsWithinRange(10, 0, 10, true); + IsWithinRange(11, 0, 10, false); + IsWithinRange(-1, 0, 10, false); + + IsWithinRange(0.3, 0.1, 0.5, true); + IsWithinRange(0.1, 0.1, 0.5, true); + IsWithinRange(0.5, 0.1, 0.5, true); + IsWithinRange(0.6, 0.1, 0.5, false); + IsWithinRange(0, 0.1, 0.5, false); + } + + private static void IsWithinRange(T value, T min, T max, bool expected) where T : IComparable + { + Numeric.IsWithinRange(value, min, max).ShouldBe(expected); + } + #endregion + + #region TestTryConvert + [Test] + public static void TestTryConvert() + { + TryConvert("5", 5, true); + TryConvert("-5", -5, true); + TryConvert("5.0", -1, false); + TryConvert("5.0f", -1, false); + TryConvert("-5.0", -1, false); + TryConvert("-5.0f", -1, false); + TryConvert("five", -1, false); + TryConvert("5five", -1, false); + TryConvert("five5", -1, false); + TryConvert("5five5", -1, false); + + TryConvert("5.0", 5.0, true); + TryConvert("-5.0", -5.0, true); + TryConvert("five", -1, false); + TryConvert("5five", -1, false); + TryConvert("five5", -1, false); + TryConvert("5five5", -1, false); + TryConvert("5.0five", -1, false); + TryConvert("-5.0dfive", -1, false); + TryConvert("5.0f", -1, false); + TryConvert("-5.0f", -1, false); + TryConvert("5.0d", -1, false); + } + + private static void TryConvert(string value, T expectedResult, bool expected) + where T : IConvertible, IComparable + { + Numeric.TryConvert(value, out T result).ShouldBe(expected); + + if (expected) result.ShouldBe(expectedResult); + } + #endregion + + #region TestSizeToString + [Test] + public static void TestSizeToString() + { + SizeToString(0, 2, "0 B"); + SizeToString(1, 2, "1 B"); + SizeToString(1023, 2, "1023 B"); + SizeToString(1024, 2, "1.00 KiB"); + SizeToString(1025, 2, "1.00 KiB"); + SizeToString(1024 * 1024, 2, "1.00 MiB"); + SizeToString(1024 * 1024 * 1024, 2, "1.00 GiB"); + SizeToString(2137420969, 2, "1.99 GiB"); + SizeToString(2137420969, 6, "1.990628 GiB"); + } + + private static void SizeToString(long fileSize, int precision, string expected) + { + Numeric.SizeToString(fileSize, precision).ShouldBe(expected); + } + #endregion +} From e8e82c7717171fa1e6c52fca5a5cb522396b741b Mon Sep 17 00:00:00 2001 From: MASSHUU12 Date: Tue, 19 Mar 2024 15:19:40 +0100 Subject: [PATCH 12/14] Remove old TestAttributeHelper & TestNumeric --- test/old/helpers/TestAttributeHelper.cs | 77 ---------------------- test/old/helpers/TestNumeric.cs | 86 ------------------------- 2 files changed, 163 deletions(-) delete mode 100644 test/old/helpers/TestAttributeHelper.cs delete mode 100644 test/old/helpers/TestNumeric.cs diff --git a/test/old/helpers/TestAttributeHelper.cs b/test/old/helpers/TestAttributeHelper.cs deleted file mode 100644 index 3a747314..00000000 --- a/test/old/helpers/TestAttributeHelper.cs +++ /dev/null @@ -1,77 +0,0 @@ -using YAT.Attributes; -using YAT.Helpers; - -namespace GdUnit4 -{ - using static Assertions; - - - [TestSuite] - public partial class TestAttributeHelper - { - [Command("test")] - [Argument("arg1", "string")] - [Argument("arg3", "string")] - [Argument("arg3", "string")] - private class TestClass { } - - [TestCase] - public void TestGetAttribute_AttributePresent() - { - var obj = new TestClass(); - var attribute = Reflection.GetAttribute(obj); - - AssertObject(attribute).IsNotNull(); - AssertString(attribute.Name).IsEqual("test"); - } - - [TestCase] - public void TestGetAttribute_AttributeNotPresent() - { - var obj = new TestClass(); - var attribute = Reflection.GetAttribute(obj); - - AssertObject(attribute).IsNull(); - } - - [TestCase] - public void TestGetAttribute_AttributesPresent() - { - var obj = new TestClass(); - var attributes = Reflection.GetAttributes(obj); - - AssertObject(attributes).IsNotNull(); - AssertInt(attributes.Length).IsEqual(3); - AssertString(attributes[0].Name).IsEqual("arg1"); - AssertString(attributes[1].Name).IsEqual("arg3"); - AssertString(attributes[2].Name).IsEqual("arg3"); - } - - [TestCase] - public void TestGetAttribute_AttributesNotPresent() - { - var obj = new TestClass(); - var attributes = Reflection.GetAttributes(obj); - - AssertArray(attributes).IsEmpty(); - } - - [TestCase] - public void TestHasAttribute_AttributePresent() - { - var obj = new TestClass(); - var hasAttribute = Reflection.HasAttribute(obj); - - AssertBool(hasAttribute).IsEqual(true); - } - - [TestCase] - public void TestHasAttribute_AttributeNotPresent() - { - var obj = new TestClass(); - var hasAttribute = Reflection.HasAttribute(obj); - - AssertBool(hasAttribute).IsEqual(false); - } - } -} diff --git a/test/old/helpers/TestNumeric.cs b/test/old/helpers/TestNumeric.cs deleted file mode 100644 index 0c038e37..00000000 --- a/test/old/helpers/TestNumeric.cs +++ /dev/null @@ -1,86 +0,0 @@ -using YAT.Helpers; - -namespace GdUnit4 -{ - using static Assertions; - - [TestSuite] - public partial class TestNumericHelper - { - #region TestIsWithinRange - [TestCase(5, 0, 10, true)] - [TestCase(0, 0, 10, true)] - [TestCase(10, 0, 10, true)] - [TestCase(11, 0, 10, false)] - [TestCase(-1, 0, 10, false)] - public void TestIsWithinRangeInt(int value, int min, int max, bool expected) - { - AssertThat(Numeric.IsWithinRange(value, min, max)).IsEqual(expected); - } - - [TestCase(0.3, 0.1, 0.5, true)] - [TestCase(0.1, 0.1, 0.5, true)] - [TestCase(0.5, 0.1, 0.5, true)] - [TestCase(0.6, 0.1, 0.5, false)] - [TestCase(0, 0.1, 0.5, false)] - public void TestIsWithinRangeDouble(double value, double min, double max, bool expected) - { - AssertThat(Numeric.IsWithinRange(value, min, max)).IsEqual(expected); - } - #endregion - - #region TestTryConvert - [TestCase("5", 5, true)] - [TestCase("-5", -5, true)] - [TestCase("5.0", -1, false)] - [TestCase("5.0f", -1, false)] - [TestCase("-5.0", -1, false)] - [TestCase("-5.0f", -1, false)] - [TestCase("five", -1, false)] - [TestCase("5five", -1, false)] - [TestCase("five5", -1, false)] - [TestCase("5five5", -1, false)] - public void TestTryConvertInt(string value, int expectedResult, bool expected) - { - AssertThat(Numeric.TryConvert(value, out int i)).IsEqual(expected); - - if (expected) AssertThat(i).IsEqual(expectedResult); - } - - [TestCase("5.0", 5.0, true)] - [TestCase("-5.0", -5.0, true)] - [TestCase("five", -1, false)] - [TestCase("5five", -1, false)] - [TestCase("five5", -1, false)] - [TestCase("5five5", -1, false)] - [TestCase("5.0five", -1, false)] - [TestCase("-5.0dfive", -1, false)] - [TestCase("5.0f", -1, false)] - [TestCase("-5.0f", -1, false)] - [TestCase("5.0d", -1, false)] - [TestCase("-5.0d", -1, false)] - public void TestTryConvertDouble(string value, double expectedResult, bool expected) - { - AssertThat(Numeric.TryConvert(value, out double d)).IsEqual(expected); - - if (expected) AssertThat(d).IsEqual(expectedResult); - } - #endregion - - #region TestSizeToString - [TestCase(0, 2, "0 B")] - [TestCase(1, 2, "1 B")] - [TestCase(1023, 2, "1023 B")] - [TestCase(1024, 2, "1.00 KiB")] - [TestCase(1025, 2, "1.00 KiB")] - [TestCase(1024 * 1024, 2, "1.00 MiB")] - [TestCase(1024 * 1024 * 1024, 2, "1.00 GiB")] - [TestCase(2137420969, 2, "1.99 GiB")] - [TestCase(2137420969, 6, "1.990628 GiB")] - public void TestSizeToString(long fileSize, int precision, string expected) - { - AssertThat(Numeric.SizeToString(fileSize, precision)).IsEqual(expected); - } - #endregion - } -} From a6fabc15b5bc3688a10164a8293bba870496e6dc Mon Sep 17 00:00:00 2001 From: MASSHUU12 Date: Tue, 19 Mar 2024 15:53:02 +0100 Subject: [PATCH 13/14] Convert TestScene to GoDotTest --- test/helpers/TestScene.cs | 30 ++++++++++++++++++++++++++++++ test/old/helpers/TestScene.cs | 24 ------------------------ 2 files changed, 30 insertions(+), 24 deletions(-) create mode 100644 test/helpers/TestScene.cs delete mode 100644 test/old/helpers/TestScene.cs diff --git a/test/helpers/TestScene.cs b/test/helpers/TestScene.cs new file mode 100644 index 00000000..eba24662 --- /dev/null +++ b/test/helpers/TestScene.cs @@ -0,0 +1,30 @@ +using Chickensoft.GoDotTest; +using Godot; +using YAT.Helpers; +using Shouldly; + +namespace Test; + +public class TestScene : TestClass +{ + public TestScene(Node testScene) : base(testScene) { } + + [Test] + public static void TestGetRangeFromHint() + { + GetRangeFromHint("", 0, 0, 0); + GetRangeFromHint("0, 32", 0, 32, 0); + GetRangeFromHint("1,255,1", 1, 255, 1); + GetRangeFromHint("0,1,0.1", 0, 1, 0.1f); + GetRangeFromHint("0.3,0.5,0.1", 0.3f, 0.5f, 0.1f); + } + + private static void GetRangeFromHint(string hint, float min, float max, float step) + { + var (actualMin, actualMax, actualStep) = Scene.GetRangeFromHint(hint); + + min.ShouldBe(actualMin); + max.ShouldBe(actualMax); + step.ShouldBe(actualStep); + } +} diff --git a/test/old/helpers/TestScene.cs b/test/old/helpers/TestScene.cs deleted file mode 100644 index c84b83c3..00000000 --- a/test/old/helpers/TestScene.cs +++ /dev/null @@ -1,24 +0,0 @@ -using YAT.Helpers; - -namespace GdUnit4 -{ - using static Assertions; - - [TestSuite] - public partial class TestScene - { - [TestCase("", 0, 0, 0)] - [TestCase("0, 32", 0, 32, 0)] - [TestCase("1,255,1", 1, 255, 1)] - [TestCase("0,1,0.1", 0, 1, 0.1f)] - [TestCase("0.3,0.5,0.1", 0.3f, 0.5f, 0.1f)] - public void TestGetRangeFromHint(string hint, float min, float max, float step) - { - var (actualMin, actualMax, actualStep) = Scene.GetRangeFromHint(hint); - - AssertFloat(min).IsEqual(actualMin); - AssertFloat(max).IsEqual(actualMax); - AssertFloat(step).IsEqual(actualStep); - } - } -} From bc4f7d9e5cb3938ba91adaeb6a2bfb593eaa938a Mon Sep 17 00:00:00 2001 From: MASSHUU12 Date: Tue, 19 Mar 2024 16:01:13 +0100 Subject: [PATCH 14/14] Convert TestText to GoDotTest --- test/helpers/TestText.cs | 135 +++++++++++++++++++++++++++++++++++ test/old/helpers/TestText.cs | 95 ------------------------ 2 files changed, 135 insertions(+), 95 deletions(-) create mode 100644 test/helpers/TestText.cs delete mode 100644 test/old/helpers/TestText.cs diff --git a/test/helpers/TestText.cs b/test/helpers/TestText.cs new file mode 100644 index 00000000..4e78af9d --- /dev/null +++ b/test/helpers/TestText.cs @@ -0,0 +1,135 @@ +using Chickensoft.GoDotTest; +using Godot; +using YAT.Helpers; +using Shouldly; + +namespace Test; + +public class TestText : TestClass +{ + public TestText(Node testScene) : base(testScene) { } + + [Test] + public static void TestEscapeBBCode() + { + EscapeBBCode("Hello, world!", "Hello, world!"); + EscapeBBCode("Hello, [b]world[/b]!", "Hello, [lb]b]world[lb]/b]!"); + EscapeBBCode("[b]Hello[/b], world!", "[lb]b]Hello[lb]/b], world!"); + EscapeBBCode("[b]Hello, world![/b]", "[lb]b]Hello, world![lb]/b]"); + EscapeBBCode("[b]Hello, [b]world[/b]![/b]", "[lb]b]Hello, [lb]b]world[lb]/b]![lb]/b]"); + EscapeBBCode("[b]Hello, [b]world[/b]![/b] [b]Hello, [b]world[/b]![/b]", "[lb]b]Hello, [lb]b]world[lb]/b]![lb]/b] [lb]b]Hello, [lb]b]world[lb]/b]![lb]/b]"); + } + + private static void EscapeBBCode(string text, string expected) + { + Text.EscapeBBCode(text).ShouldBe(expected); + } + + [Test] + public static void TestMakeBold() + { + MakeBold("Hello, world!", "[b]Hello, world![/b]"); + MakeBold("Hello, [b]world[/b]!", "[b]Hello, [b]world[/b]![/b]"); + MakeBold("[b]Hello[/b], world!", "[b][b]Hello[/b], world![/b]"); + MakeBold("[b]Hello, world![/b]", "[b][b]Hello, world![/b][/b]"); + MakeBold("[b]Hello, [b]world[/b]![/b]", "[b][b]Hello, [b]world[/b]![/b][/b]"); + } + + private static void MakeBold(string text, string expected) + { + Text.MakeBold(text).ShouldBe(expected); + } + + [Test] + public static void TestSanitizeText() + { + SanitizeText("Hello, world!", new string[] { "Hello,", "world!" }); + SanitizeText("Hello, world! ", new string[] { "Hello,", "world!" }); + SanitizeText(" Hello, world!", new string[] { "Hello,", "world!" }); + SanitizeText(" Hello, world! ", new string[] { "Hello,", "world!" }); + SanitizeText("Hello, world!", new string[] { "Hello,", "world!" }); + SanitizeText(" Hello, world! ", new string[] { "Hello,", "world!" }); + } + + private static void SanitizeText(string text, string[] expected) + { + Text.SanitizeText(text).ShouldBe(expected); + } + + [Test] + public static void TestConcatenateSentence() + { + ConcatenateSentence(new string[] { "Hello,", "world!" }, new string[] { "Hello,", "world!" }); + ConcatenateSentence(new string[] { "echo", "\"Hello,", "world!\"" }, new string[] { "echo", "Hello, world!" }); + ConcatenateSentence(new string[] { "echo", "'Hello,", "world!'" }, new string[] { "echo", "Hello, world!" }); + ConcatenateSentence(new string[] { "qc", "add", "-name=\"John", "Doe\"" }, new string[] { "qc", "add", "-name=John Doe" }); + ConcatenateSentence(new string[] { "qc", "add", "-name='John", "Doe'" }, new string[] { "qc", "add", "-name=John Doe" }); + ConcatenateSentence(new string[] { "qc", "add", "-name='John", "\"Doe'" }, new string[] { "qc", "add", "-name=John \"Doe" }); + } + + private static void ConcatenateSentence(string[] strings, string[] expected) + { + Text.ConcatenateSentence(strings).ShouldBe(expected); + } + + [Test] + public static void TestStartsWith() + { + StartsWith("Hello, world!", true, new char[] { 'H', 'H', 'H' }); + StartsWith("Hello, world!", true, new char[] { 'H', 'h' }); + StartsWith("Hello, world!", true, new char[] { 'H', 'e' }); + StartsWith("Hello, world!", true, new char[] { 'H', 'l' }); + StartsWith("Hello, world!", true, new char[] { 'o', 'H' }); + StartsWith("Hello, world!", false, new char[] { 'o', 'o' }); + } + + private static void StartsWith(string text, bool expected, char[] chars) + { + Text.StartsWith(text, chars).ShouldBe(expected); + } + + [Test] + public static void TestEndsWith() + { + EndsWith("Hello, world!", true, new char[] { '!', '!', '!' }); + EndsWith("Hello, world!", true, new char[] { '!', 'd' }); + EndsWith("Hello, world!", true, new char[] { '!', 'l' }); + EndsWith("Hello, world!", true, new char[] { '!', 'r' }); + EndsWith("Hello, world!", true, new char[] { 'w', '!' }); + } + + private static void EndsWith(string text, bool expected, char[] chars) + { + Text.EndsWith(text, chars).ShouldBe(expected); + } + + [Test] + public static void TestSplitClean() + { + SplitClean("Hello!", "", new string[] { "Hello!" }); + SplitClean("Hello!", " ", new string[] { "Hello!" }); + SplitClean("Hello!", "l", new string[] { "He", "o!" }); + SplitClean("Hello!", "ll", new string[] { "He", "o!" }); + SplitClean("Hello, World!", ", ", new string[] { "Hello", "World!" }); + } + + private static void SplitClean(string text, string separator, string[] expected) + { + Text.SplitClean(text, separator).ShouldBe(expected); + } + + [Test] + public static void TestShortenPath() + { + ShortenPath("res://example/main_menu/MainMenu.tscn", 128, "res://example/main_menu/MainMenu.tscn"); + ShortenPath("res://example/main_menu/MainMenu.tscn", 30, "res://.../.../MainMenu.tscn"); + ShortenPath("res://example/main_menu/MainMenu.tscn", 15, "res:/.../.../.."); + ShortenPath("res://example/main_menu/MainMenu.tscn", 0, "..."); + ShortenPath("", 16, "..."); + } + + private static void ShortenPath(string path, ushort maxLength, string expected) + { + Text.ShortenPath(path, maxLength).ShouldBe(expected); + } +} diff --git a/test/old/helpers/TestText.cs b/test/old/helpers/TestText.cs deleted file mode 100644 index 213a990d..00000000 --- a/test/old/helpers/TestText.cs +++ /dev/null @@ -1,95 +0,0 @@ -using YAT.Helpers; - -namespace GdUnit4 -{ - using static Assertions; - - [TestSuite] - public partial class TestText - { - [TestCase("Hello, world!", "Hello, world!")] - [TestCase("Hello, [b]world[/b]!", "Hello, [lb]b]world[lb]/b]!")] - [TestCase("[b]Hello[/b], world!", "[lb]b]Hello[lb]/b], world!")] - [TestCase("[b]Hello, world![/b]", "[lb]b]Hello, world![lb]/b]")] - [TestCase("[b]Hello, [b]world[/b]![/b]", "[lb]b]Hello, [lb]b]world[lb]/b]![lb]/b]")] - [TestCase("[b]Hello, [b]world[/b]![/b] [b]Hello, [b]world[/b]![/b]", "[lb]b]Hello, [lb]b]world[lb]/b]![lb]/b] [lb]b]Hello, [lb]b]world[lb]/b]![lb]/b]")] - public void TestEscapeBBCode(string text, string expected) - { - AssertThat(Text.EscapeBBCode(text)).IsEqual(expected); - } - - [TestCase("Hello, world!", "[b]Hello, world![/b]")] - [TestCase("Hello, [b]world[/b]!", "[b]Hello, [b]world[/b]![/b]")] - [TestCase("[b]Hello[/b], world!", "[b][b]Hello[/b], world![/b]")] - [TestCase("[b]Hello, world![/b]", "[b][b]Hello, world![/b][/b]")] - [TestCase("[b]Hello, [b]world[/b]![/b]", "[b][b]Hello, [b]world[/b]![/b][/b]")] - public void TestMakeBold(string text, string expected) - { - AssertThat(Text.MakeBold(text)).IsEqual(expected); - } - - [TestCase("Hello, world!", new string[] { "Hello,", "world!" })] - [TestCase("Hello, world! ", new string[] { "Hello,", "world!" })] - [TestCase(" Hello, world!", new string[] { "Hello,", "world!" })] - [TestCase(" Hello, world! ", new string[] { "Hello,", "world!" })] - [TestCase("Hello, world!", new string[] { "Hello,", "world!" })] - [TestCase(" Hello, world! ", new string[] { "Hello,", "world!" })] - public void TestSanitizeText(string text, string[] expected) - { - AssertArray(Text.SanitizeText(text)).IsEqual(expected); - } - - [TestCase(new string[] { "Hello,", "world!" }, new string[] { "Hello,", "world!" })] - [TestCase(new string[] { "echo", "\"Hello,", "world!\"" }, new string[] { "echo", "Hello, world!" })] - [TestCase(new string[] { "echo", "'Hello,", "world!'" }, new string[] { "echo", "Hello, world!" })] - [TestCase(new string[] { "qc", "add", "-name=\"John", "Doe\"" }, new string[] { "qc", "add", "-name=John Doe" })] - [TestCase(new string[] { "qc", "add", "-name='John", "Doe'" }, new string[] { "qc", "add", "-name=John Doe" })] - [TestCase(new string[] { "qc", "add", "-name='John", "\"Doe'" }, new string[] { "qc", "add", "-name=John \"Doe" })] - public void TestConcatenateSentence(string[] strings, string[] expected) - { - AssertArray(Text.ConcatenateSentence(strings)).IsEqual(expected); - } - - [TestCase("Hello, world!", true, new char[] { 'H', 'H', 'H' })] - [TestCase("Hello, world!", true, new char[] { 'H', 'h' })] - [TestCase("Hello, world!", true, new char[] { 'H', 'e' })] - [TestCase("Hello, world!", true, new char[] { 'H', 'l' })] - [TestCase("Hello, world!", true, new char[] { 'o', 'H' })] - [TestCase("Hello, world!", false, new char[] { 'o', 'o' })] - public void TestStartsWith(string text, bool expected, char[] chars) - { - AssertThat(Text.StartsWith(text, chars)).IsEqual(expected); - } - - [TestCase("Hello, world!", true, new char[] { '!', '!', '!' })] - [TestCase("Hello, world!", true, new char[] { '!', 'd' })] - [TestCase("Hello, world!", true, new char[] { '!', 'l' })] - [TestCase("Hello, world!", true, new char[] { '!', 'r' })] - [TestCase("Hello, world!", true, new char[] { 'w', '!' })] - [TestCase("Hello, world!", false, new char[] { 'o', 'o' })] - public void TestEndsWith(string text, bool expected, char[] chars) - { - AssertThat(Text.EndsWith(text, chars)).IsEqual(expected); - } - - [TestCase("Hello!", "", new string[] { "Hello!" })] - [TestCase("Hello!", " ", new string[] { "Hello!" })] - [TestCase("Hello!", "l", new string[] { "He", "o!" })] - [TestCase("Hello!", "ll", new string[] { "He", "o!" })] - [TestCase("Hello, World!", ", ", new string[] { "Hello", "World!" })] - public void TestSplitClean(string text, string separator, string[] expected) - { - AssertArray(Text.SplitClean(text, separator)).IsEqual(expected); - } - - [TestCase("res://example/main_menu/MainMenu.tscn", (ushort)128, "res://example/main_menu/MainMenu.tscn")] - [TestCase("res://example/main_menu/MainMenu.tscn", (ushort)30, "...ple/main_menu/MainMenu.tscn")] - [TestCase("res://example/main_menu/MainMenu.tscn", (ushort)15, "...ainMenu.tscn")] - [TestCase("res://example/main_menu/MainMenu.tscn", (ushort)0, "...")] - [TestCase("", (ushort)16, "...")] - public void TestShortenPath(string path, ushort maxLength, string expected) - { - AssertThat(Text.ShortenPath(path, maxLength)).IsEqual(expected); - } - } -}