From c43d164c6a0fa37794660c1027feaecdc2242a42 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Sat, 25 Mar 2023 17:07:08 +0100 Subject: [PATCH] Implement more instance method tests --- CHANGELOG.md | 1 + packages/lib-roblox/src/instance/mod.rs | 4 ++-- tests/roblox/instance/methods/GetChildren.luau | 18 ++++++++++++++++++ .../instance/methods/GetDescendants.luau | 18 ++++++++++++++++++ tests/roblox/instance/methods/GetFullName.luau | 11 +++++++++++ 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 tests/roblox/instance/methods/GetChildren.luau create mode 100644 tests/roblox/instance/methods/GetDescendants.luau create mode 100644 tests/roblox/instance/methods/GetFullName.luau diff --git a/CHANGELOG.md b/CHANGELOG.md index 56e9a12..7f5e02a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed accessing a destroyed instance printing an error message even if placed inside a pcall - Fixed cloned instances not having correct instance reference properties set (`ObjectValue.Value`, `Motor6D.Part0`, ...) +- Fixed `Instance::GetDescendants` returning the same thing as `Instance::GetChildren` (oops) ## `0.6.2` - March 25th, 2023 diff --git a/packages/lib-roblox/src/instance/mod.rs b/packages/lib-roblox/src/instance/mod.rs index 7f2e716..4e62b58 100644 --- a/packages/lib-roblox/src/instance/mod.rs +++ b/packages/lib-roblox/src/instance/mod.rs @@ -538,7 +538,7 @@ impl Instance { descendants.push(*queue_ref); let queue_inst = dom.get_by_ref(*queue_ref).unwrap(); for queue_ref_inner in queue_inst.children().iter().rev() { - queue.push_front(queue_ref_inner); + queue.push_back(queue_ref_inner); } } @@ -902,7 +902,7 @@ impl LuaUserData for Instance { }); methods.add_method("GetDescendants", |lua, this, ()| { this.ensure_not_destroyed()?; - this.get_children().to_lua(lua) + this.get_descendants().to_lua(lua) }); methods.add_method("GetFullName", |lua, this, ()| { this.ensure_not_destroyed()?; diff --git a/tests/roblox/instance/methods/GetChildren.luau b/tests/roblox/instance/methods/GetChildren.luau new file mode 100644 index 0000000..37952b6 --- /dev/null +++ b/tests/roblox/instance/methods/GetChildren.luau @@ -0,0 +1,18 @@ +local roblox = require("@lune/roblox") :: any +local Instance = roblox.Instance + +local model = + roblox.readModelFile("tests/roblox/rbx-test-files/models/three-nested-folders/binary.rbxm")[1] + +assert(#model:GetChildren() == 1) + +local newChild = Instance.new("Model") +newChild.Parent = model + +assert(#model:GetChildren() == 2) +assert(table.find(model:GetChildren(), newChild) ~= nil) + +newChild:Destroy() + +assert(#model:GetChildren() == 1) +assert(table.find(model:GetChildren(), newChild) == nil) diff --git a/tests/roblox/instance/methods/GetDescendants.luau b/tests/roblox/instance/methods/GetDescendants.luau new file mode 100644 index 0000000..7e6c6df --- /dev/null +++ b/tests/roblox/instance/methods/GetDescendants.luau @@ -0,0 +1,18 @@ +local roblox = require("@lune/roblox") :: any +local Instance = roblox.Instance + +local model = + roblox.readModelFile("tests/roblox/rbx-test-files/models/three-nested-folders/binary.rbxm")[1] + +assert(#model:GetDescendants() == 2) + +local newChild = Instance.new("Model") +newChild.Parent = model + +assert(#model:GetDescendants() == 3) +assert(table.find(model:GetDescendants(), newChild) == 2) + +newChild:Destroy() + +assert(#model:GetDescendants() == 2) +assert(table.find(model:GetDescendants(), newChild) == nil) diff --git a/tests/roblox/instance/methods/GetFullName.luau b/tests/roblox/instance/methods/GetFullName.luau new file mode 100644 index 0000000..d097148 --- /dev/null +++ b/tests/roblox/instance/methods/GetFullName.luau @@ -0,0 +1,11 @@ +local roblox = require("@lune/roblox") :: any + +local model = + roblox.readModelFile("tests/roblox/rbx-test-files/models/three-nested-folders/binary.rbxm")[1] + +local child = model:FindFirstChild("Parent") +local descendant = child:FindFirstChild("Child") + +assert(descendant:GetFullName() == "Grandparent.Parent.Child") +assert(child:GetFullName() == "Grandparent.Parent") +assert(model:GetFullName() == "Grandparent")