From dcec0e6ad3f68ff5410c7bc268120ea2e6aafd4b Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Sat, 25 Mar 2023 18:04:19 +0100 Subject: [PATCH] Finish up roblox instance method test suite --- packages/lib/src/tests.rs | 16 ++++++++++ .../instance/methods/FindFirstAncestor.luau | 16 ++++++++++ .../methods/FindFirstAncestorOfClass.luau | 16 ++++++++++ .../methods/FindFirstAncestorWhichIsA.luau | 16 ++++++++++ .../instance/methods/FindFirstChild.luau | 18 +++++++++++ .../methods/FindFirstChildOfClass.luau | 18 +++++++++++ .../methods/FindFirstChildWhichIsA.luau | 18 +++++++++++ .../instance/methods/FindFirstDescendant.luau | 31 +++++++++++++++++++ 8 files changed, 149 insertions(+) create mode 100644 tests/roblox/instance/methods/FindFirstAncestor.luau create mode 100644 tests/roblox/instance/methods/FindFirstAncestorOfClass.luau create mode 100644 tests/roblox/instance/methods/FindFirstAncestorWhichIsA.luau create mode 100644 tests/roblox/instance/methods/FindFirstChild.luau create mode 100644 tests/roblox/instance/methods/FindFirstChildOfClass.luau create mode 100644 tests/roblox/instance/methods/FindFirstChildWhichIsA.luau create mode 100644 tests/roblox/instance/methods/FindFirstDescendant.luau diff --git a/packages/lib/src/tests.rs b/packages/lib/src/tests.rs index d6e9b80..d9e351c 100644 --- a/packages/lib/src/tests.rs +++ b/packages/lib/src/tests.rs @@ -123,4 +123,20 @@ create_tests! { roblox_instance_attributes: "roblox/instance/attributes", roblox_instance_new: "roblox/instance/new", roblox_instance_properties: "roblox/instance/properties", + roblox_instance_methods_clear_all_children: "roblox/instance/methods/ClearAllChildren", + roblox_instance_methods_clone: "roblox/instance/methods/Clone", + roblox_instance_methods_destroy: "roblox/instance/methods/Destroy", + roblox_instance_methods_find_first_ancestor: "roblox/instance/methods/FindFirstAncestor", + roblox_instance_methods_find_first_ancestor_of_class: "roblox/instance/methods/FindFirstAncestorOfClass", + roblox_instance_methods_find_first_ancestor_which_is_a: "roblox/instance/methods/FindFirstAncestorWhichIsA", + roblox_instance_methods_find_first_child: "roblox/instance/methods/FindFirstChild", + roblox_instance_methods_find_first_child_of_class: "roblox/instance/methods/FindFirstChildOfClass", + roblox_instance_methods_find_first_child_which_is_a: "roblox/instance/methods/FindFirstChildWhichIsA", + roblox_instance_methods_find_first_descendant: "roblox/instance/methods/FindFirstDescendant", + roblox_instance_methods_get_children: "roblox/instance/methods/GetChildren", + roblox_instance_methods_get_descendants: "roblox/instance/methods/GetDescendants", + roblox_instance_methods_get_full_name: "roblox/instance/methods/GetFullName", + roblox_instance_methods_is_a: "roblox/instance/methods/IsA", + roblox_instance_methods_is_ancestor_of: "roblox/instance/methods/IsAncestorOf", + roblox_instance_methods_is_descendant_of: "roblox/instance/methods/IsDescendantOf", } diff --git a/tests/roblox/instance/methods/FindFirstAncestor.luau b/tests/roblox/instance/methods/FindFirstAncestor.luau new file mode 100644 index 0000000..c0b5fc2 --- /dev/null +++ b/tests/roblox/instance/methods/FindFirstAncestor.luau @@ -0,0 +1,16 @@ +local roblox = require("@lune/roblox") :: any +local Instance = roblox.Instance + +local root = Instance.new("Folder") +local child = Instance.new("Model") +local nested = Instance.new("Tool") +local descendant = Instance.new("Part") + +descendant.Parent = nested +nested.Parent = child +child.Parent = root + +assert(descendant:FindFirstAncestor("Part") == nil) +assert(descendant:FindFirstAncestor("Tool") == nested) +assert(descendant:FindFirstAncestor("Model") == child) +assert(descendant:FindFirstAncestor("Folder") == root) diff --git a/tests/roblox/instance/methods/FindFirstAncestorOfClass.luau b/tests/roblox/instance/methods/FindFirstAncestorOfClass.luau new file mode 100644 index 0000000..1f68f5e --- /dev/null +++ b/tests/roblox/instance/methods/FindFirstAncestorOfClass.luau @@ -0,0 +1,16 @@ +local roblox = require("@lune/roblox") :: any +local Instance = roblox.Instance + +local root = Instance.new("Folder") +local child = Instance.new("Model") +local nested = Instance.new("Tool") +local descendant = Instance.new("Part") + +descendant.Parent = nested +nested.Parent = child +child.Parent = root + +assert(descendant:FindFirstAncestorOfClass("Part") == nil) +assert(descendant:FindFirstAncestorOfClass("Tool") == nested) +assert(descendant:FindFirstAncestorOfClass("Model") == child) +assert(descendant:FindFirstAncestorOfClass("Folder") == root) diff --git a/tests/roblox/instance/methods/FindFirstAncestorWhichIsA.luau b/tests/roblox/instance/methods/FindFirstAncestorWhichIsA.luau new file mode 100644 index 0000000..a7322b5 --- /dev/null +++ b/tests/roblox/instance/methods/FindFirstAncestorWhichIsA.luau @@ -0,0 +1,16 @@ +local roblox = require("@lune/roblox") :: any +local Instance = roblox.Instance + +local root = Instance.new("Folder") +local child = Instance.new("Model") +local nested = Instance.new("Tool") +local descendant = Instance.new("Part") + +descendant.Parent = nested +nested.Parent = child +child.Parent = root + +assert(descendant:FindFirstAncestorWhichIsA("Part") == nil) +assert(descendant:FindFirstAncestorWhichIsA("Tool") == nested) +assert(descendant:FindFirstAncestorWhichIsA("Model") == nested) +assert(descendant:FindFirstAncestorWhichIsA("Folder") == root) diff --git a/tests/roblox/instance/methods/FindFirstChild.luau b/tests/roblox/instance/methods/FindFirstChild.luau new file mode 100644 index 0000000..8f1f3e4 --- /dev/null +++ b/tests/roblox/instance/methods/FindFirstChild.luau @@ -0,0 +1,18 @@ +local roblox = require("@lune/roblox") :: any +local Instance = roblox.Instance + +local root = Instance.new("Folder") +local child = Instance.new("Model") +local nested = Instance.new("Tool") +local adjacent = Instance.new("Model") +local descendant = Instance.new("Part") + +descendant.Parent = nested +nested.Parent = child +adjacent.Parent = child +child.Parent = root + +assert(child:FindFirstChild("Folder") == nil) +assert(child:FindFirstChild("Model") == adjacent) +assert(child:FindFirstChild("Tool") == nested) +assert(child:FindFirstChild("Part") == nil) diff --git a/tests/roblox/instance/methods/FindFirstChildOfClass.luau b/tests/roblox/instance/methods/FindFirstChildOfClass.luau new file mode 100644 index 0000000..55b12d4 --- /dev/null +++ b/tests/roblox/instance/methods/FindFirstChildOfClass.luau @@ -0,0 +1,18 @@ +local roblox = require("@lune/roblox") :: any +local Instance = roblox.Instance + +local root = Instance.new("Folder") +local child = Instance.new("Model") +local nested = Instance.new("Tool") +local adjacent = Instance.new("Model") +local descendant = Instance.new("Part") + +descendant.Parent = nested +nested.Parent = child +adjacent.Parent = child +child.Parent = root + +assert(child:FindFirstChildOfClass("Folder") == nil) +assert(child:FindFirstChildOfClass("Tool") == nested) +assert(child:FindFirstChildOfClass("Model") == adjacent) +assert(child:FindFirstChildOfClass("Part") == nil) diff --git a/tests/roblox/instance/methods/FindFirstChildWhichIsA.luau b/tests/roblox/instance/methods/FindFirstChildWhichIsA.luau new file mode 100644 index 0000000..087ce1d --- /dev/null +++ b/tests/roblox/instance/methods/FindFirstChildWhichIsA.luau @@ -0,0 +1,18 @@ +local roblox = require("@lune/roblox") :: any +local Instance = roblox.Instance + +local root = Instance.new("Folder") +local child = Instance.new("Model") +local nested = Instance.new("Tool") +local adjacent = Instance.new("Model") +local descendant = Instance.new("Part") + +descendant.Parent = nested +nested.Parent = child +adjacent.Parent = child +child.Parent = root + +assert(child:FindFirstChildWhichIsA("Folder") == nil) +assert(child:FindFirstChildWhichIsA("Tool") == nested) +assert(child:FindFirstChildWhichIsA("Model") == nested) +assert(child:FindFirstChildWhichIsA("Part") == nil) diff --git a/tests/roblox/instance/methods/FindFirstDescendant.luau b/tests/roblox/instance/methods/FindFirstDescendant.luau new file mode 100644 index 0000000..1b8e35b --- /dev/null +++ b/tests/roblox/instance/methods/FindFirstDescendant.luau @@ -0,0 +1,31 @@ +local roblox = require("@lune/roblox") :: any +local Instance = roblox.Instance + +local root = Instance.new("Folder") +local inner1 = Instance.new("Model") +local inner1_1 = Instance.new("Part") +local inner1_2 = Instance.new("Part") +local inner2 = Instance.new("Model") +local inner2_1 = Instance.new("Part") +local inner2_2 = Instance.new("Part") + +inner1.Parent = root +inner1_1.Parent = inner1 +inner1_2.Parent = inner1 +inner2.Parent = root +inner2_1.Parent = inner2 +inner2_2.Parent = inner2 + +assert(root:FindFirstDescendant("Folder") == nil) +assert(root:FindFirstDescendant("Model") == inner1) +assert(root:FindFirstDescendant("Part") == inner1_1) + +inner1:Destroy() + +assert(root:FindFirstDescendant("Folder") == nil) +assert(root:FindFirstDescendant("Model") == inner2) +assert(root:FindFirstDescendant("Part") == inner2_1) + +inner2_1:Destroy() + +assert(root:FindFirstDescendant("Part") == inner2_2)